#include using namespace std; using ll =long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin>>N; vector DP(N+1,-1e18); vector A(N),B(N); for(int i=0;i>A[i]>>B[i]; } DP[0]=0; for(int i=N-1;i>=0;i--){ vector NDP(N+1,-1e18); for(int j=0;j<=N;j++){ if(j!=N)NDP[j+1]=max(NDP[j+1],DP[j]+B[i]); NDP[j]=max(NDP[j],DP[j]+A[i]*j); } swap(DP,NDP); } ll an=0; for(int i=0;i<=N;i++)an=max(an,DP[i]); cout<