#include using namespace std; using i64 = long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif auto solve = [&]() { int n; cin >> n; vector a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } int sa = 0, sb = 0; i64 ans = 0; for (int i = n - 1; i >= 0; i--) { ans += max(1LL * a[i] * sb, 1LL * b[i] * sa); sb += b[i]; sa += a[i]; } cout << ans << '\n'; }; solve(); return 0; }