#include #include #include using namespace std; long long cost[2001][2001]; int main () { int n; cin >> n; vector > P(n); for (auto &p : P) cin >> p.second >> p.first; sort(P.rbegin(), P.rend()); for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { long long c = cost[i-1][j-1] + P[i-1].second + P[i-1].first * (j-1); if (i == j || cost[i-1][j] > c) { cost[i][j] = c; } else { cost[i][j] = cost[i-1][j]; } } } cout << cost[n][2*(n+1)/3] << endl; }