QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#721123#9606. PM 大师251Sec100 ✓7263ms178332kbC++143.0kb2024-11-07 15:19:482024-11-07 15:19:48

Judging History

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

  • [2024-11-07 15:19:48]
  • 评测
  • 测评结果:100
  • 用时:7263ms
  • 内存:178332kb
  • [2024-11-07 15:19:48]
  • 提交

answer

#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;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int n, q, a[1000005];
int c[1000005];
multiset<int> pos[1000005];
tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> s;
int O(int x) {
	int t = s.order_of_key(x);
	if (*(s.find_by_order(t)) == x) return t + 1;
	return t;
}
struct Seg {
	struct Dat {
		int u, w;
		Dat operator+(const Dat &b) const {
			if (w != b.w) return w < b.w ? *this : b;
			return u < b.u ? *this : b;
		}
	} f[4000005];
	int tg[4000005];
	void Pushtag(int p, int w) {
		f[p].w += w, tg[p] += w;
	}
	void Pushdown(int p) {
		if (tg[p]) {
			Pushtag(p << 1, tg[p]), Pushtag(p << 1 | 1, tg[p]);
			tg[p] = 0;
		}
	}
	void Build(int p, int l, int r) {
		f[p].w = inf, f[p].u = l;
		if (l == r) return;
		int mid = l + r >> 1;
		Build(p << 1, l, mid), Build(p << 1 | 1, mid + 1, r);
	}
	void Modify(int p, int l, int r, int L, int R, int w) {
		if (l >= L && r <= R) return Pushtag(p, w);
		if (l > R || r < L) return;
		int mid = l + r >> 1;
		Pushdown(p);
		Modify(p << 1, l, mid, L, R, w), Modify(p << 1 | 1, mid + 1, r, L, R, w);
		f[p] = f[p << 1] + f[p << 1 | 1];
	}
	void ModifyP(int p, int l, int r, int i, int w) {
		if (l == r) return void(f[p].w = w);
		int mid = l + r >> 1;
		Pushdown(p);
		if (i <= mid) ModifyP(p << 1, l, mid, i, w);
		else ModifyP(p << 1 | 1, mid + 1, r, i, w);
		f[p] = f[p << 1] + f[p << 1 | 1];
	}
} fS, gS;
void UpdF(int w) {
	if (s.find(w) != s.end()) {
		fS.ModifyP(1, 1, n, w, inf);
		return;
	}
	if (pos[w].size()) fS.ModifyP(1, 1, n, w, O(w) - c[*pos[w].begin()]);
	else fS.ModifyP(1, 1, n, w, -inf);
}
void UpdG(int w) {
	if (s.find(w) == s.end()) {
		gS.ModifyP(1, 1, n, w, inf);
		return;
	}
	if (pos[w].size()) gS.ModifyP(1, 1, n, w, c[*pos[w].begin()] - O(w));
	else gS.ModifyP(1, 1, n, w, inf);
}
void Upd() {
	while (true) {
		if (fS.f[1].w < 0) {
			int i = fS.f[1].u;
			s.insert(i);
			UpdF(i), UpdG(i);
			fS.Modify(1, 1, n, i + 1, n, 1);
			gS.Modify(1, 1, n, i + 1, n, -1);
			continue;
		}
		if (gS.f[1].w < 0) {
			int i = gS.f[1].u;
			s.erase(i);
			UpdF(i), UpdG(i);
			fS.Modify(1, 1, n, i + 1, n, -1);
			gS.Modify(1, 1, n, i + 1, n, 1);
			continue;
		}
		break;
	}
}
void Ins(int p, int w) {
	if (w == -1) return;
	pos[w].insert(p);
	UpdF(w), UpdG(w);
}
void Del(int p, int w) {
	if (w == -1) return;
	pos[w].erase(pos[w].find(p));
	UpdF(w), UpdG(w);
}
int main() {
	scanf("%d%d", &n, &q);
	fS.Build(1, 1, n), gS.Build(1, 1, n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		if (!a[i]) c[i] = 1;
	}
	for (int i = 1; i <= n; i++) c[i] += c[i - 1];
	for (int i = 1; i <= n; i++) s.insert(i);
	while (q--) {
		int x, k, y; scanf("%d%d%d", &x, &k, &y);
		Del(x, a[x]), Ins(x, a[x] = k), Upd();
		if (a[y]) printf("%d\n", a[y]);
		else printf("%d\n", *(s.find_by_order(c[y] - 1)));
	}
	return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 3ms
memory: 57168kb

input:

10 10
0 -1 0 0 -1 0 -1 -1 0 -1
7 5 9
7 5 1
10 8 4
7 10 1
8 -1 3
10 6 4
2 2 1
2 9 6
5 8 4
7 -1 9

output:

6
1
3
1
2
3
1
4
3
5

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 32ms
memory: 60300kb

input:

10000 10000
-1 0 -1 -1 -1 0 -1 0 -1 0 -1 0 0 -1 -1 0 0 -1 0 -1 -1 -1 0 0 -1 -1 0 -1 -1 -1 0 0 0 -1 0 -1 -1 -1 -1 0 -1 -1 0 -1 -1 0 -1 -1 0 0 -1 0 0 0 -1 -1 -1 -1 0 0 0 0 -1 0 -1 -1 0 -1 -1 -1 0 0 -1 0 0 -1 -1 0 0 -1 -1 -1 -1 0 0 0 -1 0 -1 0 0 0 0 -1 0 0 -1 -1 0 -1 -1 -1 0 -1 0 -1 0 0 -1 -1 0 -1 -1 0...

output:

37
1767
2083
1505
2208
3174
1012
3136
4044
2661
802
4772
931
2188
605
732
1473
1221
4070
706
3786
464
300
2857
4852
3026
2965
2102
4096
4859
1841
60
2465
645
4312
2002
4168
3292
2854
2043
194
4748
3298
1687
916
4465
1101
4649
4552
598
3717
3883
2111
1911
2502
2265
2737
2193
4200
3607
4086
3908
2529
...

result:

ok 10000 lines

Test #3:

score: 10
Accepted
time: 27ms
memory: 60072kb

input:

10000 10000
0 0 -1 0 0 -1 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 ...

output:

6984
1876
1755
3945
3988
8817
1301
9211
6838
70
2044
5300
4026
6870
1879
7611
2604
5187
8292
1796
5087
2635
2369
8040
5721
6993
5554
966
5743
4301
8644
4755
2400
4647
6158
6998
2597
7698
8252
6522
8528
8153
3332
2833
4289
3081
9022
6921
6121
1549
2801
958
9507
2148
7998
4954
8624
7643
22
4162
5666
8...

result:

ok 10000 lines

Test #4:

score: 10
Accepted
time: 40ms
memory: 58156kb

input:

10000 10000
0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 ...

output:

549
7364
7058
4716
4807
6918
163
2855
4219
8220
1848
2315
1228
6516
1570
7755
728
911
2810
2028
3977
6371
8418
788
2040
7159
7360
3776
8573
8326
3057
3814
3587
4894
2018
5314
812
5691
5689
7967
4493
7806
1966
5618
6862
3303
1947
6878
7511
6879
5418
5836
8916
5951
4960
1424
1290
4315
873
3208
1774
73...

result:

ok 10000 lines

Test #5:

score: 10
Accepted
time: 33ms
memory: 60104kb

input:

10000 10000
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 -1 -1 -1 -1 0 0 0 0 0 -1 -1 0 0 0 -1 0 0 0 0 -1 0 0 -1 0 0 0 -1 -1 0 -1 -1 0 -1 -1 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 -1 0 -1 0 0 -1 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 -1 0 0 0 ...

output:

3638
2094
6615
88
2643
3081
3993
7204
6569
1008
7035
4008
6846
2407
2888
6884
5588
340
3145
3234
3779
2608
6289
1428
2477
3411
161
2203
2128
5677
1759
2106
6596
313
7461
5011
1208
3021
7029
3452
4582
6173
479
4360
224
3681
5249
2351
569
1369
5212
5572
3429
7152
6636
6318
6928
6644
6678
5661
4229
185...

result:

ok 10000 lines

Test #6:

score: 10
Accepted
time: 29ms
memory: 58140kb

input:

10000 10000
-1 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 0 -1 -1 -1 0 -1 0 -1 -1 -1 -1 -1 -1 0 -1 -1 0 -1 -1 0 -1 0 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 0 -1 -1 -1 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 ...

output:

2420
325
2194
1102
1154
1391
12
1517
1948
1801
593
441
975
1902
1078
184
226
587
52
2361
1584
2137
2255
190
1904
193
636
62
1915
1028
1751
612
330
659
1700
1672
1073
756
202
425
766
522
1844
2295
744
37
865
2367
32
1066
948
1026
1162
812
625
1512
161
1394
2372
429
1232
1155
1295
998
1941
1632
1151
1...

result:

ok 10000 lines

Test #7:

score: 10
Accepted
time: 28ms
memory: 60244kb

input:

10000 10000
-1 0 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 0 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0...

output:

219
484
774
725
570
54
54
931
240
552
787
897
322
15
756
440
675
152
337
275
408
856
622
562
494
3
890
858
849
460
141
187
119
271
441
426
550
804
308
823
398
918
244
522
213
785
84
429
428
500
619
179
808
173
853
1011
955
46
375
520
704
416
955
800
661
899
953
533
319
87
1011
172
254
810
842
879
59...

result:

ok 10000 lines

Test #8:

score: 10
Accepted
time: 26ms
memory: 60048kb

input:

10000 10000
-1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

236
370
232
128
262
311
250
336
164
107
97
183
354
3
346
307
282
350
99
214
350
489
170
373
130
81
221
200
184
275
451
67
60
70
41
472
153
479
288
228
212
332
68
76
338
114
242
116
207
22
234
204
451
213
258
159
34
193
259
122
448
105
131
177
474
490
439
405
170
322
380
360
425
33
414
302
191
161
33...

result:

ok 10000 lines

Subtask #2:

score: 10
Accepted

Test #9:

score: 10
Accepted
time: 5707ms
memory: 163968kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

459886
53317
492356
423943
292374
39197
57078
411846
146532
49283
12402
316482
109785
61994
283770
156543
483178
281298
130833
46233
335000
428931
210801
24959
71722
361514
117444
218823
54814
378720
81973
194272
135873
484070
293734
303811
349950
344506
479375
229463
8421
114254
237253
295732
15835...

result:

ok 1000000 lines

Test #10:

score: 10
Accepted
time: 7263ms
memory: 160560kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

231864
158988
610606
558023
74606
42402
245012
525664
260911
510218
257983
146399
83879
681860
375125
59670
894882
210723
509929
9256
413137
839173
549143
526070
729809
423388
596082
184674
660967
119639
742727
901832
938252
900078
190461
920677
441621
942117
188500
185870
522884
40015
9817
716146
7...

result:

ok 1000000 lines

Test #11:

score: 10
Accepted
time: 7087ms
memory: 160612kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

36874
472618
842917
114716
491408
773508
452063
603860
728342
748513
475705
258696
486435
316427
736929
378854
238269
110066
1161
156017
484791
539880
789570
421405
27960
173470
21339
774513
531030
728993
156647
533307
212440
258827
731424
220524
712655
444910
546596
745273
497179
341745
676112
5092...

result:

ok 1000000 lines

Test #12:

score: 10
Accepted
time: 6359ms
memory: 160352kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

668119
431443
15455
296704
240224
645285
127520
95201
89016
184805
731059
712630
396434
292253
553741
212645
355171
214190
127817
191153
701410
89507
340566
287015
187296
35719
746439
375147
88190
102370
390425
435125
502654
399775
608758
98602
171926
271902
511567
384122
726564
28359
4230
471734
12...

result:

ok 1000000 lines

Test #13:

score: 10
Accepted
time: 5184ms
memory: 166240kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

122105
239109
25040
14694
216977
99003
181576
195235
117059
231141
152732
140117
42783
77977
226878
131724
129445
6315
84475
200684
240468
74983
112696
224812
7559
33824
18998
187
133123
151253
107837
158008
132668
13180
180187
124564
177382
102508
128808
131293
88975
157536
238149
98474
128162
9293...

result:

ok 1000000 lines

Test #14:

score: 10
Accepted
time: 4885ms
memory: 167260kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

47044
6150
94661
59151
4729
2518
23567
71693
42072
50518
22840
39707
35445
82412
27250
50855
39799
64638
21397
39142
82263
66705
54956
24413
54915
20050
12379
30158
7056
56960
48528
81919
34586
47114
79033
79833
35677
74173
90352
31325
75842
4392
42035
27995
87130
20590
19983
78934
8490
46331
18425
...

result:

ok 1000000 lines

Test #15:

score: 10
Accepted
time: 4980ms
memory: 170268kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

41828
48247
26228
2049
8832
16507
32126
45098
16614
23119
34270
34422
36737
30148
40987
19693
38932
49063
35507
26936
34825
4751
48640
8128
29266
16813
36942
31358
20695
21688
15879
16628
42878
6807
40994
38198
1395
11655
10644
35127
2309
23706
2631
15256
28080
47633
38700
24115
9522
27033
46263
538...

result:

ok 1000000 lines

Subtask #3:

score: 10
Accepted

Test #16:

score: 10
Accepted
time: 2500ms
memory: 166352kb

input:

1000000 1000000
0 -1 -1 0 -1 -1 0 -1 0 -1 0 0 0 0 -1 -1 -1 0 -1 0 -1 0 -1 -1 0 -1 -1 -1 0 -1 -1 -1 0 -1 0 0 0 -1 -1 -1 -1 0 -1 -1 0 0 -1 -1 0 -1 -1 -1 0 -1 0 -1 0 0 -1 0 -1 -1 -1 -1 -1 -1 -1 0 -1 0 0 -1 0 0 0 0 0 0 0 0 0 -1 0 -1 0 0 0 -1 -1 -1 0 0 0 -1 0 0 0 -1 -1 0 0 0 0 -1 -1 0 0 0 0 -1 0 -1 0 0 0...

output:

419426
372348
476911
34348
150780
460622
223328
283198
443164
347044
103688
492126
361590
20471
24004
315761
428482
18708
420730
182298
498955
177266
56353
462764
158257
244933
422040
484780
403241
187513
20639
466402
267820
384702
293959
84073
125864
363325
86066
479275
368199
195169
20943
82210
29...

result:

ok 1000000 lines

Test #17:

score: 10
Accepted
time: 2598ms
memory: 148308kb

input:

1000000 1000000
0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

877817
169670
503865
868941
757832
762592
267527
132121
530021
515297
594043
369906
279274
769900
279993
925891
867298
65017
327392
534338
454981
371962
773139
594668
861490
297472
691830
240392
6931
837802
329267
717727
622016
302076
867101
808473
234174
156539
246761
217031
706530
892460
804744
36...

result:

ok 1000000 lines

Test #18:

score: 10
Accepted
time: 2632ms
memory: 150792kb

input:

1000000 1000000
0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 -1 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -...

output:

76964
254688
647867
132442
555987
772576
148660
189913
890249
469690
650795
527444
823200
239204
536286
369356
374355
316809
102958
181712
133162
278773
624648
23406
191762
690329
48553
204392
70394
472228
352467
863376
689494
255188
762658
128967
848134
101255
825979
353786
758958
597186
80265
8005...

result:

ok 1000000 lines

Test #19:

score: 10
Accepted
time: 2645ms
memory: 157472kb

input:

1000000 1000000
0 0 -1 0 0 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 0 -1 0 0 0 0 0 0 0 0 -1 0 -1 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 -1 0 -1 -1 0 0 0 0 -1 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 -1 -1 -1 ...

output:

301362
124661
594574
157761
452519
202544
349211
125801
300630
652855
79737
245694
343621
402370
220223
476997
106123
58847
28413
436012
281469
582215
577107
244922
278352
280065
748256
673531
10514
243821
418778
355056
186471
292616
428202
270231
545683
441274
487468
96171
653364
293158
395100
6348...

result:

ok 1000000 lines

Test #20:

score: 10
Accepted
time: 2283ms
memory: 171908kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 0 -1 0 -1 0 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 0 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 0 -1 -1 -1 -1 -1 0 0 0 0 -1 0 -1 -1 -1 0 0 0 0 -1 -1 0 0 0 -1 -1 -1 -1 -1 -1 ...

output:

17462
58557
246658
26828
228805
46664
5019
174233
104683
211580
60036
225402
181205
52446
98450
212982
193185
179563
194752
23834
194419
83859
193437
130118
156179
245458
17678
50207
160851
30676
225732
67445
220034
72349
22635
6223
123948
109346
105038
193636
113546
110188
66568
124787
140476
40757...

result:

ok 1000000 lines

Test #21:

score: 10
Accepted
time: 2115ms
memory: 174300kb

input:

1000000 1000000
0 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 -1 0 -1 -1 0 -1 0 -1 0 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -...

output:

39803
29623
63234
76116
87461
45159
12590
58765
7365
60656
1333
827
21466
7412
20037
21268
71878
14866
48131
59337
29187
66884
2578
94083
10058
23669
70154
29562
64147
74928
9714
61444
43695
25505
44102
89065
53943
61516
9907
29901
92226
17249
21627
45499
75849
54272
22009
10210
41368
99653
17547
43...

result:

ok 1000000 lines

Test #22:

score: 10
Accepted
time: 1993ms
memory: 177120kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

41794
11248
19370
9521
15603
231
33587
39333
33779
21719
13484
35524
29843
20241
10670
33496
23214
33568
43776
30681
495
8566
17874
35327
13257
40753
26163
17324
12968
7409
24322
17057
13897
48782
29846
19715
49649
38079
16190
42374
43535
7308
22123
7177
8266
28008
40105
12128
14380
45158
48919
3273...

result:

ok 1000000 lines

Subtask #4:

score: 10
Accepted

Test #23:

score: 10
Accepted
time: 4474ms
memory: 168044kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

99
15
51
89
58
47
81
4
40
58
14
26
26
2
62
3
28
51
13
23
91
62
25
6
56
7
25
56
87
8
66
40
56
50
75
68
70
51
54
64
79
22
59
53
45
5
13
34
44
67
18
48
7
13
63
84
50
45
48
42
47
47
4
89
35
22
59
55
5
69
14
61
84
91
51
55
92
28
31
68
17
58
50
81
61
58
54
91
34
12
26
80
50
21
6
7
43
11
73
70
1
49
35
42
1...

result:

ok 1000000 lines

Test #24:

score: 10
Accepted
time: 4418ms
memory: 168104kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

80
76
92
88
88
24
88
70
71
23
40
93
52
46
63
41
50
44
60
37
40
29
32
38
17
29
86
53
37
9
39
50
39
57
95
2
66
5
34
81
47
53
19
82
61
2
9
86
57
85
66
73
71
84
3
60
34
75
80
56
58
87
68
94
2
68
14
80
52
97
16
41
97
64
35
84
83
26
46
24
88
26
30
92
56
38
88
95
5
18
100
19
42
8
56
24
44
69
99
16
50
71
10...

result:

ok 1000000 lines

Test #25:

score: 10
Accepted
time: 4422ms
memory: 167660kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

31
56
68
1
88
75
26
48
60
62
24
63
5
51
24
29
30
72
15
73
50
87
82
11
55
56
84
37
57
87
22
75
93
86
58
28
25
21
90
97
66
11
49
65
8
37
100
93
77
90
47
5
21
18
20
100
42
28
88
99
34
34
66
96
9
50
56
13
76
95
31
70
16
90
95
25
44
97
77
100
48
7
23
88
76
48
43
22
92
71
49
6
81
51
16
5
29
32
44
93
42
24...

result:

ok 1000000 lines

Subtask #5:

score: 30
Accepted

Test #26:

score: 30
Accepted
time: 2397ms
memory: 167520kb

input:

1000000 499990
-1 0 -1 0 0 0 -1 0 0 0 -1 0 0 0 -1 -1 0 0 0 -1 0 -1 -1 0 0 0 0 -1 -1 0 -1 -1 -1 0 -1 0 -1 0 -1 0 0 0 0 -1 0 -1 0 0 0 0 0 -1 0 -1 -1 -1 0 -1 -1 0 0 0 0 -1 -1 -1 0 0 0 -1 -1 0 0 -1 0 -1 -1 0 -1 -1 -1 0 0 0 -1 0 0 0 0 -1 0 0 -1 -1 0 -1 0 0 -1 -1 0 0 -1 0 0 0 -1 -1 -1 -1 0 -1 0 -1 -1 -1 0...

output:

122348
449823
381435
492392
497609
306719
456448
468935
453769
131422
210398
134485
239919
286756
212338
48890
92958
296248
50112
369374
68132
168648
21288
329297
217369
338217
432768
374186
173797
122895
10249
126058
161754
64109
25040
96703
73480
214083
473367
351678
289989
105133
455653
50593
250...

result:

ok 499990 lines

Test #27:

score: 30
Accepted
time: 646ms
memory: 163456kb

input:

1000000 50011
0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

919658
553478
16799
88273
466906
665678
236667
710244
510205
781710
608312
529251
737092
417257
927478
593624
333374
644792
785167
654830
496068
6284
779632
691219
845727
579257
93857
322734
890777
87819
622388
703546
141171
454693
614782
197928
207053
782698
255989
567493
867801
877293
457839
42933...

result:

ok 50011 lines

Test #28:

score: 30
Accepted
time: 847ms
memory: 162440kb

input:

1000000 99995
-1 0 0 0 0 0 0 -1 -1 0 0 -1 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0...

output:

49938
656925
571376
117084
108873
663835
572728
543876
588005
268851
640693
536005
302323
637062
897431
630313
312309
341789
334452
270739
157256
370168
210749
573115
718797
40014
218190
135533
592508
298312
484706
641584
759115
505429
755941
40675
801311
390311
767089
44866
425173
208074
512311
593...

result:

ok 99995 lines

Test #29:

score: 30
Accepted
time: 1467ms
memory: 161652kb

input:

1000000 250014
0 0 0 0 -1 0 0 0 0 0 -1 -1 0 -1 -1 0 0 -1 0 0 0 0 0 0 -1 0 0 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 0 0 -1 0 0 0 -1 0 -1 0 0 0 0 0 -1 0 0 0 -1 0 -1 0 0 0 -1 0 0 0 0 -1 0 0 0 0 0 0 -1 -1 -1 0 0 -1 -1 0 0 0 0 0 0 0 0 0 -1 -1 -1 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 ...

output:

40921
70204
315652
460903
134497
226220
501630
19812
381118
621565
7816
743667
199250
553666
45639
158188
511016
63407
102591
351313
399128
482671
215377
630162
92337
733909
723960
246131
679411
584092
157720
705366
527645
261651
331754
62695
61372
232834
34421
624368
509594
73319
125211
463806
2883...

result:

ok 250014 lines

Test #30:

score: 30
Accepted
time: 3196ms
memory: 172452kb

input:

1000000 749994
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 0 -1 0 -1 -1 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 0 -1 0 -1 0 -1 -1 -1 -1 0 -1 -1 -1 0 0 -1 -1 -1 -1 0 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 0 -1 0 -1 0 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 0 -1 -1 0 -1...

output:

37202
190371
245478
62728
240658
239387
229062
249667
26805
148232
170665
110568
101986
185216
170044
174559
193288
103231
225060
37266
9689
8370
53146
244334
199871
239193
15559
150656
213671
234719
110081
66381
147638
111855
17238
62234
246442
1464
72459
146403
4114
208068
22027
213126
17509
69503...

result:

ok 749994 lines

Test #31:

score: 30
Accepted
time: 3542ms
memory: 178332kb

input:

1000000 900008
-1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 0 -1 -1 0 0 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

82776
93285
80511
8834
94224
40408
80193
72272
40314
85291
97626
26414
1234
8449
42393
9918
57434
72138
9062
41307
4444
22216
10885
90238
52708
23209
94641
72376
42168
52947
6083
42366
32978
35270
89535
10005
4409
69687
98726
44374
69542
90082
41662
39137
83058
87287
62048
70126
90490
5569
35674
485...

result:

ok 900008 lines

Test #32:

score: 30
Accepted
time: 3622ms
memory: 175048kb

input:

1000000 950009
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 0 -1 -...

output:

49119
45050
22519
42138
21136
15539
43254
9649
10668
48846
29989
21975
11925
27548
19751
21187
106
9735
23197
10368
22010
47017
16418
24302
21435
14814
48039
19956
33930
17390
33631
40089
29482
49137
47134
19475
34804
39183
12927
17158
101
46801
22929
6943
147
22762
17712
34910
35548
21885
1373
1580...

result:

ok 950009 lines

Subtask #6:

score: 30
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Test #33:

score: 30
Accepted
time: 5741ms
memory: 165436kb

input:

1000000 1000000
0 -1 0 -1 0 0 0 0 0 0 0 -1 0 -1 0 0 -1 0 0 -1 -1 -1 -1 0 0 0 0 -1 -1 0 -1 -1 0 -1 -1 -1 0 -1 0 -1 0 -1 -1 0 -1 -1 0 0 -1 0 0 -1 0 -1 0 0 -1 0 -1 -1 0 0 0 -1 -1 0 0 0 -1 0 -1 -1 0 -1 -1 0 -1 -1 0 0 -1 -1 0 -1 0 0 -1 0 -1 -1 -1 0 0 0 0 0 0 0 -1 -1 -1 -1 0 -1 -1 0 -1 -1 -1 0 0 -1 -1 0 -...

output:

450902
69745
285045
445004
480123
87974
425032
79170
466584
244575
384683
96546
345527
119477
241699
485351
442606
433735
425086
349308
297607
240268
245027
467738
320842
314638
72274
187792
418672
57169
458288
470111
407464
333692
1883
413662
184306
345235
271129
5570
494656
333849
49892
472498
171...

result:

ok 1000000 lines

Test #34:

score: 30
Accepted
time: 7108ms
memory: 159516kb

input:

1000000 1000000
0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 -1 0 0 0 0 -...

output:

915762
547780
61902
656715
203431
397277
804523
726954
837625
231200
786213
1118
903651
837123
121684
294440
565738
506893
91697
308958
263005
767084
870353
185823
610644
695643
833692
14713
133910
484357
635220
798027
55216
375619
781084
314537
618894
59080
326343
679643
187583
596145
294621
402801...

result:

ok 1000000 lines

Test #35:

score: 30
Accepted
time: 6890ms
memory: 160952kb

input:

1000000 1000000
0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 -1 0 0 -1 0...

output:

29284
504085
357259
131123
407333
124587
185784
777486
211199
540243
834244
654871
807766
239429
267256
804990
171968
210795
528337
65618
513825
686591
523629
423109
102538
873534
442105
499324
334556
469974
345801
244937
820399
275924
602163
657252
705097
154408
367642
339931
719584
588636
558994
4...

result:

ok 1000000 lines

Test #36:

score: 30
Accepted
time: 6299ms
memory: 161964kb

input:

1000000 1000000
-1 -1 -1 0 -1 0 0 0 -1 0 0 -1 -1 -1 0 -1 0 0 -1 0 0 0 0 0 0 0 0 0 -1 0 0 -1 0 0 -1 0 0 0 0 0 -1 0 -1 -1 0 0 0 0 0 -1 0 0 -1 -1 0 0 0 -1 0 0 -1 0 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 -1 0 -1 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 -1 0 0 0 0 -1 -1...

output:

121016
181930
424070
245900
257125
407826
468434
645922
634802
480718
282245
716521
264718
610481
669737
670081
728026
4586
414821
746274
328865
726795
230254
441436
577253
690000
155078
364792
396711
24120
700867
366621
653077
32986
612266
253108
585985
316136
98012
382164
162870
598322
533662
1853...

result:

ok 1000000 lines

Test #37:

score: 30
Accepted
time: 5315ms
memory: 167104kb

input:

1000000 1000000
-1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 0 -1 -1 0 -1 -1 0 -1 -1 0 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 0 0...

output:

166196
146485
67924
201572
23240
207035
239797
108092
60892
241972
135190
207800
153013
129202
147873
92605
69592
238084
41348
126611
193843
184904
213643
107447
96633
76737
147221
150173
152235
107730
175226
142921
185280
29385
157907
201359
242101
135881
193654
238305
39817
1288
177086
39520
13758...

result:

ok 1000000 lines

Test #38:

score: 30
Accepted
time: 5058ms
memory: 167692kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 0 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 ...

output:

44846
37517
34047
36880
97749
71416
38051
86374
22274
25253
46174
50071
9397
60070
23691
45459
90089
74854
49276
99905
64940
47547
25440
45135
31514
46043
80501
27347
78889
30102
66159
60326
72383
8681
32961
30229
3094
13693
19581
15685
24809
3327
18602
1692
33414
37723
55845
41164
67449
25514
69521...

result:

ok 1000000 lines

Test #39:

score: 30
Accepted
time: 4873ms
memory: 169680kb

input:

1000000 1000000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...

output:

41059
3763
16555
4760
18507
8193
45556
42071
17666
26084
22602
39013
13568
45172
47670
6061
43733
6961
6137
6966
12749
44924
45888
10711
49160
46979
27250
28200
8496
21024
46892
36901
46533
17479
31292
36187
45410
14257
8537
5835
730
48749
10111
28850
4746
20585
48377
5811
19389
46439
33662
35898
32...

result:

ok 1000000 lines