#include #define rep(i,n) for(int i=0;i ; const int INF = 1e9; const int MOD = 1000000007; int main(){ int n; cin >> n; vector

ab(n); rep(i,n) cin >> ab[i].second >> ab[i].first; sort(ab.begin(),ab.end(),greater

()); vector> dp(n+1,vector(n+1,INF)); dp[0][0] = 0; for(int i=1;i<=n;i++){ for(int j=0;j<=n;j++){ if(j>0) dp[i][j] = min(dp[i-1][j-1], dp[i-1][j] + ab[i-1].second + ab[i-1].first*(i-j-1)); else dp[i][j] = dp[i-1][j] + ab[i-1].second + ab[i-1].first*(i-j-1); } } cout << dp[n][n/3] << endl; return 0; }