#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int n, m;
ll dp[2005][2005];
vector<P> v;

int main() {
    cin >> n;
    m = n/3;
    REP(i,n){
        ll a, b;
        cin >> a >> b;
        v.push_back({b,a});
    }
    SORT(v);
    reverse(ALL(v));
    REP(i,n+1) fill(dp[i], dp[i]+n+1, LLINF/3);
    dp[0][0] = 0;
    for(int i=0;i<n;i++){
        ll a = v[i].second, b = v[i].first;
        dp[i+1][0] = dp[i][0] + b*i + a;
        for(int j=1;j<=m;j++){
            dp[i+1][j] = min(dp[i][j] + b*(i-j) + a, dp[i][j-1]);
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}