#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; struct ST { ll val; ll A, B; int i; }; bool operator<(const ST& a, const ST& b){ if(a.val == b.val) return a.B < b.B; return a.val > b.val; } priority_queue que[2005]; bool checked[2005]; int main(){ int N; cin >> N; int M = 0; { vector tmp(N,0); int j = N-1; rep(d,N){ if(tmp[d] == -1) break; M++; if(d%2 == 1){ tmp[j] = -1; j--; } } } vector v; rep(i,N){ ll a, b; cin >> a >> b; v.push_back((ST){0LL,a,b,i}); } rep(i,N-M){ ll d = M+i; vector w; rep(j,v.size()){ ST tmp = v[j]; tmp.val = tmp.A + d * tmp.B; w.push_back(tmp); } sort(ALLOF(w)); rep(j,w.size()){ if(checked[w[j].i]) continue; checked[w[j].i] = true; break; } } ll ret = 0; vector bs; rep(i,N){ if(checked[i]) continue; bs.push_back(v[i].B); ret += v[i].A; } sort(ALLOF(bs)); reverse(ALLOF(bs)); rep(i,bs.size()){ ret += i * bs[i]; } cout << ret << endl; return 0; }