#include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f, MOD = 1000000007; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; /*-----------------------------------------*/ int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int n; cin >> n; vector > ba(n); REP(i, n) cin >> ba[i].second >> ba[i].first; sort(ALL(ba), greater >()); vector > dp(n + 1, vector(n + 1, LINF)); dp[0][0] = 0; FOR(i, 1, n + 1) REP(j, i + 1) { dp[i][j] = min((j > 0 ? dp[i - 1][j - 1] : LINF), dp[i - 1][j] + ba[i - 1].second + (long long)ba[i - 1].first * (i - j - 1)); } cout << dp[n][n / 3] << '\n'; return 0; }