#include #include #include #include #include #include #include #include #include #include #define ll long long #define db double using namespace std; const ll N = 2e5 + 100; ll sma,smb,ans,n; ll a[N],b[N]; int main() { scanf("%lld",&n); for (ll i = 1;i <= n;i++) { scanf("%lld%lld",&a[i],&b[i]); } sma = smb = ans = 0; for (ll i = n;i > 0;i--) { ans += max(a[i] * smb,b[i] * sma); sma += a[i]; smb += b[i]; } printf("%lld",ans); return 0; }