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 <bits/stdc++.h>
#define int long long
using namespace std;
int const N = 1e6 + 5;
pair <int,int>  P[N];
int odp[N] = {0}, suf[N] = {0};
#define pi pair < pair <int, int >, int > 
#define x(n,m,h) pair < pair <int ,int >, int > (pair <int, int> (n,m), h)//!!
#define st first 
#define nd second
int suma[N] = {0};
bool uzy[N] = {0};
void add(const int &a,const int &b,const int &c){
	for (int i = a; i <= b; ++i){
		suma[i] += c;
	}
}
pair <int,int> mina(const int &a,const int &b){
	int x = 1e18;
	int j = b;
	for (int i = b; i >= a; --i){
		if(!uzy[i]) {
			if(suma[i] <= x)j = i;
			x = min(suma[i], x);
		}
	}	
	uzy[j] = 1;
	return pair <int,int> (x,j);
}
main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;	
	int pomoc = 0;
	for (int i = 0; i < n; ++i){
		cin >> P[i].st >> P[i].nd;
	}
	sort(P, P+n);
	for (int i = 0; i < n; ++i) suf[i] = P[i].st;
	for (int i = n-2; i >= 0; --i)suf[i] += suf[i+1];
	
	for (int i = 0; i < n; ++i){
		add(i,i, (i-1)*P[i].st + P[i].nd + suf[i]);
	}
	int suma3 = 0, sima = 0;
	for (int i = 0; i < n; ++i){
		suma3 += i*P[i].st + P[i].nd;
		sima += suma[i];
	}
	odp[n-1] = suma3;
	for (int i = n-2; i >= 0; --i){
		pair <int,int > x = mina(0,n-1);
		suma3 -= x.st;
		add(0, x.nd, -P[x.nd].st);
		for (int h = x.nd+1;h < n; ++h){
			add(h,h,-P[h].st);
		}
		odp[i] = suma3;
	}
	for (int i = 0; i < n; ++i){
		cout << odp[i] << '\n';
	}
}