program rifornimenti;
const
MAXN = 1000000;
{ input data }
var
N, i,h : longint;
P : array[0..MAXN-1] of longint;
G : array[0..MAXN-1] of longint;
costopiatti : array[0..MAXN-1] of int64;
spesaminima : int64;
begin
(*assign(input, 'input.txt'); reset(input);
assign(output, 'output.txt'); rewrite(output);*)
readln(N);
for i:=0 to N-1 do read(P[i]);
readln;
for i:=0 to N-1 do read(G[i]);
readln;
for i:=0 to N-1 do costopiatti[i]:=G[i]*P[i];
spesaminima:=costopiatti[0];
i:=0; h:=1;
while i<N do
begin
while (h<=N-1) do
begin
if spesaminima+P[i]*G[h]<=spesaminima+costopiatti[h] then spesaminima:=spesaminima+P[i]*g[h]
else break;
h:=h+1;
end;
i:=h; writeln (i,' ',h);
end;
writeln(spesaminima); { print result }
end.
cHJvZ3JhbSByaWZvcm5pbWVudGk7CmNvbnN0CiAgICBNQVhOID0gMTAwMDAwMDsKCnsgaW5wdXQgZGF0YSB9CnZhcgogICAgTiwgaSxoICA6IGxvbmdpbnQ7CiAgICBQICAgICA6IGFycmF5WzAuLk1BWE4tMV0gb2YgbG9uZ2ludDsKICAgIEcgICAgIDogYXJyYXlbMC4uTUFYTi0xXSBvZiBsb25naW50OwogICAgY29zdG9waWF0dGkgOiAgYXJyYXlbMC4uTUFYTi0xXSBvZiBpbnQ2NDsKICAgIHNwZXNhbWluaW1hIDogaW50NjQ7CmJlZ2luCiAgICAoKmFzc2lnbihpbnB1dCwgICdpbnB1dC50eHQnKTsgIHJlc2V0KGlucHV0KTsKICAgIGFzc2lnbihvdXRwdXQsICdvdXRwdXQudHh0Jyk7IHJld3JpdGUob3V0cHV0KTsqKQogICAgcmVhZGxuKE4pOwogICAgZm9yIGk6PTAgdG8gTi0xIGRvIHJlYWQoUFtpXSk7CiAgICByZWFkbG47CiAgICBmb3IgaTo9MCB0byBOLTEgZG8gcmVhZChHW2ldKTsKICAgIHJlYWRsbjsKICAgIGZvciBpOj0wIHRvIE4tMSBkbyBjb3N0b3BpYXR0aVtpXTo9R1tpXSpQW2ldOwogICAgc3Blc2FtaW5pbWE6PWNvc3RvcGlhdHRpWzBdOyAKICAgIGk6PTA7IGg6PTE7CiAgICB3aGlsZSBpPE4gZG8KICAgICAgICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgICAgICB3aGlsZSAoaDw9Ti0xKSBkbwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJlZ2luCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiBzcGVzYW1pbmltYStQW2ldKkdbaF08PXNwZXNhbWluaW1hK2Nvc3RvcGlhdHRpW2hdIHRoZW4gc3Blc2FtaW5pbWE6PXNwZXNhbWluaW1hK1BbaV0qZ1toXQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaDo9aCsxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVuZDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICBpOj1oOyAgd3JpdGVsbiAoaSwnICcsaCk7CiAgICAgICAgICAgICAgIGVuZDsKICAgd3JpdGVsbihzcGVzYW1pbmltYSk7IHsgcHJpbnQgcmVzdWx0IH0KZW5kLg==