#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include using namespace std; #include using namespace atcoder; #define REP(i, n) for(int i = 0; i < (int)n; i++) #define LREP(i, n) for(LL i = 0; i < (LL)n; i++) #define RREP(i, n) for(int i = (int)n-1; i >= 0; i--) #define V(T) vector #define P pair #define LP pair #define T3 tuple #define T4 tuple #define INF 1000000007 #define SIZE 500100 #define MOD 1000000007 typedef long long LL; #define SIZE2 2010 LL N, M; LL A[SIZE], B[SIZE]; bool done[SIZE2][SIZE2]; LL memo[SIZE2][SIZE2]; LL dfs(LL i, LL j) { if (i == N) { if (j == M) return 0; return 1e18; } if (done[i][j]) return memo[i][j]; LL res = dfs(i + 1, j) + (A[i] + B[i] * (i - j)); if (j < M) res = min(res, dfs(i + 1, j + 1)); done[i][j] = true; return memo[i][j] = res; } int main() { cin >> N; REP(i, N) cin >> A[i] >> B[i]; M = N / 3; V(LP) X; REP(i, N) X.push_back(LP(B[i], A[i])); sort(X.begin(), X.end(), greater()); REP(i, N) { A[i] = X[i].second; B[i] = X[i].first; } cout << dfs(0, 0) << endl; }