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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define fru(j,n) for(int j=0; j<(n); ++j)
#define tr(it,v) for(auto it=(v).begin(); it!=(v).end(); ++it)
//#define tr(it,v) for(typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define x first
#define y second
#define pb push_back
#define ALL(G) (G).begin(),(G).end()

#if 0
#define DEB printf
#else
#define DEB(...)
#endif

typedef long long ll;
typedef long long LL;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const int inft = 1000000009;
const int mod = 1000000007;
const int MAXN = 1000006,T=1024*1024;

vector<pll> A;//at+b

/*******************************************************************/
struct node {
	node *c[2], *p;
	ll b;
	int v;
	int s;
	bool hasp() { return p; }
	int dir(node *n) { return c[0] != n; }
	void upd() {
		b = A[v].x; fru(i,2) if(c[i]) b +=c[i]->b;
		s = 1; fru(i,2) if(c[i]) s += c[i]->s;
	}
};

void rot(node *n, int d) {
	node *m = n->c[d];
	if((n->c[d] = m->c[!d])) n->c[d]->p = n;
	m->c[!d] = n;
	if(n->hasp()) n->p->c[n->p->dir(n)] = m;
	m->p = n->p;
	n->p = m;
	n->upd();
	m->upd();
}

void splay(node *n) {
	while(n->hasp()) {
		node *p1 = n->p, *p2 = p1->p;
		if(!p1->hasp()) return rot(p1,p1->dir(n));
		int d1 = p1->dir(n), d2 = p2->dir(p1);
		if(d1 == d2) swap(p1,p2);
		rot(p1,d1);
		rot(p2,d2);
	}
}
node *root;

void  insert_atS(int pos,int value){
	node *curr=new node();
	curr->v=value;
	if(root==NULL){
		root=curr;
		root->upd();
		splay(root);
		return;
	}
	int mi=pos;
	node *temp=root;
	if(mi==0){
		while(temp->c[0])temp=temp->c[0];
		temp->c[0]=curr;
		temp->c[0]->p=temp;
		temp->c[0]->upd();
		splay(root=temp->c[0]);
		return;
	}
	while(mi){
		if(temp->c[0] && temp->c[0]->s>=mi){temp=temp->c[0];continue;}
		else if(temp->c[0]){
			mi-=temp->c[0]->s;
		}
		mi--;
		if(mi==0)break;
		temp=temp->c[1];
	}
	if(temp->c[1]==NULL){
		temp->c[1]=curr;
		temp->c[1]->p=temp;
		temp->c[1]->upd();
		splay(root=temp->c[1]);
		return;
	}
	temp=temp->c[1];
	while(temp->c[0])temp=temp->c[0];
	temp->c[0]=curr;
	temp->c[0]->p=temp;
	temp->c[0]->upd();
	splay(root=temp->c[0]);
	return;
}

int get_atS(int pos){
	int mi=pos;
	node *temp=root;
	bool here=0;
	while(1){
		if(temp->c[0] && temp->c[0]->s>mi){temp=temp->c[0];continue;}
		else if(temp->c[0]){
			mi-=temp->c[0]->s;
		}
		if(mi==0){here=1;break;}
		mi--;
		temp=temp->c[1];
	}
	if(!here)while(temp->c[0])temp=temp->c[0];
	splay(root=temp);
	return temp->v;	
}

ll count_atS(int pos){
	ll ret=0;
	int mi=pos;
	node *temp=root;
	if(mi==0)return 0;
	while(mi){
		if(temp->c[0] && temp->c[0]->s>=mi){temp=temp->c[0];continue;}
		else if(temp->c[0]){
			mi-=temp->c[0]->s;
			ret+=temp->c[0]->b;
		}
		mi--;
		ret+=A[temp->v].x;
		if(mi==0)break;
		temp=temp->c[1];
	}
	splay(root=temp);
	return ret;
}

ll count_at(int pos){//return sum of <*,> < pos
	DEB("count at %d\n",pos);
	ll ret=count_atS(pos);
//	ll ret2=0;fru(i,pos)ret2+=A[V[i].y].x;
//	DEB("ans %lld :: %lld\n",ret,ret2);
	return ret;
}
void insert_at(int pos,int value){ 
	DEB("insert at %d: %d\n",pos,value);
	insert_atS(pos,value);
//	V.insert(V.begin()+pos,value);
	return;
}

int get_at(int pos){
	int ret=get_atS(pos);
//	DEB("ans %lld %d :: %lld %d\n",ret.x,ret.y,V[pos].x,V[pos].y);
	return ret;//V[pos];
}
/****************************************************************/
int n;
ll s[2*T],bb[2*T],mn[MAXN],poczwie[MAXN];

ll ssum(ll *drz, int a,int b){
	a+=T;b+=T;
	ll ret=0;
	while(a<=b){
		if(a%2==1){ret+=drz[a];a++;}
		if(b%2==0){ret+=drz[b];b--;}
		a/=2;
		b/=2;
	}
	return ret;
}

void sset(ll *drz, int a,int value){
	a+=T;
	while(a){
		drz[a]+=value;
		a/=2;
	}
}

ll compute(int m){
	int u=get_at(m);
	ll BB=count_at(m);
	return A[u].x*mn[u]+A[u].y+BB-poczwie[u];
}
void solve() {
	scanf("%d",&n);
	A.resize(n);
	fru(i,n)scanf("%lld%lld",&A[i].x,&A[i].y);
	sort(ALL(A));
	fru(i,n){
		int k=i;//na k da sie na pewno,
		DEB("rozwazam %d\n",i);
		pair<ll,int> me(A[i].y,i);
		if(i==0 || compute(0)<me.x){
			poczwie[me.y]=0;
			insert_at(0,me.y);
			mn[me.y]=0;
			continue;
		}
		node *temp=root,*prev=root;
		int nr=0;
		ll BB=0;

		while(temp){
			prev=temp;
			int m=nr+(temp->c[0]?temp->c[0]->s:0);
			int u=temp->v;
			if(A[u].x*mn[u]+A[u].y+BB+(temp->c[0]?temp->c[0]->b:0LL)-poczwie[u]>A[i].y+A[i].x*m){
				nr+=(temp->c[0]?temp->c[0]->s:0)+1;
				BB+=(temp->c[0]?temp->c[0]->b:0LL)+A[u].x;
				temp=temp->c[1];
			}else{
				k=m;
				temp=temp->c[0];
			}
		}
	//	splay(root=prev);
		me.x=A[i].y+k*A[i].x;
		insert_at(k,me.y);
		poczwie[me.y]=count_at(k);
		mn[me.y]=k;

	}
	ll ret=0;
	fru(i,n){
		//dorzucam u
		int u=get_at(i);
		ll nr=ssum(s,0,u);
		ll B=ssum(bb,u,n);
		ret+=A[u].x*nr+A[u].y+B;
		sset(s,u,1);
		sset(bb,u,A[u].x);
		printf("%lld\n",ret);
	}
}

int main() {
	solve();
	return 0;
}