1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define FOR(i,n) REP(i,0,(int)n-1)
#define mp make_pair
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define VI vector<int>
#define fi first
#define se second

const int MAXN = 1000042;
ll sufsum[MAXN];
bool visited[MAXN];

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	vector<pair<ll,ll> > V;
	FOR(i,n) {
		int a,b;
		cin>>a>>b;
		V.pb(mp(a,b));
	}
	sort(V.begin(), V.end());
	//FOR(i,n) cout<<V[i].fi<<", "<<V[i].se<<"\n";
	//cout<<"\n";
	ll res = 0;
	FOR(i,n) {
		ll best = 0, val;
		int kand = -1, cnt = 0;
		FOR(j,n) {
			if(visited[j]) {
				cnt++;
				continue;
			}
			val = (1LL*cnt*V[j].fi) + V[j].se + sufsum[j]; 
			//cout<<"j: "<<j<<" = "<<val<<"\n";
			if(val > best) {
				best = val;
				kand = j;
			}
		}
		res += best;
		visited[kand] = true;
		for(int j = kand; j>=0; j--) sufsum[j] += V[kand].fi;
		cout<<res<<"\n";
	}
	return 0;
}