#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; struct Product { ll a, b; Product(ll _a, ll _b) :a(_a), b(_b) {} bool operator<(const Product &p) { return b > p.b; } }; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll N; scanf("%lld", &N); vector vp; vp.reserve(N); for (ll i = 0; i < N; i++) { ll a, b; scanf("%lld %lld", &a, &b); vp.emplace_back(a, b); } sort(vp.begin(), vp.end()); vector> dp(N + 1, vector(N + 1, INF)); dp[0][0] = 0; for (ll i = 0; i < N; i++) { for (ll j = 0; j <= N / 3; j++) { if (dp[i][j] == INF) continue; chmin(dp[i + 1][j], dp[i][j] + vp[i].a + vp[i].b * (i - j)); chmin(dp[i + 1][j + 1], dp[i][j]); } } cout << dp[N][N / 3] << endl; return 0; }