#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair P; typedef pair PP; const ll MOD=1e9+7; int main(){ int N; cin>>N; vector A(N),B(N); for(int i=0;i>A[i]>>B[i]; } /* vector order(N); iota(order.begin(),order.end(),0); sort(order.begin(),order.end(), [&](const int lhs,const int rhs){ if(B[lhs]!=B[rhs]){ return B[lhs]>B[rhs]; }else{ return A[lhs] sumB(N,0); sumB[0]=B[order[0]]; for(int i=1;i sumA(N+1),sumB(N+1); sumA[N-1]=A[N-1]; sumB[N-1]=B[N-1]; for(int i=N-2;i>=0;i--){ sumA[i]=sumA[i+1]+A[i]; sumB[i]=sumB[i+1]+B[i]; } ll ans=0; for(int i=N-1;i>=0;i--){ ll lhs=B[i]*sumA[i+1]; ll rhs=A[i]*sumB[i+1]; if(lhs>rhs){ ans+=lhs; }else{ ans+=rhs; } } cout<