#include #include using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000000000000 int main(){ int N; cin>>N; vector> X(N); rep(i,N){ cin>>X[i].second>>X[i].first; } sort(X.rbegin(),X.rend()); int D = 0; int n = N; rep(i,10000){ n--; if(i%2 && n!=0){ n--; D++; } if(n==0)break; } vector dp(D+1,Inf); dp[0] = 0; rep(i,N){ vector ndp(D+1,Inf); rep(j,D+1){ if(dp[j]==Inf)continue; if(j!=D){ ndp[j+1] = min(ndp[j+1],dp[j]); } ndp[j] = min(ndp[j],dp[j] + X[i].second + X[i].first * (i-j)); } swap(dp,ndp); } cout<