QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#267937#6304. RectanglezhaohaikunAC ✓2031ms154492kbC++147.2kb2023-11-27 21:21:152023-11-27 21:21:16

Judging History

你现在查看的是最新测评结果

  • [2023-11-27 21:21:16]
  • 评测
  • 测评结果:AC
  • 用时:2031ms
  • 内存:154492kb
  • [2023-11-27 21:21:15]
  • 提交

answer

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
// MagicDark
#include <bits/stdc++.h>
#define mid ((l + r) >> 1)
#define ls num << 1
#define rs ls | 1
#define li ls, l, mid
#define ri rs, mid + 1, r
#define x1 cryforthezi1
#define x2 cryforthezi2
#define y1 cryforthezi3
#define y2 cryforthezi4
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T &x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T &x, T y) {x = min(x, y);}
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 2e5 + 10, MOD = 998244353, T = 1e9, inv6 = 166374059;
int n, x1[N], y1[N], x2[N], y2[N], yy[N], ans, lp[N], rp[N];
int cx, cy, tx[N], ty[N];
int len[N << 2], mx[N << 2], tag[N << 2], seg[N << 2], lmax[N], rmin[N];
inline void add(int &x, ll y) {x = (x + y) % MOD;}
void build(int num, int l, int r) {
	seg[num] = mx[num] = tag[num] = 0, len[num] = ty[r + 1] - ty[l];
	if (l == r) return;
	build(li), build(ri);
}
vector <tuple <int, int>> g1;
vector <tuple <int, int>> g2;
vector <tuple <int, int>> g3;
void down(int num, int x) {
	g1.emplace_back(num, mx[num]);
	g2.emplace_back(num, tag[num]);
	g3.emplace_back(num, seg[num]);
	mx[num] = tag[num] = x;
	seg[num] = (ll) len[num] * x % MOD;
}
void pushdown(int num) {
	if (tag[num]) {
		g2.emplace_back(num, tag[num]);
		down(ls, tag[num]), down(rs, tag[num]);
		tag[num] = 0;
	}
}
void pushup(int num) {
	g1.emplace_back(num, mx[num]);
	g3.emplace_back(num, seg[num]);
	mx[num] = mx[rs];
	seg[num] = (seg[ls] + seg[rs]) % MOD;
}
void change(int num, int l, int r, int L, int R, int x) {
	if (L <= l && r <= R) return down(num, x);
	pushdown(num);
	if (mid >= L) change(li, L, R, x);
	if (mid < R) change(ri, L, R, x);
	pushup(num);
}
int query(int num, int l, int r, int L, int R) {
	if (L <= l && r <= R) return seg[num];
	pushdown(num);
	if (mid >= R) return query(li, L, R);
	if (mid < L) return query(ri, L, R);
	return (query(li, L, R) + query(ri, L, R)) % MOD;
}
int findpos(int num, int l, int r, int x) {
	if (l == r) return l;
	pushdown(num);
	if (mx[ls] > x) return findpos(li, x);
	return findpos(ri, x);
}
vector <int> gg[N << 2];
void modify(int num, int l, int r, int L, int R, int x) {
	if (L <= l && r <= R) return gg[num].push_back(x);
	if (mid >= L) modify(li, L, R, x);
	if (mid < R) modify(ri, L, R, x);
}
void analysis(int num, int l, int r) {
	unsigned t1 = g1.size(), t2 = g2.size(), t3 = g3.size();
	for (int id: gg[num]) {
		int g = mx[1] <= y1[id] ? cy : findpos(1, 1, cy, y1[id]) - 1;
		if (yy[id] <= g) change(1, 1, cy, yy[id], g, y1[id]);
	}
	if (l == r) {
		if (lmax[l]) {
			int L = lower_bound(ty + 1, ty + cy + 1, lmax[l]) - ty;
			if (L <= cy) {
				int R = mx[1] <= rmin[l] ? cy : findpos(1, 1, cy, rmin[l]) - 1;
				if (L <= R) add(ans, ((ll) (ty[R + 1] - ty[L]) * (rmin[l] + 1) % MOD - query(1, 1, cy, L, R) + MOD) * (tx[l + 1] - tx[l]));
			}
		}
	} else analysis(li), analysis(ri);
	while (g1.size() > t1) {
		int id = get <0> (g1.back());
		mx[id] = get <1> (g1.back());
		g1.pop_back();
	}
	while (g2.size() > t2) {
		int id = get <0> (g2.back());
		tag[id] = get <1> (g2.back());
		g2.pop_back();
	}
	while (g3.size() > t3) {
		int id = get <0> (g3.back());
		seg[id] = get <1> (g3.back());
		g3.pop_back();
	}
}
struct P1 {// 大根堆
	priority_queue <int> q1, q2;
	void insert(int x) {
		q1.push(x);
	}
	void erase(int x) {
		q2.push(x);
	}
	unsigned size() {
		return q1.size() - q2.size();
	}
	bool empty() {
		return q1.size() == q2.size();
	}
	int top() {
		while (q2.size() && q2.top() == q1.top()) q1.pop(), q2.pop();
		return q1.top();
	}
	void pop() {
		while (q2.size() && q2.top() == q1.top()) q1.pop(), q2.pop();
		q1.pop();
	}
};
struct P2 {// 小根堆
	priority_queue <int, vector <int>, greater <int>> q1, q2;
	void insert(int x) {
		q1.push(x);
	}
	void erase(int x) {
		q2.push(x);
	}
	unsigned size() {
		return q1.size() - q2.size();
	}
	bool empty() {
		return q1.size() == q2.size();
	}
	int top() {
		while (q2.size() && q2.top() == q1.top()) q1.pop(), q2.pop();
		return q1.top();
	}
	void pop() {
		while (q2.size() && q2.top() == q1.top()) q1.pop(), q2.pop();
		q1.pop();
	}
};
vector <int> ins[N], del[N];
int t1[N];
bool t2[N];
void solve() {
	F(i, 1, 2 * n + 5) {
		ins[i].clear();
		del[i].clear();
	}
	F(i, 1, 8 * n + 10) {
		gg[i].clear();
	}
	cx = 0, cy = 0;
	tx[++cx] = 1;
	ty[++cy] = 1;
	F(i, 1, n) {
		tx[++cx] = x1[i];
		if (x2[i] != T) tx[++cx] = x2[i] + 1;
		ty[++cy] = y1[i];
		if (y2[i] != T) ty[++cy] = y2[i] + 1;
	}
	sort(tx + 1, tx + cx + 1);
	F(i, 1, cx) lp[i] = 0, rp[i] = T + 1;
	sort(ty + 1, ty + cy + 1);
	tx[(cx = unique(tx + 1, tx + cx + 1) - tx)--] = T + 1;
	ty[(cy = unique(ty + 1, ty + cy + 1) - ty)--] = T + 1;
	build(1, 1, cy);
	F(i, 1, n) {
		int x1 = lower_bound(tx + 1, tx + cx + 1, ::x1[i]) - tx;
		int x2 = lower_bound(tx + 1, tx + cx + 1, ::x2[i] + 1) - tx;
		chkmax(lp[x2], ::x1[i]);
		chkmin(rp[x1 - 1], ::x2[i]);
		yy[i] = lower_bound(ty + 1, ty + cy + 1, y2[i] + 1) - ty;
		if (x1 > 1) modify(1, 1, cx, 1, x1 - 1, i), ins[1].push_back(i), del[x1].push_back(i);
		if (x2 <= cx) modify(1, 1, cx, x2, cx, i), ins[x2].push_back(i);
	}
	P1 l;
	P2 r;
	int L = 1, R = T;
	F(i, 1, cx) {
		for (int j: ins[i]) {
			l.insert(y1[j]);
			r.insert(y2[j]);
		}
		for (int j: del[i]) {
			l.erase(y1[j]);
			r.erase(y2[j]);
		}
		if (l.empty()) lmax[i] = 0, add(ans, (ll) T * (T - 1) / 2 % MOD * (tx[i + 1] - tx[i]));//, debug << i << " " << (ll) T * (T - 1) / 2 % MOD * (tx[i + 1] - tx[i]) % MOD;
		else {
			lmax[i] = l.top(), rmin[i] = r.top();
			if (lmax[i] <= rmin[i]) {
				add(ans, ((ll) T * (T - 1) / 2 - (ll) (T - (rmin[i] - lmax[i] + 1)) * (T - (rmin[i] - lmax[i] + 1) - 1) / 2) % MOD * (tx[i + 1] - tx[i]));
				swap(lmax[i], rmin[i]);
				lmax[i]++;
				rmin[i]--;
			}
		}
		if (lp[i]) {
			chkmax(L, lp[i]);
			chkmin(R, tx[i] - 1);
		}
		t1[i] = max(0, min(tx[i] - 1, R) - L + 1);
		t2[i] = R >= tx[i];
	}
	L = 1, R = T;
	DF(i, cx, 1) {
		if (rp[i] <= T) {
			chkmax(L, tx[i + 1]);
			chkmin(R, rp[i]);
		}
		int k1 = max(0, R - max(tx[i + 1], L) + 1);
		bool k2 = L <= tx[i];
		add(ans, (ll) (tx[i + 1] - tx[i]) * t1[i] % MOD * k1);
		if (t2[i]) add(ans, (ll) (tx[i + 1] - tx[i]) * (tx[i + 1] - tx[i] - 1) / 2 % MOD * k1);
		if (k2) add(ans, (ll) (tx[i + 1] - tx[i]) * (tx[i + 1] - tx[i] - 1) / 2 % MOD * t1[i]);
		if (t2[i] && k2) add(ans, (ll) (tx[i + 1] - tx[i]) * (tx[i + 1] - tx[i] - 1) % MOD * (tx[i + 1] - tx[i] - 2) % MOD * inv6);
	}
	analysis(1, 1, cx);
}
void zhk() {
	ans = 0;
	read(n);
	F(i, 1, n) read(x1[i]), read(y1[i]), read(x2[i]), read(y2[i]);
	solve();
	F(i, 1, n) swap(x1[i], y1[i]), swap(x2[i], y2[i]);
	solve();
	cout << ans << '\n';
}
signed main() {
	int _ = 1;
	cin >> _;
	while (_--) zhk();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 12ms
memory: 47292kb

input:

3
1
1 1 1000000000 1000000000
3
1 1 2 2
3 3 4 4
5 5 6 6
5
581574116 47617804 999010750 826131769
223840663 366320907 613364068 926991396
267630832 51913575 488301124 223957497
217461197 492085159 999485867 913732845
28144453 603781668 912516656 993160442

output:

230616300
64
977066618

result:

ok 3 number(s): "230616300 64 977066618"

Test #2:

score: 0
Accepted
time: 20ms
memory: 47320kb

input:

1000
10
5 7 6 10
4 3 6 9
1 6 3 7
1 1 7 10
1 2 7 7
5 2 8 3
2 1 5 7
1 1 10 6
1 7 2 8
4 7 5 9
10
6 6 8 10
4 4 9 9
2 4 6 5
5 3 10 10
1 3 4 4
2 2 3 6
7 5 8 6
2 7 8 8
5 7 10 10
2 4 7 8
10
3 6 6 10
1 2 7 4
7 5 10 9
4 5 8 9
2 7 5 9
2 2 9 7
3 3 8 4
1 1 8 6
5 4 10 6
3 9 7 10
10
3 1 8 9
1 3 8 10
4 1 7 4
2 4 5 ...

output:

28090346
21067815
91293528
63203269
14045217
24579047
49158123
56180656
10533942
83
28090372
101827338
512901428
38624242
10533932
42135595
7022614
7022661
7022622
31601641
21067817
35112979
7022628
7022682
17556485
42135554
59692019
28090452
14045202
73737099
42135505
31601703
49158091
28090434
108...

result:

ok 1000 numbers

Test #3:

score: 0
Accepted
time: 29ms
memory: 47032kb

input:

1000
10
56 6 85 86
2 67 79 76
41 32 57 94
7 24 95 72
4 82 98 99
21 16 64 95
5 15 97 50
75 34 93 63
65 1 74 40
62 50 91 57
10
1 66 4 99
73 28 80 35
9 46 84 72
57 12 74 75
24 20 72 86
30 35 51 52
20 32 80 48
1 27 38 38
79 30 91 86
49 11 78 31
10
84 36 95 84
18 76 83 96
87 6 97 24
59 74 79 81
36 6 49 1...

output:

286940182
6719
3879
10985
284425706
1482
154507014
337096188
15634
15198
13957
311811545
2065
487051821
104322525
4160
6232
3566
259869863
676660625
533734216
1108
210694302
941064564
9524057
366655439
960
712817222
294969344
505637269
5277
216
807601960
6489
192
252834684
9863
523061934
1036
370
16...

result:

ok 1000 numbers

Test #4:

score: 0
Accepted
time: 23ms
memory: 48660kb

input:

1000
10
151949335 343818689 226887829 843487881
26268786 629172470 727820988 753588469
239557045 129989050 828912527 803511337
216216272 737211068 952614934 901139965
9412307 270208240 969836975 781270622
210767204 691143582 734743967 978765608
115072779 149374200 365237395 723260248
373039270 50881...

output:

989992685
889170389
199600526
811602467
101647877
422274637
988817681
775346897
987827054
201664770
0
425324155
654779513
129937888
504567840
567363794
953468940
390846625
863893486
832900735
549488122
626520957
651708706
325695215
265584217
535054615
654784437
835844534
970196650
259827660
73563096...

result:

ok 1000 numbers

Test #5:

score: 0
Accepted
time: 371ms
memory: 47652kb

input:

20000
10
387518709 362080654 857718988 413892967
259574026 383071239 349422952 406322216
252781835 421214199 960954668 766986966
709548059 152868851 829506776 286195984
533564379 238783143 835360470 804665480
37715197 439312193 350269160 510361284
760325088 379134217 996444460 640572941
75706031 242...

output:

425031005
145199488
76594243
608094392
105901554
767793557
925027675
718008576
542146803
257776847
83948409
557131094
957234323
316994452
711146361
878596101
863265391
86278462
882556696
943381219
171834801
312110039
509815322
995001589
267270543
321796762
646607323
535110629
612892338
264981338
862...

result:

ok 20000 numbers

Test #6:

score: 0
Accepted
time: 352ms
memory: 46700kb

input:

20000
9
23397362 5465077 922916650 905326448
334129892 259574026 806023297 349422952
85390000 14589070 252781835 159363469
518493829 9904109 881263301 763351170
376515120 592421912 709548059 922381128
522936 888125869 919020884 968891551
192627293 528719402 238783143 846674462
269993278 155196111 41...

output:

38446691
441652008
80634077
86958519
313123987
37147655
292453230
135822548
347213034
875178269
572593450
121333363
910761745
288628833
144542647
336001702
492148086
504465362
307137735
40715447
936972207
895075762
698856636
442121431
960601688
728799681
619152060
51416671
586371383
183976942
996194...

result:

ok 20000 numbers

Test #7:

score: 0
Accepted
time: 437ms
memory: 47776kb

input:

2000
98
441828066 355550044 980140398 758338808
139187839 379489833 732496729 915149220
6198442 7406064 811667085 671521385
634108502 54340068 750182168 712125681
51518185 164417838 414217749 690302726
26971686 349814847 96913121 613904116
18885592 344395345 969337141 761958781
6500321 288362602 695...

output:

847505316
69861689
762022665
942187496
610542723
297361682
408287130
37288980
129194998
781348133
138625309
885806848
596340815
251557403
136654463
415973838
348935020
217451841
607735223
183258123
453186006
29511771
486730947
90933161
744360742
932334149
464917933
58351031
36268611
777434481
348682...

result:

ok 2000 numbers

Test #8:

score: 0
Accepted
time: 542ms
memory: 49104kb

input:

200
993
336152525 31049117 970839548 34483370
257968529 73378100 760295564 459870661
769587893 565770848 979251259 884779692
92706327 715631888 976631772 730467480
102936760 674056008 996888200 756831534
141490448 466112222 761954523 960644829
601216664 500053814 974949771 928192751
298296452 359164...

output:

163043779
101789580
214159985
605122084
222495872
595662571
919415389
27790333
940923361
745272650
432367810
269413997
881525570
275197159
128519736
759744770
394059985
858394070
885939030
507707772
380648232
853123251
659897376
142847962
866652391
78179639
672081467
655879491
267275050
880872481
74...

result:

ok 200 numbers

Test #9:

score: 0
Accepted
time: 114ms
memory: 47436kb

input:

200
989
1 8 5 9
6 4 9 7
9 4 10 10
3 3 8 7
7 1 9 5
9 4 10 6
4 3 7 8
3 1 7 4
2 5 3 6
3 4 4 7
4 3 7 9
1 2 9 8
4 3 6 4
2 2 6 10
6 8 7 10
2 1 3 9
1 1 4 10
1 5 4 8
2 3 4 9
4 3 9 9
1 2 6 7
7 4 9 5
4 3 8 10
4 1 8 10
7 2 8 5
2 4 3 8
5 4 10 6
9 1 10 5
5 3 7 7
6 4 10 10
6 6 7 9
1 1 3 10
2 2 9 8
2 3 7 8
3 9 10 ...

output:

3
1
2
1
2
1
2
3511294
1
3511294
2
2
3511295
3
2
2
6
1
2
1
1
3
1
3511294
1
1
10533874
1
1
1
2
2
1
6
432141794
1
1
2
4
1
3511294
2
3511294
3
3
1
2
1
853749714
3
3
7022585
3511294
2
2
3
7022585
3
14045164
1
2
1
1
1
4
2
4
3511295
3
3
3511295
3511295
7022585
1
2
1
3
2
1
7022585
2
2
2
3
2
7022585
2
4
3
2
...

result:

ok 200 numbers

Test #10:

score: 0
Accepted
time: 246ms
memory: 48972kb

input:

200
993
5 48 42 78
55 33 66 92
6 5 38 34
38 34 82 48
9 76 34 86
50 39 72 44
46 54 96 82
4 13 68 24
39 25 93 56
36 53 98 86
19 10 73 24
54 27 97 84
34 21 93 76
44 7 70 89
63 73 97 98
50 24 94 35
8 30 98 67
3 15 81 67
39 9 78 24
8 65 100 98
13 5 86 33
54 67 99 84
3 2 43 4
53 51 70 86
1 61 61 90
46 78 ...

output:

1
1
2
1
2
3
2
1
2
1
1
1
1
1
2
2
1
2
2
17
1
3
1
10
1
2
2
1
1
81
15
1
170
1
4
1
2
1
1
2
1
2
1
2
1
1
4
1
2
1
2
1
1
1
1
2
3511413
1
2
1
2
2
7022597
1
2
2
2
2
2
1
1
1
1
2
1
1
2
1
1
1
1
1
1
3
2
4
1
2
3
1
6
1
1
1
2
1
1
1
1
2
10
6
5
1
1
1
1
1
1
2
10
6
2
4
3
3511332
2
2
1
1
1
4
1
2
1
2
1
5
7
6
1
1
2
1
1
1
1
...

result:

ok 200 numbers

Test #11:

score: 0
Accepted
time: 681ms
memory: 50996kb

input:

20
9956
444627993 347200064 774678572 839098978
96936514 121569633 839637347 729127099
343857875 554213034 875416430 628610537
15566043 187047055 405963021 764745923
487340755 59747358 604299543 832826844
486772462 67273090 826002755 268527861
703758831 112254125 887710074 874858855
569284980 830139...

output:

723891885
824191538
424987081
659035365
778857924
125675099
919713447
291966121
841813
399938856
822967409
178787426
958377822
295302425
835192235
569958073
114037901
814150865
893384876
929070768

result:

ok 20 numbers

Test #12:

score: 0
Accepted
time: 1242ms
memory: 85144kb

input:

2
99774
247800693 19906287 955213467 53123614
752909581 205074868 772413424 686934334
565298662 150234672 941079197 750300220
29485217 794172007 678447605 874228231
524081254 14156413 775198532 256753797
121163010 271762780 489047491 996802646
61272893 135510320 459683721 975698463
37577668 16804082...

output:

272047384
165799897

result:

ok 2 number(s): "272047384 165799897"

Test #13:

score: 0
Accepted
time: 1267ms
memory: 85012kb

input:

2
99484
80367959 446700298 316938043 713030699
180389 97354205 991264982 207371172
227833166 343626198 994287807 999074121
223486533 274166047 762438540 996451527
139307586 443291005 936748272 801084030
368603416 246191750 992851831 575339592
136221208 723918872 407787921 838545617
455487191 6275486...

output:

802453384
719182239

result:

ok 2 number(s): "802453384 719182239"

Test #14:

score: 0
Accepted
time: 1260ms
memory: 84896kb

input:

2
99702
94595645 404782179 993272416 799556541
245960576 714158438 987938798 821638563
327691314 213461603 998000552 819971477
908733781 18331290 994253841 385477664
28676928 357826789 998470667 719588896
710572487 806027973 975068392 829637377
822675537 183304736 991051351 955945560
469997956 65270...

output:

652843490
385598972

result:

ok 2 number(s): "652843490 385598972"

Test #15:

score: 0
Accepted
time: 1286ms
memory: 83788kb

input:

2
99412
198128938 38044404 520528603 69633461
296156091 253862054 879892175 422416582
113833513 497466407 912643387 778378206
852447189 420378642 973727926 802939446
34007282 574929361 774903967 607765114
349114758 378613356 379719307 996737934
263835095 266671229 866002851 601998719
429266410 68169...

output:

399712945
504439560

result:

ok 2 number(s): "399712945 504439560"

Test #16:

score: 0
Accepted
time: 1004ms
memory: 75120kb

input:

2
99774
75930961 154072381 847971169 627055843
244525147 409278367 925944938 528328481
129723553 183994451 964033785 826775854
68114505 152036158 731700382 837809150
53123614 32632966 910136942 528684484
252909581 230872854 640150186 541470159
486420648 319619359 641792851 842591283
120182438 144662...

output:

201422441
375708952

result:

ok 2 number(s): "201422441 375708952"

Test #17:

score: 0
Accepted
time: 1024ms
memory: 74596kb

input:

2
99484
354512509 247852935 857376242 935585705
229195412 489307246 734432800 913935320
412027735 213030699 758437130 984647634
92940939 374006481 731384363 511640022
207371172 201030984 553877630 516667157
227833166 100756172 987896615 711405227
211506664 32713580 677678240 836139667
12482308 26243...

output:

206929702
212882508

result:

ok 2 number(s): "206929702 212882508"

Test #18:

score: 0
Accepted
time: 2031ms
memory: 151188kb

input:

2
99774
421095862 11979 995712432 500003783
74991422 13267 987221609 500005947
473667912 15491 579440162 500007494
272043704 19052 616675855 500007502
278107248 23574 823547269 500016619
99934893 24255 891019779 500027215
79491760 25101 858593398 500029356
389573792 28614 992644024 500031209
4814993...

output:

276881665
190505423

result:

ok 2 number(s): "276881665 190505423"

Test #19:

score: 0
Accepted
time: 2009ms
memory: 154492kb

input:

2
99484
269092999 2671 585644878 500008033
372100401 8563 649839023 500009251
11650408 13647 528532391 500010810
75879435 17429 948107876 500012680
387930366 29201 868851180 500016196
237571354 29479 835522858 500029354
449017445 36501 967334218 500029916
115558018 37338 572750917 500032757
28547691...

output:

966302926
659824663

result:

ok 2 number(s): "966302926 659824663"

Test #20:

score: 0
Accepted
time: 1368ms
memory: 86316kb

input:

2
100000
754616987 692578669 762385085 792789635
125404016 208944814 515858719 643886493
211266037 375488155 733820614 638134169
438299584 685393805 886369360 872046908
802228771 454379005 917034699 570584282
292374663 161921658 827473191 255585103
851878474 200274303 956604075 726081646
179044352 9...

output:

0
0

result:

ok 2 number(s): "0 0"

Test #21:

score: 0
Accepted
time: 685ms
memory: 52452kb

input:

20
9956
444627993 347200064 774678572 839098978
96936514 121569633 839637347 729127099
343857875 554213034 875416430 628610537
15566043 187047055 405963021 764745923
487340755 59747358 604299543 832826844
486772462 67273090 826002755 268527861
703758831 112254125 887710074 874858855
569284980 830139...

output:

723891885
858451192
338913450
0
374481170
0
372871015
758146456
943438772
972933858
103815851
223844636
0
221315585
0
927233491
87870972
0
974315240
0

result:

ok 20 numbers

Test #22:

score: 0
Accepted
time: 538ms
memory: 47392kb

input:

200
993
336152525 31049117 970839548 34483370
257968529 73378100 760295564 459870661
769587893 565770848 979251259 884779692
92706327 715631888 976631772 730467480
102936760 674056008 996888200 756831534
141490448 466112222 761954523 960644829
601216664 500053814 974949771 928192751
298296452 359164...

output:

163043779
931879100
340196911
603166447
571390080
941998134
535799686
806119803
0
0
968763447
0
505819026
301019994
445840311
913276365
0
0
0
0
373552780
469172930
895190508
788634597
448187144
0
59265419
601265027
881546313
822325486
0
0
948651482
529402096
510913350
0
0
330047724
19129674
51376051...

result:

ok 200 numbers

Test #23:

score: 0
Accepted
time: 446ms
memory: 48700kb

input:

2000
98
441828066 355550044 980140398 758338808
139187839 379489833 732496729 915149220
6198442 7406064 811667085 671521385
634108502 54340068 750182168 712125681
51518185 164417838 414217749 690302726
26971686 349814847 96913121 613904116
18885592 344395345 969337141 761958781
6500321 288362602 695...

output:

847505316
672057059
0
991749478
955014565
674711156
512643789
13536242
259157042
697460156
315324274
16820689
214291497
744247395
329778126
790070062
483967980
0
866914675
14414666
805420059
363232673
937992739
752762044
998000591
0
190653624
911419118
204932075
533889386
0
0
945352404
342908219
308...

result:

ok 2000 numbers

Test #24:

score: 0
Accepted
time: 180ms
memory: 47176kb

input:

100000
2
775086006 424901926 899447001 457273141
530656416 24127940 816730296 182824942
2
133448509 220692583 266404827 585541277
287907002 605654910 393289456 924736781
2
401696411 773194424 634303570 904175508
423057303 216493046 589873987 629571934
2
41138650 82403078 570504605 136479528
20017467...

output:

344597716
344561652
640677942
566457599
534894296
634815985
720802151
390192816
916770283
615422820
61143661
357457269
309084331
301952468
768959678
324515596
35801341
379330323
877366125
304583614
168573950
338498007
344179264
828689538
123780346
613736137
283614241
647439497
207739096
856885350
15...

result:

ok 100000 numbers