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
#include <algorithm>
#include <cstdio>
#include <utility>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REPD(i,n) FORD(i,0,n)
#define FT first
#define SD second

typedef long long LL;

pair<LL, LL> p[1000000];
bool u[1000000];

int main() {
	int n;
	scanf("%d", &n);
	REP(i,n) scanf("%lld%lld", &p[i].FT, &p[i].SD);
	sort(p, p + n);
	LL res = 0;
	REP(k,n) {
		LL bestVal = 0, s = 0;
		int best = -1, m = k;
		REPD(i,n) {
			if (u[i]) {
				s += p[i].FT;
				--m;
				continue;
			}
			LL val = s + m * p[i].FT + p[i].SD;
			if (val >= bestVal) {
				bestVal = val;
				best = i;
			}
		}
		res += bestVal;
		u[best] = 1;
		printf("%lld\n", res);
	}
}