n = int(input()) ab = [tuple(map(int,input().split())) for _ in range(n)] s = [0]*n; t = [0]*n; ans = 0 for i,(a,b) in enumerate(ab[:0:-1],1): s[-i-1] = s[-i]+a; t[-i-1] = t[-i]+b for i,(a,b) in enumerate(ab): ans += max(a*t[i],b*s[i]) print(ans)