#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef pair pint; typedef pair pli; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; int main(){ int n; cin>>n; ll a[n],b[n]; rep(i,n)cin>>a[i]>>b[i]; vector ord(n); iota(ord.begin(),ord.end(),0); sort(ord.begin(),ord.end(),[&](auto x,auto y){ return b[x]==b[y] ? a[x]>a[y] : b[x]>b[y]; }); ll dp[n+1][n+1]; rep(i,n+1)rep(j,n+1)dp[i][j]=longinf; dp[0][0]=0; rep(i,n)rep(j,n){ int idx=ord[i]; dp[i+1][j+1]=min(dp[i][j]+a[idx]+b[idx]*j,dp[i+1][j+1]); dp[i+1][j]=min(dp[i+1][j],dp[i][j]); dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j+1]); } int m; if(n%3==0)m=n/3*2; if(n%3==1)m=n/3*2+1; if(n%3==2)m=n/3*2+2; cout<