n = int(input()) AB = [list(map(int, input().split())) for _ in range(n)] accumA = [0 for _ in range(n)] accumA[n - 1] = AB[n - 1][0] accumB = [0 for _ in range(n)] accumB[n - 1] = AB[n - 1][1] for i in range(n - 2, -1, -1): accumA[i] = accumA[i + 1] + AB[i][0] accumB[i] = accumB[i + 1] + AB[i][1] ans = 0 for i in range(n - 1): ans += max(AB[i][0] * accumB[i + 1], AB[i][1] * accumA[i + 1]) print(ans)