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
55
56
57
58
59
60
61
62
63
#include <cstdio>
#include <vector>
#include <algorithm>

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,b,e) for(int i=b; i<=e; i++)
#define FORD(i,b,e) for(int i=b; i>=e; i--)
#define PB push_back
using namespace std;

typedef vector <int> VI;
typedef vector < VI > VVI;
typedef pair<int, int> PII;
typedef unsigned long long LL;

#define N 1000009

struct F{
	LL a, b, left, right, used;
};

bool comp(F a, F b){
	return a.a < b.a;
}

F tab[N];
LL fin[N];

int n;
LL getBest(){
	LL bestVal = 0;
	int bestId = -1;
	REP(i,N){
		if(!tab[i].used){
			LL tmp = tab[i].b + tab[i].left * tab[i].a + tab[i].right;
			if(tmp > bestVal){
				bestVal = tmp;
				bestId = i;
			}
		}
	}

	tab[bestId].used = true;
	REP(i,bestId) tab[i].right += tab[bestId].a; 
	FOR(i, bestId+1, n-1){
		tab[i].left++;
	}
	return bestVal;
}

int main(){
	scanf("%d", &n);
	REP(i,n) scanf("%lld %lld", &tab[i].a, &tab[i].b);

	sort(tab, tab+n, comp);
	
	LL res = 0;

	REP(i,n){
		res += getBest();
		printf("%lld\n", res);
	}
}