#include using namespace std; #define sc cerr #define qlog(x) {sc<<#x<<" = "<<(x)<<"\n";} #define rep(i,l,r) for(ll i=(l);i<=(r);i++) #define irep(i,l,r) for(ll i=(l);i>=(r);i--) #define qloga(a,l,r) {sc<<#a<<" : "; rep(I,l,r){sc<<(a)[I]<<" ";}sc<<"\n";} #define qlogSTL(a) {sc<<#a<<" : "; for(const auto &I:(a)){sc<<(I)<<" ";}sc<<"\n";} typedef long long ll; typedef unsigned long long ull; #define int ll constexpr int N=2e3+10; int n; ll f[N][N]; pair a[N]; void upd(ll &x,ll y){ x=min(x,y); } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n; rep(i,1,n)cin>>a[i].second>>a[i].first; sort(a+1,a+1+n,greater>()); memset(f,0x3f,sizeof(f)); f[0][0]=0; rep(i,0,n)rep(j,0,n){ int x=a[i+1].second; int y=a[i+1].first; upd(f[i+1][j],f[i][j]); upd(f[i+1][j+1],f[i][j]+x+j*y); } ll ans=0; int cnt=0; rep(i,0,n){ if(cnt>=n){ ans=f[n][i]; break; } cnt++; if(i&1)cnt++; } cout<