n = int(input()) tot_a = 0 tot_b = 0 ans = 0 AB = [list(map(int, input().split())) for _ in range(n)] for a, b in AB[::-1]: bef = b * tot_a aft = a * tot_b ans += max(bef, aft) tot_a += a tot_b += b print(ans)