#include #include using namespace std; #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int n; cin >> n; vector a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; long long as = 0, bs = 0; long long ans = 0; for (int i = n - 1; i >= 0; i--){ ans += max(as * b[i], bs * a[i]); as += a[i]; bs += b[i]; } cout << ans << endl; return 0; }