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.