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
#define _USE_MATH_DEFINES/////////////////////////////////////////////////////
#include <bits/stdc++.h>//////////////////////////////////////////////////////
#ifdef LOC////////////////////////////////////////////////////////////////////
#include "debuglib.h"/////////////////////////////////////////////////////////
#else/////////////////////////////////////////////////////////////////////////
#define deb(...)//////////////////////////////////////////////////////////////
#define DBP(...)//////////////////////////////////////////////////////////////
#endif////////////////////////////////////////////////////////////////////////
#define x first///////////////////////////////////////////////////////////////
#define y second//////////////////////////////////////////////////////////////
#define mp make_pair//////////////////////////////////////////////////////////
#define pb push_back//////////////////////////////////////////////////////////
#define sz(x)int((x).size())//////////////////////////////////////////////////
#define each(a,x)for(auto&a:(x))//////////////////////////////////////////////
#define all(x)(x).begin(),(x).end()///////////////////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)////////////////////////////////////
using namespace std;using namespace rel_ops;using ll=int64_t;using Pii=pair///
<int,int>;using ull=uint64_t;using Vi=vector<int>;void run();int main(){cin.//
sync_with_stdio(0);cin.tie(0);cout<<fixed<<setprecision(20);run();return 0;}//
//--------------------------------------------------------------------------//

constexpr ll INF = 1e9;

struct SegmentTree {
	struct Node {
		int extra{0}, great{INF};
		DBP(extra, great);
	};

	vector<Node> V;
	int len, origLen;

	void init(int n) {
		origLen = n;
		for (len = 1; len < n; len *= 2);
		V.assign(len*2, {});
	}

	void set(int i, int val) {
		V[len+i].extra = V[len+i].great = val;
	}

	void update(int i) {
		V[i].great = max(V[i*2].great, V[i*2+1].great) + V[i].extra;
	}

	void build() {
		for (int i = len-1; i > 0; i--) update(i);
	}

	int get(int i) {
		i += len;
		int ret = V[i].extra;
		while ((i /= 2) > 0) ret += V[i].extra;
		return ret;
	}

	void push() {
		rep(i, 1, len) {
			V[i*2].extra += V[i].extra;
			V[i*2+1].extra += V[i].extra;
			V[i].extra = 0;
		}
	}

	void add(int vBegin, int vEnd, int val, int i, int begin, int end) {
		if (begin >= vEnd || vBegin >= end) return;

		if (vBegin <= begin && end <= vEnd) {
			V[i].extra += val;
			V[i].great += val;
			return;
		}

		int mid = (begin+end) / 2;
		add(vBegin, vEnd, val, i*2, begin, mid);
		add(vBegin, vEnd, val, i*2+1, mid, end);
		update(i);
	}

	int lowerBound(int val, int i, int begin, int end) {
		if (i >= len) return i - len + (V[i].extra < val);

		int mid = (begin+end) / 2;
		val -= V[i].extra;

		if (V[i*2].great >= val) {
			return lowerBound(val, i*2, begin, mid);
		}
		return lowerBound(val, i*2+1, mid, end);
	}

	void add(int vBegin, int vEnd, int val) { add(vBegin, vEnd, val, 1, 0, len); }
	int lowerBound(int val) { return lowerBound(val, 1, 0, len); }

	void rawr(int i) {
		int coord = get(i);
		int from = lowerBound(coord), to = lowerBound(coord+1);
		add(0, from, 1);
		add(to, origLen, -1);
	}
};

// ---

int n;
vector<Pii> points;
bool twoD;

Vi orderX, posX, orderY, posY;
SegmentTree treeX, treeY;

void rawr(int i) {
	treeX.rawr(posX[i]);
	if (twoD) treeY.rawr(posY[i]);
}

ll getAnswer(int without) {
	ll ret = 0;
	treeX.push();
	if (twoD) treeY.push();

	rep(i, 0, n) if (i != without) {
		int a = treeX.V[treeX.len + posX[i]].extra;
		if (twoD) {
			int b = treeY.V[treeY.len + posY[i]].extra;
			ret += ll(a) * ll(b);
		} else {
			ret += a;
		}
	}
	return ret;
}

void handle(int k) {
	vector<SegmentTree::Node> savedX = treeX.V, savedY;
	if (twoD) savedY = treeY.V;

	rep(i, k+1, n) rawr(i);

	ll ans = getAnswer(k);
	ans += ll(points[k].x) * points[k].y;
	cout << ans << '\n';

	treeX.V.swap(savedX);
	if (twoD) treeY.V.swap(savedY);
	rawr(k);
}

void solve() {
	orderX.resize(n);
	iota(all(orderX), 0);
	sort(all(orderX), [](int l, int r) { return points[l].x < points[r].x; });

	orderY.resize(n);
	iota(all(orderY), 0);
	sort(all(orderY), [](int l, int r) { return points[l].y < points[r].y; });

	posX.resize(n);
	rep(i, 0, n) posX[orderX[i]] = i;

	posY.resize(n);
	rep(i, 0, n) posY[orderY[i]] = i;

	treeX.init(n);
	treeY.init(n);
	
	rep(i, 0, n) {
		treeX.set(i, points[orderX[i]].x);
		treeY.set(i, points[orderY[i]].y);
	}

	treeX.build();
	treeY.build();
	rep(i, 0, n) handle(i);
}

void run() {
	bool x1 = 1, y1 = 1;
	cin >> n;
	points.resize(n);

	each(p, points) {
		cin >> p.x >> p.y;
		if (p.x != 1) x1 = 0;
		if (p.y != 1) y1 = 0;
	}

	if (!y1 && x1) {
		swap(x1, y1);
		each(p, points) swap(p.x, p.y);
	}

	twoD = !y1;
	solve();
}