#include using namespace std; using ll = long long; using P = pair; int main () { int N; cin >> N; std::vector

A(N); for (auto& [a, b] : A) { cin >> a >> b; } ll ans = 0, sa = 0, sb = 0; for (int i = N - 1; i >= 0; i --) { auto [a, b] = A[i]; ans += max(sa * b, sb * a); sa += a; sb += b; } std::cout << ans << std::endl; }