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
{
uncomment the following lines if you want to read/write from files
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;
costopiatti[0]:=P[0]*G[0];
for i:=1 to N-1 do costopiatti[i]:=costopiatti[i-1]+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]<=costopiatti[h] then spesaminima:=spesaminima+P[i]*g[h]
else break;
h:=h+1;
end;
i:=i+h;
end;
writeln(spesaminima); { print result }
end.
cHJvZ3JhbSByaWZvcm5pbWVudGk7Cgpjb25zdAogICAgTUFYTiA9IDEwMDAwMDA7Cgp7IGlucHV0IGRhdGEgfQp2YXIKICAgIE4sIGksaCAgOiBsb25naW50OwogICAgUCAgICAgOiBhcnJheVswLi5NQVhOLTFdIG9mIGxvbmdpbnQ7CiAgICBHICAgICA6IGFycmF5WzAuLk1BWE4tMV0gb2YgbG9uZ2ludDsKICAgIGNvc3RvcGlhdHRpIDogIGFycmF5WzAuLk1BWE4tMV0gb2YgaW50NjQ7CiAgICBzcGVzYW1pbmltYSA6IGludDY0OwpiZWdpbgp7CiAgICB1bmNvbW1lbnQgdGhlIGZvbGxvd2luZyBsaW5lcyBpZiB5b3Ugd2FudCB0byByZWFkL3dyaXRlIGZyb20gZmlsZXMKICAgIGFzc2lnbihpbnB1dCwgICdpbnB1dC50eHQnKTsgIHJlc2V0KGlucHV0KTsKICAgIGFzc2lnbihvdXRwdXQsICdvdXRwdXQudHh0Jyk7IHJld3JpdGUob3V0cHV0KTsKfQoKICAgIHJlYWRsbihOKTsKICAgIGZvciBpOj0wIHRvIE4tMSBkbwogICAgICAgIHJlYWQoUFtpXSk7CiAgICByZWFkbG47CiAgICBmb3IgaTo9MCB0byBOLTEgZG8KICAgICAgICByZWFkKEdbaV0pOwogICAgcmVhZGxuOwogICAgY29zdG9waWF0dGlbMF06PVBbMF0qR1swXTsKICAgIGZvciBpOj0xIHRvIE4tMSBkbyBjb3N0b3BpYXR0aVtpXTo9Y29zdG9waWF0dGlbaS0xXStHW2ldKlBbaV07CiAKICAgIHNwZXNhbWluaW1hOj1jb3N0b3BpYXR0aVswXTsgaTo9MDsgaDo9MTsKICAgIHdoaWxlIGk8TiBkbwogICAgICAgICAgICAgICBiZWdpbgogICAgICAgICAgICAgICAgICAgIHdoaWxlIChoPD1OLTEpIGRvCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIHNwZXNhbWluaW1hK1BbaV0qR1toXTw9Y29zdG9waWF0dGlbaF0gdGhlbiBzcGVzYW1pbmltYTo9c3Blc2FtaW5pbWErUFtpXSpnW2hdCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBoOj1oKzE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVuZDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICBpOj1pK2g7CiAgICAgICAgICAgICAgIGVuZDsKICAgd3JpdGVsbihzcGVzYW1pbmltYSk7IHsgcHJpbnQgcmVzdWx0IH0KZW5kLgo=