#include using namespace std; int n; pair p[3000]; long long memo[2010][2010]; long long dp(long long i, int nk, int cnt){ if(i == n){ return 0; } if(memo[i][nk] != -1) return memo[i][nk]; long long ans = dp(i+1, nk, cnt+1) + p[i].first * cnt + p[i].second; if(nk > 0){ ans = min(ans, dp(i+1, nk-1, cnt)); } return memo[i][nk] = ans; } int main(){ cin >> n; for(int i = 0;i < n;i++){ cin >> p[i].second >> p[i].first; } sort(p, p+n, greater >()); memset(memo, -1, sizeof(memo)); cout << dp(0, n/3, 0) << endl; return 0; }