var
n:longint;
t,d:array[1..100000] of longint;
s:array[1..100000] of real;
procedurepx(x,y:longint);var
l,h,k:longint;
mid,f:real;
begin
l:=x;h:=y;
mid:=s[(l+h) div2];
repeatwhile mid>s[l] do inc(l);
while mid<s[h] do dec(h);
if l<=h thenbegin
k:=t[l];t[l]:=t[h];t[h]:=k;
k:=d[l];d[l]:=d[h];d[h]:=k;
f:=s[l];s[l]:=s[h];s[h]:=f;
inc(l);dec(h);
end;
until l>h;
if x<h then px(x,h);
if y>l then px(l,y);
end;
var
i,j,l,x:longint;
ans:int64;
begin
readln(n);
for i:=1to n dobegin
readln(t[i],d[i]);
s[i]:=t[i]/d[i];
l:=l+d[i];
end;
px(1,n);
for i:=1to n dobegin
l:=l-d[i];
ans:=ans+l*2*t[i];
end;
writeln(ans);
end.