QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#23823#190. New Homefeecle6418100 ✓2380ms164816kbC++143.0kb2022-03-19 16:29:312022-04-30 04:17:15

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 04:17:15]
  • 评测
  • 测评结果:100
  • 用时:2380ms
  • 内存:164816kb
  • [2022-03-19 16:29:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e8;
int n,m,q,b[900005],ans[300005],mn[1200005],T;
struct Shop{int x,t,fr,to;}a1[300005];
struct Query{int x,t;}a2[300005];
struct Thing{int tp,id;};
vector<Thing> op[900005];
multiset<int> s[300005],lst[300005];
void Build(int p,int l,int r){
	if(l==r){
		if(l==b[0]+1){
			for(int i=1;i<=m;i++)lst[l].insert(0);
			mn[p]=0;
		}
		else mn[p]=l-1;
		return ;
	}
	int mid=(l+r)/2;
	Build(p*2,l,mid),Build(p*2+1,mid+1,r);
	mn[p]=min(mn[p*2],mn[p*2+1]);
}
void Addlst(int p,int l,int r,int x,int y,int dlt){
	if(l==r){
		if(dlt==1)lst[x].insert(y);
		else lst[x].erase(lst[x].find(y));
		if(lst[x].size())mn[p]=*lst[x].begin();
		else mn[p]=l-1;
		return ;
	}
	int mid=(l+r)/2;
	if(x<=mid)Addlst(p*2,l,mid,x,y,dlt);
	else Addlst(p*2+1,mid+1,r,x,y,dlt);
	mn[p]=min(mn[p*2],mn[p*2+1]);
}
int id(int x,bool right=0){
	if(!right)return lower_bound(b+1,b+b[0]+1,x)-b;
	return upper_bound(b+1,b+b[0]+1,x)-b-1;
}
void Ins(int tp,int x){
	if(s[tp].find(x)!=s[tp].end())return s[tp].insert(x),void();
	auto it=s[tp].lower_bound(x);
	int L;
	Addlst(1,1,b[0]+1,x,L=*--it,1);
	++it;
	Addlst(1,1,b[0]+1,*it,L,-1);
	Addlst(1,1,b[0]+1,*it,x,1);
	s[tp].insert(x);
}
void Erase(int tp,int x){
	s[tp].erase(s[tp].find(x));
	if(s[tp].find(x)!=s[tp].end())return ;
	auto it=s[tp].lower_bound(x);
	int L;
	Addlst(1,1,b[0]+1,x,L=*--it,-1);
	++it;
	Addlst(1,1,b[0]+1,*it,x,-1);
	Addlst(1,1,b[0]+1,*it,L,1);
}
int Find(int p,int l,int r,int fr,int curmn){
	if(l==r){
		if(l==b[0]+1)return assert(0),fr-b[mn[p]];
		return max(b[l]-fr,fr-b[curmn]);
	}
	int mid=(l+r)/2;
	int u=min(curmn,mn[p*2+1]);
	if(u)u=b[u];
	else u=-1e9;
	int rr=b[mid+1]-1;
	if(mid+1==b[0]+1)rr=2*N+1;
	if(rr<fr||(rr>=fr&&u<2*fr-rr)){
		return Find(p*2+1,mid+1,r,fr,curmn);
	}
	return Find(p*2,l,mid,fr,min(curmn,mn[p*2+1]));
}
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d%d",&a1[i].x,&a1[i].t,&a1[i].fr,&a1[i].to);
		b[++b[0]]=a1[i].fr,b[++b[0]]=a1[i].to;
	}
	for(int i=1;i<=q;i++){
		scanf("%d%d",&a2[i].x,&a2[i].t);
		b[++b[0]]=a2[i].t;
	}
	sort(b+1,b+b[0]+1);
	b[0]=unique(b+1,b+b[0]+1)-b-1;
	for(int i=1;i<=n;i++){
		a1[i].fr=id(a1[i].fr),a1[i].to=id(a1[i].to);
		op[a1[i].fr].push_back({1,i}),op[a1[i].to+1].push_back({-1,i});
	}
	for(int i=1;i<=q;i++){
		a2[i].t=id(a2[i].t),op[a2[i].t].push_back({0,i});
	}
	T=b[0];
	b[0]=0;
	for(int i=1;i<=n;i++)b[++b[0]]=a1[i].x;
	sort(b+1,b+b[0]+1);
	b[0]=unique(b+1,b+b[0]+1)-b-1;
	for(int i=1;i<=n;i++)a1[i].x=id(a1[i].x);
	for(int i=1;i<=m;i++)s[i].insert(0),s[i].insert(b[0]+1);
	Build(1,1,b[0]+1);
	for(int i=1;i<=T;i++){
		for(Thing j:op[i]){
			if(j.tp==1)Ins(a1[j.id].t,a1[j.id].x);
			if(j.tp==-1)Erase(a1[j.id].t,a1[j.id].x);
		}
		for(Thing j:op[i]){
			if(j.tp==0){
				int x=a2[j.id].x;
				if(0!=*lst[b[0]+1].begin())ans[j.id]=Find(1,1,b[0]+1,x,N);
				else ans[j.id]=-1;
			}
		}
	}
	for(int i=1;i<=q;i++)printf("%d\n",ans[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 9ms
memory: 53240kb

input:

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

output:

4
2
-1
-1

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 8ms
memory: 53572kb

input:

2 1 3
1 1 1 4
1 1 2 6
1 3
1 5
1 7

output:

0
0
-1

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 9ms
memory: 54444kb

input:

1 1 1
100000000 1 1 1
1 1

output:

99999999

result:

ok single line: '99999999'

Test #4:

score: 0
Accepted
time: 8ms
memory: 54632kb

input:

20 10 20
1 6 1 1
1 9 1 1
1 3 1 1
1 5 1 1
1 2 1 1
1 7 1 1
1 7 1 1
1 8 1 1
1 3 1 1
1 8 1 1
1 5 1 1
1 2 1 1
1 10 1 1
1 7 1 1
1 7 1 1
1 10 1 1
1 1 1 1
1 4 1 1
1 6 1 1
1 8 1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
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:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 20 lines

Test #5:

score: 0
Accepted
time: 4ms
memory: 54104kb

input:

20 10 1
45 4 53 54
75 8 56 60
65 3 87 100
56 7 93 97
36 3 64 91
63 4 93 94
71 2 45 97
67 5 57 65
34 6 7 52
96 9 43 95
83 5 63 92
24 3 55 99
7 10 38 52
59 10 59 100
43 5 5 21
38 9 72 82
72 2 1 64
22 7 50 81
74 5 88 89
84 1 25 29
41 48

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 11ms
memory: 53832kb

input:

1 10 20
58 4 59 59
36 88
80 47
56 65
74 45
99 4
17 2
13 46
92 38
82 2
42 47
40 40
30 9
13 41
14 77
61 33
20 73
89 3
89 100
83 100
28 59

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

result:

ok 20 lines

Test #7:

score: 0
Accepted
time: 12ms
memory: 54664kb

input:

20 4 20
61418457 4 33932551 98975124
50805588 3 56616927 66076460
44262243 1 58029464 59272268
34981593 4 10760710 89302332
58741675 3 60670049 77700264
33623668 3 63722438 67824726
62526450 2 43078579 75611393
4274055 2 14095759 73162733
87374777 4 83277088 91743411
94571186 3 89842706 99458411
124...

output:

10979904
42075856
54788268
-1
-1
42932550
-1
24180475
27529716
-1
-1
24630956
16686222
-1
35018819
52156445
41144455
35084106
64627631
26558377

result:

ok 20 lines

Test #8:

score: 0
Accepted
time: 7ms
memory: 53308kb

input:

400 6 400
13 6 1 2
6 2 1 5
1 6 10 11
14 6 9 12
3 1 10 15
10 1 10 13
12 4 7 15
3 5 7 7
11 2 15 15
9 4 2 10
9 2 2 2
3 2 11 13
2 5 4 4
15 1 6 14
9 6 13 15
2 3 14 15
10 3 9 11
3 2 12 13
6 5 13 14
13 5 13 15
5 6 1 4
8 4 6 15
7 2 6 12
7 2 11 12
2 6 9 15
13 1 6 11
4 1 8 13
12 2 2 10
6 2 4 6
3 1 11 11
10 6 ...

output:

0
1
1
1
1
0
1
1
1
1
2
0
0
1
4
1
1
0
3
1
0
0
1
1
11
0
1
5
2
0
0
8
2
2
4
1
1
1
0
1
2
0
2
1
1
1
1
1
0
1
0
1
6
1
4
0
0
1
0
0
1
1
1
4
0
2
5
2
1
1
0
1
1
3
1
1
0
0
1
9
2
1
1
1
1
2
2
1
1
1
1
1
1
8
1
1
1
1
1
3
1
1
1
1
0
3
2
0
7
3
1
2
1
0
1
3
0
1
2
2
0
0
1
0
1
1
1
3
2
3
3
1
2
1
1
1
1
2
1
2
1
1
5
0
1
5
3
2
1
1...

result:

ok 400 lines

Test #9:

score: 0
Accepted
time: 4ms
memory: 54016kb

input:

400 10 400
43340857 4 45698748 89832178
54619105 4 12139243 31375025
37861883 8 47732866 65672593
28228848 2 34377649 37188437
24894809 5 21779229 60269842
5631877 9 56806239 99891497
58348534 9 55212163 99535913
96241892 8 13013131 71454036
96553400 5 68855786 90287612
49896594 7 75131914 88890304
...

output:

61438693
10092902
17042653
-1
14307562
44443029
-1
12918912
18058222
21930309
8237607
16854750
21730597
12859269
16464543
5185522
11308124
17123350
33463533
39018069
7610293
25072752
-1
25395408
38817024
-1
-1
20033481
43512384
25208569
17827332
23318396
16702567
10179947
30415219
15582621
10432423
...

result:

ok 400 lines

Test #10:

score: 0
Accepted
time: 7ms
memory: 54564kb

input:

400 400 400
50895816 112 11074810 50852590
91036952 324 226350 42542861
93200007 152 88561471 97853611
58986775 6 42946440 47476776
29191962 123 42448629 81705957
85607864 215 29065353 76256459
63414892 222 13827288 67943972
74982535 186 36761229 88857832
62363052 134 7564006 70661082
17925970 164 9...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 400 lines

Test #11:

score: 0
Accepted
time: 12ms
memory: 53200kb

input:

400 133 400
3672823 119 18980672 88133847
67471612 108 41504712 97890476
40231264 19 37977684 52706386
96965371 77 21512104 86735367
29768987 114 25023034 84911918
59319041 24 8655797 88359567
81666143 66 7551736 73528006
68054496 103 13398677 59490218
84578976 36 34975186 62284778
32378800 45 23893...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
87968835
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 400 lines

Test #12:

score: 0
Accepted
time: 9ms
memory: 55088kb

input:

400 400 400
1581479 181 42400111 59732368
907309 87 5432725 51741834
25558404 52 27591603 55926047
73925801 89 12982129 72562916
93044109 8 22280490 87851712
4340628 199 21917419 59718121
29672983 78 47325176 83492730
37972962 29 7273544 67846186
33992886 275 8776836 87243343
19347144 392 15078284 7...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 400 lines

Test #13:

score: 0
Accepted
time: 14ms
memory: 53764kb

input:

400 11 400
40710338 3 16766984 69515403
16397634 1 40616452 86952344
23986892 4 3711721 90215388
77091994 9 20674420 67833193
91288329 1 33738566 54779431
10971676 10 6962019 90743517
31716858 8 45519538 68166156
5219948 2 17257088 68841179
83743328 11 47480189 76282688
78162024 7 32457788 53262410
...

output:

4939905
23411162
7237354
7801322
18434376
3540541
5694122
5210393
4697783
10462459
29677624
48631432
5297965
4337578
4367168
20332085
5214702
5091001
3888050
-1
5363635
4067299
6861399
15591527
4964092
1992550
6176507
5922653
16627616
-1
4028480
3968144
5974366
5520655
11225360
7374306
9720663
15759...

result:

ok 400 lines

Test #14:

score: 0
Accepted
time: 8ms
memory: 54372kb

input:

400 20 400
10522853 16 3875473 15470596
10244202 4 8804037 17670418
18427843 8 2894806 13624813
9342852 8 14040683 15305924
18066564 13 4953771 17185081
3290462 9 10613188 16519838
4724465 11 6497896 17646746
11138017 1 1435979 8077032
13696787 12 18036390 19470914
3792181 4 16705463 18216042
320466...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 400 lines

Test #15:

score: 0
Accepted
time: 8ms
memory: 53892kb

input:

400 3 400
7133454 1 5318840 16336998
14681771 3 14283494 19488133
3067337 2 15733173 18756469
19418351 2 195529 14731721
1990147 3 12317038 15097650
14347730 2 7126801 7455128
2501003 3 7366596 15539428
8853316 1 7516862 8151398
6938740 2 6852313 16787099
12511351 2 15104531 16729860
13626126 1 1382...

output:

3722216
1410158
2153626
823235
1917377
1202314
3296486
503311
-1
11340917
1082628
1614137
647038
711346
6169693
826067
1314916
8511450
2219292
-1
1148822
-1
1017529
1349749
1487025
5455581
2091924
1324126
1280399
1082465
1458499
1221119
452102
-1
3476390
1904784
839574
16318381
3437188
3442616
87847...

result:

ok 400 lines

Test #16:

score: 0
Accepted
time: 14ms
memory: 54264kb

input:

400 5 400
1338030 5 46136 1306367
516205 3 349494 674020
1457759 4 746415 1812760
41272 2 871535 1098966
1341950 5 1210712 1759003
1702670 2 432353 1906011
1675031 1 48529 1212647
100509 4 1542025 1626545
2622468 1 2140798 2675670
3910307 5 3717865 3981158
2007817 4 2984729 3555785
2944217 1 3461836...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 400 lines

Test #17:

score: 0
Accepted
time: 5ms
memory: 54256kb

input:

390 3 390
1146372 1 1908187 2533863
2446740 3 3169712 3309037
2202363 1 2162162 3137371
3073428 2 966559 2635463
3060348 1 260960 486563
2506279 2 1985241 2640110
2937458 1 1277976 1812302
1350636 3 1269239 2234342
2068936 1 999429 1946001
1420761 3 3269927 3275363
2426388 3 387304 1265083
1849865 2...

output:

2559714
2933290
-1
-1
1843610
-1
517555
-1
-1
-1
-1
2611274
-1
-1
1632355
-1
350545
1770180
2338077
2874779
-1
-1
1435419
-1
1493771
-1
-1
1234422
-1
-1
-1
1246494
2143487
-1
-1
540459
1783699
-1
-1
1921725
2021526
-1
-1
1193702
-1
-1
-1
1723826
2426718
1140893
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1208901
...

result:

ok 390 lines

Test #18:

score: 0
Accepted
time: 8ms
memory: 55136kb

input:

389 149 400
36593831 1 3784273 96375485
57440282 2 958534 98542960
38126928 3 36034 95331355
65995762 4 3373043 94808111
65030237 5 1683594 96169742
45136127 6 3653996 96503703
45252615 7 1775667 98338135
43231951 8 2000685 98734395
52397663 9 3095884 94520660
49714105 10 3766068 95790579
58169746 1...

output:

87969247
72859305
68429822
43479966
67681502
41461135
-1
38705911
50920201
62354342
42817692
81347574
67782120
44084429
76912490
73173037
71906180
96490576
76300295
65820149
-1
-1
-1
50185691
44389446
91162883
55968963
48090511
-1
80243422
60098514
51422725
49394331
-1
94587322
71133032
73417555
514...

result:

ok 400 lines

Test #19:

score: 0
Accepted
time: 9ms
memory: 55000kb

input:

396 214 400
42515756 1 3535916 96655328
62797037 2 2166531 94172150
54706374 3 1673019 96908826
37187317 4 5509987 94559482
62877046 5 1536575 97664313
62983296 6 4035537 97218191
43302636 7 5146517 98805937
57309706 8 3399216 96886919
63256572 9 4926648 96596943
49677708 10 506253 96364987
65777237...

output:

-1
80008513
78843150
59666539
80122533
72078494
61089492
80862696
83795645
86778746
50300138
51832223
65358649
47009165
72324985
64088034
29646137
74622987
48723688
77298052
71177138
58490373
55898526
45671241
46521430
49333721
-1
79827583
76486609
70589261
56983351
42774125
51664780
58099775
330527...

result:

ok 400 lines

Test #20:

score: 0
Accepted
time: 12ms
memory: 54436kb

input:

400 60 400
65168552 1 197837 97436716
66046539 2 2134081 95527091
66571017 3 3559448 96613004
36988788 4 11000 99200331
54756442 5 1145407 98377638
41324404 6 1232549 99338549
56248628 7 2532157 99842825
48283742 8 2957722 96050598
58805713 9 4393295 95746782
52221940 10 4775438 96699019
44736110 11...

output:

82828320
43610946
70072097
-1
90431812
48735588
62380873
79599694
87284897
65914706
76156761
42193550
45940557
48735086
51087414
44759492
74544813
65748555
76115200
86176138
48380986
65448967
70454534
83370670
76652150
83001737
60636180
53112950
73421570
-1
88220587
45851734
27404047
37404723
745171...

result:

ok 400 lines

Test #21:

score: 0
Accepted
time: 8ms
memory: 53920kb

input:

400 156 400
35659043 1 732284 85371572
45924193 2 300458 96861163
51798218 3 9738240 81279603
48639012 4 1226735 83780005
39462195 5 14259398 94145546
63563965 6 19262677 95272800
46744742 7 11186812 89239479
62764248 8 3205351 84912684
55399381 9 6805424 91170796
66428174 10 6837155 82124706
666132...

output:

-1
-1
-1
-1
-1
57718465
59597605
-1
-1
76712633
-1
-1
46733455
48857358
45033779
70384412
-1
-1
78637763
56085255
53736848
-1
61285488
87213847
-1
-1
-1
-1
88887623
-1
77018654
-1
-1
58252836
53483510
55432344
70749579
77251386
-1
42475480
66290720
65882863
-1
-1
89115582
54632870
59687352
60510765
...

result:

ok 400 lines

Test #22:

score: 0
Accepted
time: 8ms
memory: 53444kb

input:

400 220 400
60010265 1 3506055 86504662
39242364 2 10118684 92677226
36800333 3 18464122 80675074
60560739 4 1830235 87394751
45634626 5 12535177 87516185
62076225 6 10626428 89113240
52804395 7 16021761 91866831
44587319 8 17539258 89117504
60068701 9 2538902 91720974
53107572 10 1453968 94357950
6...

output:

84128943
62779261
57986920
77069794
43009750
61970847
83751085
-1
64955848
82621676
29200170
68851882
68321556
70287403
-1
47762527
69161896
66810866
67525148
87431041
52847819
-1
90762425
-1
-1
52270616
60661847
-1
-1
91311424
-1
-1
36170220
67541926
-1
-1
79831892
53791087
47511890
-1
86146563
-1
...

result:

ok 400 lines

Test #23:

score: 0
Accepted
time: 4ms
memory: 53692kb

input:

400 67 400
50971008 1 17498802 98237405
51407088 2 1905731 87800053
43859608 3 5502162 95995264
55434904 4 3145908 86648306
58312055 5 6565727 93428077
45747874 6 8589669 96851899
65445952 7 4189389 91652438
42468020 8 16472444 81012485
49756570 9 2283378 86505353
34481412 10 17989125 93634060
33630...

output:

-1
-1
54670007
37497132
-1
69710453
-1
80607403
58549262
45194314
-1
-1
61850222
73113778
54785450
73680577
54503594
-1
54573549
42942792
55412688
88339613
-1
81422086
71743088
-1
-1
-1
61524433
67319990
89627240
36842748
60608110
-1
-1
42265173
38907568
70004148
55145544
-1
77038352
-1
75937776
-1
...

result:

ok 400 lines

Test #24:

score: 0
Accepted
time: 9ms
memory: 54676kb

input:

400 400 400
100000000 1 1 100000000
100000000 2 1 100000000
100000000 3 1 100000000
100000000 4 1 100000000
100000000 5 1 100000000
100000000 6 1 100000000
100000000 7 1 100000000
100000000 8 1 100000000
100000000 9 1 100000000
100000000 10 1 100000000
100000000 11 1 100000000
100000000 12 1 1000000...

output:

99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
999...

result:

ok 400 lines

Test #25:

score: 0
Accepted
time: 9ms
memory: 53748kb

input:

400 400 400
42800778 1 16708238 94002944
13609386 2 28182812 71544065
79832947 3 30921885 98635264
62399729 4 12564983 89835010
51775003 5 30035874 87064508
2061087 6 24395270 73376487
71261001 7 7503556 86723656
54959030 8 22211415 75859069
77785946 9 27158490 95058905
61567484 10 1293538 86938365
...

output:

-1
50800067
-1
-1
-1
49992900
-1
55521560
-1
-1
-1
-1
-1
-1
53256954
51497729
-1
-1
71307016
-1
-1
91689048
-1
-1
-1
-1
-1
-1
-1
-1
-1
95378179
72396658
-1
-1
-1
89726365
97884397
51137862
-1
86659312
-1
54934487
-1
-1
-1
54862867
63528429
-1
-1
-1
92417904
-1
59133946
-1
-1
-1
-1
-1
-1
67952954
-1
...

result:

ok 400 lines

Test #26:

score: 0
Accepted
time: 4ms
memory: 54132kb

input:

400 211 400
16349623 1 18670501 45718763
65134081 1 21253982 74076632
36007630 1 44580513 99460414
99368186 2 30068977 85427051
97159871 3 19511448 71140413
26069032 3 40490078 78656208
32840687 4 12485377 46718190
7825021 4 32727325 69341753
5683892 4 49429559 89043612
35280489 5 23054737 87387167
...

output:

63995317
70179831
54893043
-1
-1
-1
-1
-1
-1
-1
91360138
-1
-1
-1
78233321
-1
-1
-1
93895222
75137218
98817906
80975346
-1
-1
-1
88628991
-1
-1
-1
-1
-1
69610578
-1
-1
65743782
-1
62091674
-1
-1
-1
-1
-1
-1
-1
-1
-1
67938036
55935311
-1
88620728
-1
-1
-1
53173231
-1
51796073
86616415
78998362
-1
930...

result:

ok 400 lines

Test #27:

score: 0
Accepted
time: 4ms
memory: 53324kb

input:

400 134 400
84865763 1 1449762 51584911
95796263 1 33716370 66107739
75453703 1 42227669 85769765
20302341 2 6385782 55297433
5887904 2 21079050 79254029
75528010 2 53378619 80263375
13826063 3 2203433 34697852
91527815 3 26713672 54172170
54822186 3 47029672 78178094
94634415 3 56643018 93356838
87...

output:

73400983
-1
53020098
80363670
81130310
-1
-1
-1
73948425
79762681
51068556
-1
63703232
-1
-1
69966535
-1
60661669
63208336
-1
-1
-1
-1
-1
88833246
46100824
-1
-1
69765650
-1
89346236
79533532
79286511
-1
-1
-1
-1
-1
67614297
52315397
-1
93708987
73082447
83038217
-1
77811918
76049359
93229491
-1
-1
...

result:

ok 400 lines

Test #28:

score: 0
Accepted
time: 14ms
memory: 54196kb

input:

400 44 400
35710445 1 9007721 30409287
99830025 1 18556117 42738837
27742044 1 24711880 49116041
75561747 1 40255585 66442597
38838136 1 51202628 73522366
43391128 1 58006128 83308395
54391589 1 74052639 93292689
18813555 2 7143709 22979706
38137780 2 15294310 26845368
31578867 2 17340002 34862693
8...

output:

-1
-1
-1
69358418
47508193
57462448
91436740
43306499
-1
58625695
69002605
60169831
52469693
74406598
78419481
-1
-1
89661286
-1
-1
67126575
52018273
47955248
65619074
66787585
-1
49354404
90338810
82102061
48795239
72318628
58234587
73118905
85380974
57447730
53014458
-1
75817261
93998358
-1
-1
-1
...

result:

ok 400 lines

Test #29:

score: 0
Accepted
time: 8ms
memory: 54388kb

input:

400 4 400
99338201 1 166307 1517779
33122497 1 941823 2234415
26591611 1 1851389 3123709
85880965 1 2483664 3834948
21130586 1 3291700 4723269
38606139 1 3884897 5829967
1880626 1 5062762 6562574
48911187 1 5458475 6981242
70766404 1 6560529 8025738
34173440 1 6984644 8712958
39037143 1 7657953 8894...

output:

45871272
36412472
76488815
67691147
80486729
35337879
85347318
28505473
27830333
36916030
51357789
37228399
87185308
30412352
94227024
18308975
71974833
33661668
38413926
20519250
72901195
73330394
16371875
29164248
45174240
81776756
32548494
46086755
36162532
27021299
32636476
43387713
26079036
234...

result:

ok 400 lines

Test #30:

score: 0
Accepted
time: 7ms
memory: 54292kb

input:

400 38 400
25 1 1 9
44 1 5 11
11 1 7 15
19 1 11 18
21 1 13 20
36 1 16 24
2 1 20 25
23 1 23 29
19 1 25 33
32 1 29 34
27 1 32 39
32 1 34 40
40 1 37 44
44 1 41 48
49 2 2 6
18 2 3 8
29 2 5 9
43 2 8 12
47 2 9 14
22 2 12 16
43 2 14 17
26 2 16 19
48 2 18 21
35 2 20 23
10 2 21 25
35 2 23 28
49 2 25 30
14 2 ...

output:

21
-1
35
-1
23
33
-1
-1
-1
-1
38
31
45
-1
38
34
39
38
33
41
42
-1
-1
-1
44
33
35
-1
24
34
44
23
31
30
-1
-1
38
45
30
-1
-1
48
-1
34
-1
43
40
36
23
39
-1
-1
43
-1
-1
-1
-1
-1
34
-1
-1
31
45
-1
30
41
43
-1
39
-1
-1
-1
-1
19
26
-1
33
36
22
37
-1
-1
-1
30
-1
41
-1
23
40
-1
30
-1
-1
47
41
39
-1
21
24
22
...

result:

ok 400 lines

Test #31:

score: 0
Accepted
time: 8ms
memory: 54368kb

input:

384 10 400
5035229 1 991655 5533662
3603482 1 2507601 7562718
5564194 2 764732 3227992
2466016 2 2495702 4550403
6766088 2 3142475 5911283
2726868 2 4510137 7355752
9404587 2 5109287 8165169
2169510 2 7000147 9851527
3629740 3 398130 3003575
6971019 3 2216012 3940047
628399 3 3532328 6065713
2944502...

output:

6065596
4511772
4004006
4007738
-1
4579455
6123769
-1
-1
-1
8864479
6635331
9234073
8728976
4349712
-1
8551795
5250940
8317155
-1
5070960
6239584
5712384
7831379
5747330
6977275
7371654
-1
5955290
6550596
-1
3910169
-1
-1
-1
4515762
-1
8211029
5174090
7301418
7836710
6516404
-1
-1
-1
7244133
-1
-1
2...

result:

ok 400 lines

Test #32:

score: 0
Accepted
time: 12ms
memory: 54616kb

input:

386 5 400
3010571 1 265473 1846840
2931577 1 1009009 2278090
4163727 1 1660173 2587461
2092776 1 2015508 3242745
279381 1 3058966 4314701
4905437 1 3572796 4734963
4329741 2 854858 2943240
73617 2 1885920 3917828
1622531 2 2976368 4562943
4125968 3 440520 2111757
1631785 3 1352001 2688897
3406030 3 ...

output:

3568000
3571983
-1
3233575
2869780
-1
-1
2585663
2857727
-1
-1
3295297
2968050
3907981
-1
3748559
2835948
-1
2891425
-1
3070756
-1
1834919
-1
-1
2300471
1661432
1456564
3670895
1153404
-1
-1
-1
1773890
-1
-1
-1
3618682
2877529
2668980
-1
-1
-1
536976
2237487
-1
4335810
-1
1572944
3014847
1728098
271...

result:

ok 400 lines

Test #33:

score: 0
Accepted
time: 4ms
memory: 54384kb

input:

316 2 400
825956 1 100175 903953
426154 1 462872 1088377
897101 2 84589 1210058
1487006 1 1372976 1883084
2385585 1 1662844 2102052
1714347 1 1755052 2442517
1453071 2 1418917 2388314
2672491 1 2743402 3245198
3705056 1 2916952 3350163
2988636 1 3127404 3532645
3396694 2 2784626 3321007
3573433 2 28...

output:

408731
-1
567142
-1
-1
502240
-1
686438
874926
-1
813343
441601
798727
827209
-1
244251
558194
388456
306390
-1
-1
-1
628285
514421
661655
140600
685138
-1
251463
339872
316658
760875
224380
128970
-1
302566
317573
216406
256466
335239
299944
510629
-1
-1
1091691
571134
-1
590537
201583
152020
58079...

result:

ok 400 lines

Subtask #2:

score: 7
Accepted

Test #34:

score: 7
Accepted
time: 325ms
memory: 66756kb

input:

60000 400 60000
36444793 284 3080519 96564525
76562130 166 22994125 59743695
76399902 168 29694545 59255380
66355790 132 10949454 89347938
40903435 35 29985718 66394219
83300910 368 17240174 54080010
85941830 363 31462093 87304647
73742613 40 29005856 54988711
27852051 29 6132393 88092297
52011498 2...

output:

4187955
12063529
12900463
3226307
10559309
3630811
3464102
2349487
10593270
4352751
12206074
3330919
9918520
2273900
2815160
3343146
4784218
4029015
3675912
3097583
3111953
3134642
2032575
7047105
2656134
3152545
4173492
4454062
10276964
8571917
2565070
2916843
3188475
2240657
2534321
4044412
133767...

result:

ok 60000 lines

Test #35:

score: 0
Accepted
time: 72ms
memory: 58312kb

input:

60000 6 60000
12 3 7 15
10 1 6 8
2 1 12 12
3 6 10 13
13 4 10 12
7 4 11 15
2 2 11 12
11 2 1 1
2 4 15 15
12 2 7 13
7 4 1 10
10 3 4 8
9 6 12 13
12 6 6 15
9 1 13 13
1 5 7 15
7 2 6 8
8 3 15 15
8 6 9 12
11 6 10 12
6 4 2 12
6 3 8 11
6 1 9 10
1 3 8 12
6 1 9 9
1 4 13 14
6 2 13 13
15 3 9 9
8 4 8 15
10 2 12 13...

output:

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
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
0
0
...

result:

ok 60000 lines

Test #36:

score: 0
Accepted
time: 292ms
memory: 62680kb

input:

60000 10 60000
97676569 2 76743953 88685974
95105143 4 43932988 73376067
76288333 6 92617916 98270964
90342208 3 40402911 69639648
33843177 10 26986536 90194147
6267732 5 63608012 88523254
7434115 6 32023864 61989797
11761897 6 21980809 94495856
66188528 1 73264146 82110042
59171955 3 14277338 57524...

output:

50934
77902
89165
70557
268052
116409
122462
34028
87774
446481
473777
43573
80880
71259
189355
220880
97525
233847
48942
76322
115779
86109
56783
97528
179902
64312
209077
130350
64127
304725
133009
34783
37976
73757
147651
110108
795553
38989
182712
57437
50691
37940
48662
526097
42900
75153
11829...

result:

ok 60000 lines

Test #37:

score: 0
Accepted
time: 283ms
memory: 63668kb

input:

60000 400 60000
35357917 106 38293412 94684300
83145885 104 8061264 45893965
34223214 63 89162022 92650692
17695158 303 7424324 16020399
80070382 360 36955678 84009798
92884003 244 82495997 98341121
35439223 250 58780027 74572027
65965217 348 62649096 64088389
81335145 154 16142185 56577974
61230381...

output:

4170388
10792534
4724031
9387143
-1
6113543
8419841
23129757
6935973
29089230
7150447
5429311
8848619
14220725
20216868
23459463
5977906
15120565
41700105
6291030
4346034
5828001
45713909
6915393
6394853
21183057
11929675
5675125
11188911
14125526
5203543
8659023
6877604
6884320
6842338
7762496
1908...

result:

ok 60000 lines

Test #38:

score: 0
Accepted
time: 320ms
memory: 66436kb

input:

60000 133 60000
20561991 86 25005935 61459650
26163084 90 46712018 76015341
35834416 95 29938241 83277292
91275144 36 3356508 79165872
45288993 129 33990712 50967656
23921464 4 2998749 83297148
90941504 98 41664456 94454241
35313504 42 21268586 90068636
33306098 121 27129638 83989086
59369734 133 24...

output:

4597679
1257253
1314315
1373379
746395
537598
1613056
1637922
1780770
2843637
1991792
2064448
724258
1046206
1003720
2065020
591046
728719
1765032
1529035
13009813
1213686
1242642
931843
1378061
1157507
616607
1812210
1742210
2435659
638669
1548908
1256669
746799
1916543
8344670
686201
2404961
14118...

result:

ok 60000 lines

Test #39:

score: 0
Accepted
time: 336ms
memory: 67236kb

input:

60000 11 60000
95017156 10 22055983 90540383
7214864 7 14505589 66729981
65618447 6 48075996 53916145
123143 10 4760078 75371216
63341349 7 44971994 83435307
65310969 7 28239153 64911494
38123767 11 3377065 60114696
58277623 8 32084862 53967693
96681909 7 33233164 99855578
19666257 9 5627734 6290910...

output:

336705
104860
94205
82790
43288
40651
54832
28163
26506
30596
18983
3739744
20887
31829
24015
41604
153894
41350
81612
57862
15729
86895
1025322
85802
221405
64158
87330
25630
29428
154778
77426
51096
24605
36197
50346
31159
33378
281265
53463
46743
39470
72112
21370
114028
51358
44094
24340
416178
...

result:

ok 60000 lines

Test #40:

score: 0
Accepted
time: 218ms
memory: 61616kb

input:

60000 20 60000
3425512 19 16018000 16549195
10119402 11 8238845 16194063
10268408 11 15839413 17100868
4399617 5 3259484 4732648
199676 11 16086296 18995937
1727842 8 7277268 16676508
6474927 13 3162304 7105628
5016549 5 5938383 19855399
5926152 13 4855095 17355188
3087266 8 918517 7822928
16432449 ...

output:

253004
164343
232146
348438
360215
141068
145249
260283
149276
224327
147694
259280
162914
254661
1130872
136138
2375633
153368
185090
175856
1274299
113654
143624
295611
244227
806555
200464
155743
162868
290566
166144
71081
221297
8732626
139680
140421
659251
484516
74592
1250711
143657
173489
143...

result:

ok 60000 lines

Test #41:

score: 0
Accepted
time: 225ms
memory: 60900kb

input:

60000 3 60000
18673433 3 5585202 14635377
783826 3 11774363 16770680
19553752 3 10057954 17405901
4686021 1 4633378 18808990
18193494 2 15475163 18023941
15045870 3 12037490 19440676
11189780 3 1998254 15563641
3689200 3 699453 762315
7205586 3 17614893 19586647
16220843 1 18388083 19723996
1728659 ...

output:

3099
6500
24888
159696
60871
7776
174516
17016
8163
99508
4769
17386
24043
11185
9724
707674
29885
13169
6701
9941
13405
7064
7448
26080
11853
58158
11457
48607
16725
10039
36762
11451
4153
168849
27848
11330
5740
42907
7483
28817
6565
3626
5997
15279
21600
32873
187015
9779
6529
9374
67572
13026
26...

result:

ok 60000 lines

Test #42:

score: 0
Accepted
time: 179ms
memory: 60544kb

input:

60000 5 60000
688239 1 1054551 1343759
180973 3 497075 543586
337167 3 853273 1769056
60342 3 262629 1916130
1563480 4 1419078 1530443
84479 1 1303616 1532279
514760 3 1511339 1772340
1583589 2 1633329 1783278
661787 5 736596 838091
1897157 2 1257190 1706268
1811663 1 100494 1797523
1622587 3 597834...

output:

12775
30199
38298
11590
55744
46051
47873
205893
90941
11330
8429
155284
84714
22339
18291
22005
36006
107643
110640
6161
25783
8564
31237
43086
27217
11362
16355
19282
16106
22465
40238
15981
17089
178549
36923
36752
53890
29567
21658
69362
48443
42018
22113
15784
78102
80409
61986
29617
8337
50702...

result:

ok 60000 lines

Test #43:

score: 0
Accepted
time: 192ms
memory: 60528kb

input:

60000 3 60000
2425933 1 1811168 2386010
1213569 1 1889604 2840745
1478278 1 874669 1590117
2807897 1 877927 2372459
1930604 3 662123 2545391
876201 3 317724 826102
1449373 2 1675828 2380928
562301 2 1338095 2549254
1023244 2 1785507 2886222
1848152 1 1753661 1999058
395709 2 1003035 3199243
1119344 ...

output:

6038
16852
6587
14319
4389
23142
110231
47901
26822
8757
169894
12226
22788
8932
21262
22982
46761
43432
7783
36162
28620
40483
17611
15331
98527
29128
18100
13254
51380
5983
32995
31639
3990
9003
27542
37097
17525
41749
8985
14129
5500
3854
79098
31518
10564
14931
11144
13924
50621
18356
20261
6961...

result:

ok 60000 lines

Test #44:

score: 0
Accepted
time: 219ms
memory: 61484kb

input:

59781 246 60000
37315959 1 60993 99801213
76422704 2 88569 948439
14046020 2 543599 1279657
8374607 2 1004457 1945741
40067097 2 1338158 2303255
21899560 2 1746120 2825984
31273845 2 2132469 2850232
26597475 2 2503612 3492829
43356396 2 2943290 3988444
11289373 2 3344028 4106971
45437891 2 3774846 4...

output:

74578823
76622648
73013434
90108506
51063886
73484565
48933151
72717340
-1
68961157
79954801
59001008
90732554
59750192
79321767
71427344
80948126
61836047
89246282
51759106
74064984
70128274
74145048
69402100
94406801
72222897
72756632
77956608
85049892
77741101
72834534
74127885
90290101
83721623
...

result:

ok 60000 lines

Test #45:

score: 0
Accepted
time: 204ms
memory: 61940kb

input:

60000 347 60000
66470962 1 12826942 88787444
86900368 2 26159482 73535463
71831560 3 6947936 58675484
78456057 3 32109463 90799791
99998804 4 15159826 59583172
37152313 4 31304630 68812769
5921233 4 40345601 93379104
12728410 5 4699578 44749006
69362307 5 32236449 64778266
97857017 5 35540293 809808...

output:

-1
64729533
-1
91994238
-1
65471365
69300455
79080511
93176276
-1
73186318
-1
-1
-1
-1
95110018
87449029
-1
-1
-1
-1
-1
-1
87751972
-1
91552158
71282793
-1
95490060
86455367
72476616
-1
-1
-1
49358706
63150818
-1
59953591
53296970
62747579
-1
-1
87304894
74845329
-1
-1
-1
-1
67781505
-1
-1
85598754
...

result:

ok 60000 lines

Test #46:

score: 0
Accepted
time: 56ms
memory: 60692kb

input:

60000 400 60000
100000000 1 1 100000000
100000000 2 1 100000000
100000000 3 1 100000000
100000000 4 1 100000000
100000000 5 1 100000000
100000000 6 1 100000000
100000000 7 1 100000000
100000000 8 1 100000000
100000000 9 1 100000000
100000000 10 1 100000000
100000000 11 1 100000000
100000000 12 1 100...

output:

99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
999...

result:

ok 60000 lines

Test #47:

score: 0
Accepted
time: 212ms
memory: 61676kb

input:

60000 198 60000
9095432 1 243193 771137
80236303 1 520439 874178
52146000 1 783121 1218256
35112073 1 949649 1545731
82268717 1 1149632 1668684
94054028 1 1520430 1939451
81189681 1 1885284 2286648
38906762 1 2151861 2696551
67991246 1 2455831 2981421
5951258 1 2544989 3313394
40346333 1 2957553 350...

output:

63321871
50195826
63147933
97291569
48592665
68629670
66739076
62707302
55018992
56455530
63519133
69857648
50938615
57769659
67061065
76767092
50053030
94433064
-1
52324182
66082894
60515406
-1
62168993
90238451
76826044
94434260
49303319
70985440
70265477
66336267
79427614
62986133
60065241
592082...

result:

ok 60000 lines

Test #48:

score: 0
Accepted
time: 195ms
memory: 60360kb

input:

60000 60 60000
98321395 1 8927 214763
68612679 1 123603 354938
35190718 1 210529 417336
61078644 1 329607 536731
53207463 1 373484 599622
48877415 1 537000 687679
31041929 1 614795 823539
49692897 1 734670 913854
59218351 1 754962 933816
65359961 1 893012 1075686
87351898 1 935909 1125846
48806010 1...

output:

45705196
52195993
95575646
53143537
78885385
45399284
80017113
54140330
87569701
39897014
75127428
74984434
79967311
68464764
48954190
69104414
60255318
76963073
83862626
80543415
73451548
89921740
51899795
95716878
55554915
76799026
75176115
66076680
57679193
76102903
77824168
79060140
71112800
692...

result:

ok 60000 lines

Test #49:

score: 0
Accepted
time: 176ms
memory: 60168kb

input:

60000 7 60000
40841429 1 1012 24513
68294018 1 11502 34849
81622562 1 33076 46768
22649411 1 33743 64990
37642709 1 53197 75824
12118727 1 56118 85129
38708722 1 70155 100781
27594550 1 81745 111481
62690 1 97653 122234
24384345 1 105288 129466
1328113 1 114498 142953
10830110 1 132461 152267
314372...

output:

66869082
61724092
65491542
44706122
35990332
77575183
52585229
32426183
48786578
30655237
62526724
52139867
46136859
41361333
29622578
58939948
28765458
53336522
74371698
85494901
28234193
69848438
30928704
37790814
22809402
56440597
27088725
42806668
74285070
38343485
18856777
15620780
40346452
407...

result:

ok 60000 lines

Test #50:

score: 0
Accepted
time: 131ms
memory: 61688kb

input:

57343 10 60000
18818 1 6425 26332
94952 1 14701 39520
4737 1 23921 54364
55499 1 42222 59730
16452 1 47605 74897
15088 1 57708 85132
96250 1 74157 96442
46432 2 774 28649
50622 2 18597 30787
42239 2 23538 49282
30883 2 35977 51551
89244 2 42001 67859
76185 2 55577 79336
5414 2 63617 87452
48371 2 79...

output:

39965
63837
55886
66807
39596
63967
79010
-1
48179
47580
-1
43070
-1
32096
-1
41924
52198
31438
-1
30946
-1
-1
-1
36227
54041
53833
-1
56476
59800
67516
-1
-1
67449
-1
80230
-1
-1
-1
58401
44913
48300
-1
39813
-1
-1
49904
-1
32342
80990
93929
49115
-1
-1
48891
74039
60027
57794
52127
-1
74178
-1
-1
...

result:

ok 60000 lines

Test #51:

score: 0
Accepted
time: 142ms
memory: 60200kb

input:

56600 5 60000
65920 1 5980 18734
5761 1 7167 22737
55716 1 16279 25828
2919 1 21166 35716
46655 1 29979 41388
98441 1 36931 44263
43391 1 42223 55259
92877 1 44038 59423
83779 1 54848 64556
18508 1 56992 72667
52190 1 68248 76115
85779 1 73934 86788
50232 1 78351 92741
40549 1 85228 97793
52115 2 44...

output:

27283
59033
-1
-1
31997
26260
37170
49830
36974
63752
27771
35169
50860
37462
56254
38832
19761
50142
34944
43468
-1
39958
44914
63654
-1
14281
84546
57939
68663
-1
37038
39397
-1
33155
-1
70049
25879
45707
52142
83501
49303
57787
64583
12836
20946
30246
36347
58667
78187
79150
36651
50623
30268
208...

result:

ok 60000 lines

Test #52:

score: 0
Accepted
time: 154ms
memory: 61048kb

input:

58144 20 60000
688620 1 21557 49553
947126 1 34398 73528
653491 1 57311 91664
841951 1 74082 134953
115951 1 96961 144546
759921 1 124937 178368
908401 1 143934 197373
396191 1 175446 218185
488430 1 197390 244525
634238 1 211085 270897
162428 1 229098 283496
182601 1 260626 296706
303257 1 294617 3...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 60000 lines

Test #53:

score: 0
Accepted
time: 165ms
memory: 60456kb

input:

59464 200 60000
2352378 1 108912 535536
2878912 1 291617 657900
2005814 1 418310 833378
2638419 1 612534 1048686
1916673 1 839703 1194535
1024871 1 1102969 1416313
1802959 1 1244102 1704391
487562 1 1496813 1872417
2523590 1 1729293 2072949
2532229 1 1777304 2299568
1468307 1 2012813 2475395
1535590...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 60000 lines

Test #54:

score: 0
Accepted
time: 167ms
memory: 61524kb

input:

57706 10 60000
493336 1 19737 85323
328969 1 53060 115770
2011146 1 82661 130140
42028 1 102428 160444
2270581 1 131762 206271
898573 1 163482 208451
3148819 1 195115 247064
2787613 1 212612 290923
705223 1 246364 298546
1156550 1 275641 350520
1469854 1 303755 358967
222303 1 326827 402431
2503196 ...

output:

2933594
1451023
1431485
2343312
1312240
791238
2013472
1466295
1012478
2487842
1368806
1768772
2938981
1390999
2426851
2014093
2006880
800391
2382933
1785060
1030365
1363946
952305
1976991
1209162
1584907
2522414
1438505
1522775
2011021
2372154
1238304
2016718
1398714
1781171
-1
1358780
777118
20115...

result:

ok 60000 lines

Subtask #3:

score: 10
Accepted

Test #55:

score: 10
Accepted
time: 1096ms
memory: 118896kb

input:

300000 60000 300000
52373645 39403 1 100000000
43175904 13875 1 100000000
55098270 40348 1 100000000
69248668 7569 1 100000000
69220659 14654 1 100000000
92585410 38487 1 100000000
41202983 28786 1 100000000
47874378 18728 1 100000000
7254419 14009 1 100000000
94592111 3845 1 100000000
19140558 2773...

output:

92572089
63051875
55804501
78575450
50003943
64449610
77271421
79106905
88880648
66025353
53245307
51023237
86239431
91432097
87018571
92214104
69302202
54090222
65223782
68084182
58672001
90191125
85664165
63548306
82947149
55401007
64762457
63374228
94614576
87656737
56978090
65217216
84550646
907...

result:

ok 300000 lines

Test #56:

score: 0
Accepted
time: 1150ms
memory: 110520kb

input:

300000 10 300000
93040678 2 1 100000000
59271814 5 1 100000000
37316939 8 1 100000000
7478119 1 1 100000000
1695217 7 1 100000000
57516451 5 1 100000000
6907995 5 1 100000000
60245146 4 1 100000000
82808072 3 1 100000000
9265646 1 1 100000000
7368378 6 1 100000000
31872639 3 1 100000000
99601010 4 1...

output:

5522
7334
5517
2562
2839
6098
2327
6405
2457
3772
2634
1727
4941
4466
5574
5731
5793
2915
2027
4940
2202
2505
6708
6735
2732
4969
5347
3220
6029
3392
3863
5132
3226
6882
7947
3618
1768
3015
9197
2585
3661
4680
3135
6374
9735
3804
12169
4088
2912
10938
1852
5842
3159
4684
4750
6077
3217
3744
2394
871...

result:

ok 300000 lines

Test #57:

score: 0
Accepted
time: 1197ms
memory: 152604kb

input:

300000 300000 300000
62727489 164656 1 100000000
56688078 181426 1 100000000
87141202 280365 1 100000000
11940497 141243 1 100000000
8793046 30906 1 100000000
66192492 103691 1 100000000
31724326 163318 1 100000000
23002584 222628 1 100000000
89415131 247427 1 100000000
35793293 211558 1 100000000
3...

output:

83436767
75334936
90660033
93135398
53429084
63545636
54790247
77936981
74925509
59663525
80162740
94200111
70138738
50803680
54765524
82855965
62057278
71446316
97905809
98702385
55324128
58922728
97145730
69786508
70039441
70155139
94518126
53350617
64444219
53404884
65490783
65833435
87799151
539...

result:

ok 300000 lines

Test #58:

score: 0
Accepted
time: 1121ms
memory: 124444kb

input:

300000 100000 300000
86166636 69539 1 100000000
17336389 10063 1 100000000
37480784 94541 1 100000000
14768768 41502 1 100000000
65398063 11337 1 100000000
84266136 19350 1 100000000
64067932 51281 1 100000000
41653502 43565 1 100000000
57066599 66302 1 100000000
27290210 38110 1 100000000
63284257 ...

output:

81900509
64888498
61040421
55451433
75576041
78273439
83697069
57387003
69218685
99039588
67133217
52606265
96344642
66926298
79096296
61111960
82210973
92972383
87870482
95248534
93326517
92431469
55383263
73378065
72330099
87228664
77974854
81356924
89024375
85274195
63788288
58628265
56764216
880...

result:

ok 300000 lines

Test #59:

score: 0
Accepted
time: 1146ms
memory: 110248kb

input:

300000 1 300000
17930182 1 1 100000000
20590273 1 1 100000000
39597199 1 1 100000000
20392086 1 1 100000000
78804082 1 1 100000000
52441457 1 1 100000000
55261461 1 1 100000000
12414102 1 1 100000000
77727582 1 1 100000000
8239755 1 1 100000000
32698480 1 1 100000000
42674452 1 1 100000000
63968433 ...

output:

342
31
213
38
189
117
285
83
6
92
78
641
117
367
38
422
176
221
33
41
198
29
207
245
94
448
164
50
191
109
392
278
300
72
101
266
35
88
155
514
152
205
364
291
482
7
94
48
23
53
13
334
333
65
340
115
105
44
178
11
137
27
83
206
46
41
88
79
258
218
65
112
21
437
92
64
37
79
44
30
54
294
5
25
298
254
...

result:

ok 300000 lines

Test #60:

score: 0
Accepted
time: 1198ms
memory: 110440kb

input:

300000 5 300000
27129595 4 1 100000000
56190752 2 1 100000000
95058256 5 1 100000000
41889597 4 1 100000000
54780172 3 1 100000000
43678932 2 1 100000000
75144995 2 1 100000000
18485880 4 1 100000000
69020362 5 1 100000000
44398591 5 1 100000000
71893878 3 1 100000000
58265982 4 1 100000000
56498652...

output:

2103
1321
1163
1011
2007
1052
600
3080
1553
2864
2132
809
3934
1502
4273
1311
1125
1220
1695
1903
1881
2115
1613
1593
827
575
1194
1595
2034
2063
1431
2289
933
2894
2896
1000
2478
3621
934
1524
1036
959
2247
2988
1324
1389
1597
1319
1402
3806
822
1696
1309
2219
1140
1943
1651
2239
2471
1460
1493
414...

result:

ok 300000 lines

Test #61:

score: 0
Accepted
time: 1042ms
memory: 152680kb

input:

300000 300000 300000
94528071 1 1 100000000
39684883 2 1 100000000
90568273 3 1 100000000
6631012 4 1 100000000
23285495 5 1 100000000
46426324 6 1 100000000
71957355 7 1 100000000
88230489 8 1 100000000
12303444 9 1 100000000
49280890 10 1 100000000
11151843 11 1 100000000
83445104 12 1 100000000
4...

output:

78260396
68271786
62691214
70632402
72254983
81306489
78988742
85032041
77786482
65329883
58428265
77900210
85198342
53710904
55385193
82894070
77807178
86604124
52221042
70340048
53901373
70607364
97817787
52807002
52209599
57077276
82147725
92635695
52081762
90178910
90489279
57461149
82718476
761...

result:

ok 300000 lines

Test #62:

score: 0
Accepted
time: 908ms
memory: 124700kb

input:

300000 100166 300000
59136436 1 1 100000000
51190433 1 1 100000000
17606146 1 1 100000000
60969159 2 1 100000000
48459752 2 1 100000000
74247907 2 1 100000000
92319606 2 1 100000000
72885303 3 1 100000000
98569041 3 1 100000000
84356906 3 1 100000000
53724960 3 1 100000000
44400800 4 1 100000000
366...

output:

84337365
58453069
71484240
94965177
51883089
80689854
66923402
89101954
71169601
53325319
92119752
96009119
70608673
92605810
53729373
80378875
78458856
64416267
72615534
79143621
91907813
87906166
55382327
62742829
95717778
65081688
75336018
49627395
94780175
95522149
98797677
95795044
55365227
638...

result:

ok 300000 lines

Test #63:

score: 0
Accepted
time: 809ms
memory: 114592kb

input:

300000 30048 300000
74582749 1 1 100000000
5799290 1 1 100000000
31752670 1 1 100000000
17258583 1 1 100000000
56845218 1 1 100000000
51635817 1 1 100000000
900108 1 1 100000000
27225561 2 1 100000000
64124035 2 1 100000000
26291772 2 1 100000000
58001042 2 1 100000000
60526138 2 1 100000000
4795228...

output:

87564347
69327130
55966183
56692477
51733435
49220473
44282280
75996025
54351711
58891035
73131189
49662728
61544976
44404010
50957395
61173489
41971057
52510826
51260853
49122854
71245841
81860613
45874211
80976620
60405648
75597172
42648646
44437987
39772800
43121836
42669491
74393629
54936563
868...

result:

ok 300000 lines

Test #64:

score: 0
Accepted
time: 894ms
memory: 110388kb

input:

300000 300 300000
93263765 1 1 100000000
45659360 1 1 100000000
66203805 1 1 100000000
32816640 1 1 100000000
40871405 1 1 100000000
22078617 1 1 100000000
21634161 1 1 100000000
88990266 1 1 100000000
28294009 1 1 100000000
3429140 1 1 100000000
20512056 1 1 100000000
94632829 1 1 100000000
7519341...

output:

235516
430655
422071
410869
400614
535448
369737
427713
494220
283088
469413
301013
337455
329289
498479
265910
394924
417055
414432
338721
482400
394817
325734
392365
288711
356803
405046
478179
293479
452759
566123
464585
520264
576216
317142
365983
414882
528215
447370
277049
417175
510030
452771...

result:

ok 300000 lines

Test #65:

score: 0
Accepted
time: 638ms
memory: 109492kb

input:

293048 20 300000
962119 1 1 100000000
660053 1 1 100000000
574253 1 1 100000000
372305 1 1 100000000
730726 1 1 100000000
12422 1 1 100000000
368149 1 1 100000000
850258 1 1 100000000
292975 1 1 100000000
26018 1 1 100000000
820861 1 1 100000000
565116 1 1 100000000
350173 1 1 100000000
245878 1 1 1...

output:

17121
5836
12871
9940
11985
14183
21999
8917
9675
12908
16908
14036
15582
8131
11560
8704
5543
22998
16684
16084
11100
9247
11591
26398
27174
11740
10442
8358
14601
20759
18400
12711
19791
16213
11654
8612
13616
9866
10350
7736
9495
17020
16238
7346
8582
9768
10809
23529
11352
13230
11722
6890
22118...

result:

ok 300000 lines

Test #66:

score: 0
Accepted
time: 628ms
memory: 110128kb

input:

297536 200 300000
1684415 1 1 100000000
2305984 1 1 100000000
938268 1 1 100000000
2799998 1 1 100000000
959483 1 1 100000000
1398011 1 1 100000000
2830108 1 1 100000000
997092 1 1 100000000
2432090 1 1 100000000
1352434 1 1 100000000
1943658 1 1 100000000
333717 1 1 100000000
674221 1 1 100000000
1...

output:

443207
222389
562825
216063
205431
486170
248462
338123
236755
243774
314118
321314
238900
302075
192079
212241
221647
269420
223211
294712
205589
222994
249490
218854
208134
244280
255397
233024
253749
314528
265161
246021
247637
488121
464774
263539
225610
296143
315572
246673
242142
171734
460900...

result:

ok 300000 lines

Subtask #4:

score: 23
Accepted

Dependency #3:

100%
Accepted

Test #67:

score: 23
Accepted
time: 1925ms
memory: 113724kb

input:

300000 6000 300000
18484573 1397 1 37221951
93018724 2863 1 21523237
20760115 1902 1 73572020
47861657 131 1 58366032
16672997 2854 1 70126530
51503726 1792 1 33692342
90778637 2112 1 52570427
19558814 1079 1 1196615
98646915 5883 1 88295729
5460512 2856 1 12409909
31020896 3642 1 33770228
36220207 ...

output:

9937102
14961480
41348977
20178508
27586139
21978693
-1
34525473
11749060
13910506
71983396
56004648
27255252
21440632
49786216
37475360
11801255
-1
25089693
-1
14613134
9509342
14050298
14147766
75991309
60676642
10842631
75290155
-1
11197340
18486285
14513136
10874212
14619610
14914187
13728378
95...

result:

ok 300000 lines

Test #68:

score: 0
Accepted
time: 362ms
memory: 85384kb

input:

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

output:

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
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
0
0
...

result:

ok 300000 lines

Test #69:

score: 0
Accepted
time: 2121ms
memory: 112820kb

input:

300000 10 300000
9924550 8 1 2939912
79922560 4 1 35734050
11350079 9 1 42734561
69678029 3 1 98928322
68190599 5 1 56814901
5419999 1 1 20179232
39369946 7 1 83324506
86787730 7 1 48141361
33465781 10 1 92855269
43430916 2 1 74441514
50928085 7 1 42734762
43714450 9 1 62517377
80910392 5 1 71775935...

output:

7756
9200
8884
13958
88838
6021
9905
21303
9476
16204
20881
25758
9982371
25261
203331
5118
2640
11136
4833
11764
13934
9093
4704
7052
6520
10488
3921
11605
11660
16282
7939
20817
15346
24758
44700
6029
4122
18755
18605
4710
18902
14508
136457
1865615
5465
6836
2196
14869
58046
55562
9223
14409
2671...

result:

ok 300000 lines

Test #70:

score: 0
Accepted
time: 2065ms
memory: 154840kb

input:

300000 300000 300000
79611361 172707 1 10595974
82371529 135353 1 40029472
61174342 243479 1 14370087
79173111 114810 1 15497296
25545323 250643 1 14541993
68871847 255914 1 39116817
9410469 144598 1 56068027
94255567 222758 1 77736367
40072840 103995 1 50294089
64925859 114187 1 93813432
27718634 5...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 300000 lines

Test #71:

score: 0
Accepted
time: 1923ms
memory: 121000kb

input:

300000 60000 300000
79322925 34751 1 70108992
63826650 15099 1 68251154
29131410 16166 1 69436449
26415873 58031 1 73889971
85972937 50200 1 40382566
40488957 23414 1 51397287
8823718 18578 1 29423419
19127362 18858 1 34398394
62944832 50576 1 96105999
23724677 26474 1 33914874
67732970 9616 1 23807...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 300000 lines

Test #72:

score: 0
Accepted
time: 1993ms
memory: 126912kb

input:

300000 100000 300000
13115916 20695 1 72258980
88244032 7094 1 1313410
11513924 23062 1 48487661
76968678 71965 1 21700948
31893445 63779 1 74576985
37202388 95764 1 98760788
41754075 41073 1 31966414
63163382 43695 1 88120583
52948500 22870 1 5599090
61455481 40739 1 16126260
6843964 57670 1 114507...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 300000 lines

Test #73:

score: 0
Accepted
time: 2061ms
memory: 112660kb

input:

300000 1 300000
44879462 1 1 31988516
86465212 1 1 65005773
13630339 1 1 83626939
27816188 1 1 88637244
45299464 1 1 9967391
5377708 1 1 40749115
32947604 1 1 73363945
88699790 1 1 70879877
68576779 1 1 30319088
37372321 1 1 48346897
26515083 1 1 84811087
54516263 1 1 44104729
90502007 1 1 68675166
...

output:

296
132
384
165
117
99
846
37
42
317
102
182
211
1634
164
3271
26
2026
350
489
3
2254
3618
27
48
282
1323
364
41432
497
999
970
629
184
66
153
243
233
558
15
125
166
77
1298
279
1206
501
141
31
154
877
1
725
485
328
55
98
1768
940
199
1401
125
221
737
908
591
76
61
87
890
2953
175
384
316
9322
971
6...

result:

ok 300000 lines

Test #74:

score: 0
Accepted
time: 2241ms
memory: 112820kb

input:

300000 5 300000
44013467 5 1 27181717
76841498 4 1 27490555
69091397 2 1 13723545
9122211 5 1 8898742
26308257 4 1 36246107
51390992 2 1 92323546
52831138 2 1 26915396
94771568 3 1 51377137
24710775 3 1 17381116
38372374 3 1 70537669
55645073 4 1 71683181
70107793 5 1 23989853
37808034 4 1 52707263
...

output:

4112
764
6088
15640
3120
520
38588
7556
4230
1424
1907
1444
4259
1726
2196
2114
4437
3654
5142
2038
47531
98134
3810
1218
1899
12877
1455
3037
4324
1471
11789
2956
7789
25359
2448
57017
1704
3137
2234
1284
3238
1001
1562
3008
2244
6310
1142
13119
5559
11526
3380
1814
26603
1619
8448
2595
914
1027
75...

result:

ok 300000 lines

Test #75:

score: 0
Accepted
time: 1932ms
memory: 157300kb

input:

300000 300000 300000
71536054 1 1 77621999
55106750 2 1 81609784
66109622 3 1 79702613
4283188 4 1 75683546
90966083 5 1 89094937
7041747 6 1 93791957
69169317 7 1 96419307
51972601 8 1 74000978
1686953 9 1 71373435
53720700 10 1 93004269
15181013 11 1 90214316
73349125 12 1 85195759
89075435 13 1 8...

output:

67059072
97532800
-1
54421521
-1
-1
92419268
97403618
-1
-1
90483434
-1
99736906
-1
-1
68911291
57809823
59842317
-1
73237943
76301836
70616850
92774092
65762545
69399696
-1
66525940
-1
51088547
-1
63103105
68696821
-1
85202225
80151608
79276543
81768417
77095255
-1
-1
-1
65838083
90507153
60070854
...

result:

ok 300000 lines

Test #76:

score: 0
Accepted
time: 1745ms
memory: 124116kb

input:

300000 74950 300000
50196577 1 1 68184005
71247478 1 1 99925872
87277856 2 1 49576703
72018607 2 1 58799176
60642541 2 1 77564094
54786713 2 1 92135635
71252802 3 1 46703377
20573607 3 1 69031723
29759763 3 1 91900696
91255265 4 1 69859471
8029841 4 1 98224290
957387 5 1 52925755
33680389 5 1 931519...

output:

59076299
-1
71338352
86355742
53939502
-1
95677779
73440902
73592206
68017441
78050875
71716985
57106834
60067881
58217472
84780829
90250959
70097889
-1
76636981
98478761
-1
50655390
71690147
86118781
57755122
85599911
76921890
60791033
56903604
-1
-1
61375733
92081516
89454428
80425545
-1
86834689
...

result:

ok 300000 lines

Test #77:

score: 0
Accepted
time: 1650ms
memory: 115060kb

input:

300000 15001 300000
87881111 1 1 7669825
15484063 1 1 11741295
83908835 1 1 17824905
77220931 1 1 21115690
37128460 1 1 23066471
39470477 1 1 28557593
77676778 1 1 31248356
81807407 1 1 33298759
46834343 1 1 36594205
36214894 1 1 39291073
75542597 1 1 43188551
21874085 1 1 46862504
49573910 1 1 5013...

output:

64251281
35307770
-1
52360708
25343158
48244014
58720155
36529969
64099891
30080606
51846495
56446498
-1
52665238
82896022
48255614
50223961
34316078
63035519
50314836
-1
34458159
55601896
52128130
32997874
60882526
39587211
38539550
51241243
25790295
35381219
52099456
55237310
65308079
-1
39537202
...

result:

ok 300000 lines

Test #78:

score: 0
Accepted
time: 1710ms
memory: 112748kb

input:

300000 158 300000
78156020 1 1 227935
62870656 1 1 304245
25526055 1 1 382058
85801839 1 1 437106
49622296 1 1 585214
51902280 1 1 690044
96595722 1 1 782244
87382009 1 1 840049
36961848 1 1 879515
16026532 1 1 992117
85922637 1 1 1058576
97333025 1 1 1216291
34822633 1 1 1249493
85087097 1 1 132641...

output:

956624
761421
418169
251558
205652
818524
1181716
623269
340007
269989
1297648
147680
7028323
779213
3528032
353747
644575
248304
763458
1181137
646704
473655
501420
339886
186349
200995
1532976
321276
155354
410930
511472
6323069
288013
711508
437856
326402
349546
1242084
326641
226068
2929118
1623...

result:

ok 300000 lines

Test #79:

score: 0
Accepted
time: 791ms
memory: 111168kb

input:

288667 10 300000
94735 1 1 5073
1557 1 1 8233
61028 1 1 10165
26868 1 1 12276
12319 1 1 15214
25135 1 1 16509
47096 1 1 19097
7017 1 1 21087
46205 1 1 23293
70551 1 1 25788
18479 1 1 28906
37798 1 1 29731
27168 1 1 33532
98675 1 1 36172
56603 1 1 38040
23825 1 1 38905
75484 1 1 41483
92999 1 1 44085...

output:

64671
92635
63178
91952
69763
46737
66960
64138
65542
104853
61984
50805
25259
77338
82973
26850
33399
102164
33608
38917
62603
30229
88613
83601
56010
90960
39512
16723
82713
66873
16867
90415
74105
93923
84809
13032
84045
69600
67917
77046
34804
15875
22354
100908
10209
83488
26972
91804
56070
801...

result:

ok 300000 lines

Test #80:

score: 0
Accepted
time: 804ms
memory: 110480kb

input:

284836 5 300000
99942 1 1 2905
90875 1 1 3426
15599 1 1 5234
28738 1 1 6159
99739 1 1 6690
72779 1 1 7978
50187 1 1 9169
77096 1 1 10090
59585 1 1 11274
62479 1 1 12754
83109 1 1 13684
70680 1 1 14615
41089 1 1 15968
13569 1 1 17259
73893 1 1 17925
38410 1 1 18771
83587 1 1 19883
22586 1 1 21630
277...

output:

3879
1740
3076
2967
64157
4297
3814
37920
6559
6382
3180
4095
7591
5557
2911
3090
6434
3029
16127
1811
5519
8105
4984
2386
4388
3676
6537
2485
4219
4620
92372
5098
2652
2633
66669
1647
13125
49491
87454
1833
2815
5814
6657
4913
4726
4610
4980
1221
3110
1817
2772
3191
4903
1743
8134
1615
2705
2134
37...

result:

ok 300000 lines

Test #81:

score: 0
Accepted
time: 921ms
memory: 111784kb

input:

292426 20 300000
630421 1 1 11707
305715 1 1 16328
617598 1 1 21644
698729 1 1 25977
764749 1 1 30375
932989 1 1 38950
322134 1 1 42590
260122 1 1 45822
469824 1 1 50995
959301 1 1 56366
503430 1 1 61231
994257 1 1 65409
974840 1 1 70565
544169 1 1 77250
965819 1 1 82340
612042 1 1 86982
866501 1 1 ...

output:

549215
764911
165545
695015
798343
513847
209346
937565
26636
768871
682420
942249
531385
214473
359994
879862
585787
453738
102158
805741
521808
43347
958124
787899
233685
982699
790990
119306
182436
414188
615088
864581
184407
829617
902220
920472
973222
44460
966110
443245
846234
804134
407520
12...

result:

ok 300000 lines

Test #82:

score: 0
Accepted
time: 996ms
memory: 112492kb

input:

296974 200 300000
2950046 1 1 285264
2724916 1 1 409676
1688317 1 1 454957
2673446 1 1 600572
2232510 1 1 661760
1397715 1 1 772520
116834 1 1 949272
2603020 1 1 1046411
45002 1 1 1174164
1551279 1 1 1257499
463645 1 1 1354268
62975 1 1 1463634
656309 1 1 1515030
534392 1 1 1704262
833281 1 1 172245...

output:

366016
507432
1151402
445130
550350
251845
865878
360197
3107446
2649116
184301
658898
671236
808311
1194952
418253
278205
339985
1222049
266621
1573672
1562192
1170845
705963
170463
344390
326773
598853
360526
2421714
586746
658271
570384
224371
758333
313642
700263
905599
496377
338509
692309
3105...

result:

ok 300000 lines

Test #83:

score: 0
Accepted
time: 1031ms
memory: 111620kb

input:

290872 10 300000
1707704 1 1 7437
2809041 1 1 9523
2213882 1 1 11615
3026721 1 1 15087
939126 1 1 17805
3266237 1 1 18585
2458906 1 1 23526
720363 1 1 26140
2345999 1 1 28740
755607 1 1 29451
2143518 1 1 33944
2737312 1 1 36098
1021770 1 1 39285
3316833 1 1 40604
1863212 1 1 43080
1407748 1 1 45491
...

output:

7472
15953
14790
18935
6462
35452
122549
5155
17220
12020
19247
34754
2807
15569
45831
5907
31126
10012
138363
3025
34780
5784
10503
6466
99498
24457
10034
6675
9645
9555
14244
4110
4739
15922
812018
3948
7346
5880
8222
3998
28824
15759
6764
10732
15450
13501
5461
13890
22436
306913
6629
11010
13747...

result:

ok 300000 lines

Subtask #5:

score: 35
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #84:

score: 35
Accepted
time: 341ms
memory: 76132kb

input:

60000 60000 60000
83448872 10404 45205919 50339735
36708841 21497 4902082 97712964
34097261 45398 38638183 51297139
10793824 31369 13841638 75803309
51204707 14772 21499849 55137158
82219659 2795 119886 66450614
14512608 10489 32690793 59504916
7128543 8635 32417983 76142161
26155257 31971 17794475 ...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 60000 lines

Test #85:

score: 0
Accepted
time: 306ms
memory: 71188kb

input:

60000 60000 60000
26989146 13025 40176777 71274092
7743106 53247 23734982 74432610
30238327 36264 31943653 65556194
75722089 29859 78315121 85479538
89149404 25999 93541000 95260000
42357544 56124 30335578 77825467
97660152 9389 32820141 34987282
43766731 31356 64794972 80116226
86359670 45654 78878...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 60000 lines

Test #86:

score: 0
Accepted
time: 305ms
memory: 69312kb

input:

60000 20000 60000
21887169 9757 44980014 88617023
15799348 14449 42417300 93492725
65903613 280 8541578 96714036
65634926 12308 48355949 66308493
91616141 13693 40188429 97568271
11805078 12288 3578160 62604949
37963126 8636 19073933 93731416
87645266 17252 1663826 89311418
92833534 2976 30732447 83...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 60000 lines

Test #87:

score: 0
Accepted
time: 224ms
memory: 66720kb

input:

60000 20200 60000
54192085 1 290940 99868075
35950014 2 137511 99768592
47766665 3 236543 99698160
56083303 4 446966 99705427
39348317 5 53683 99745028
49979073 6 372754 99802886
54584535 7 134943 99599799
65085698 8 397064 99534885
52233279 9 390020 99744164
52782808 10 346588 99883898
66503247 11 ...

output:

73871197
74373736
53839505
53029280
71399327
93576974
96107766
51705925
91303398
93752491
64751633
53786316
66176419
52425843
70528639
94507029
66671237
74503800
61726946
70077467
66241361
71743285
83199713
57818452
56901469
87094125
60059572
88134671
71363063
85435975
90387382
93694299
52548784
563...

result:

ok 60000 lines

Test #88:

score: 0
Accepted
time: 248ms
memory: 68956kb

input:

59929 30173 60000
64110568 1 213141 99926158
41434177 2 200079 99540962
47826435 3 292 99474845
48660536 4 284117 99879520
36699562 5 110601 99954778
36421422 6 424857 99457340
50987418 7 396422 99918556
59673912 8 46361 99487481
35366242 9 357149 99971334
33637989 10 329517 99499849
50719105 11 544...

output:

46357729
82864222
54943664
91583526
59551332
77333866
48492803
94942774
77752465
92169702
85195226
60315562
80866639
58324038
78259223
73338018
74616374
54509462
70654558
70914727
78846423
96944791
88966974
59708957
70141532
-1
72648365
98229606
78318238
81126713
62572765
64638573
72701481
61553218
...

result:

ok 60000 lines

Test #89:

score: 0
Accepted
time: 235ms
memory: 62860kb

input:

59824 6232 60000
55256092 1 161472 99625320
35331829 2 112788 99669382
38080628 3 97183 99824466
46320708 4 75885 99785855
55938095 5 285904 99805339
53821260 6 255661 99835264
51688882 7 276129 99582067
51584453 8 13444 99927494
40098775 9 110942 99642754
52593558 10 221099 99843849
39771648 11 177...

output:

65445691
56513948
86625192
86072853
54118391
49487408
84921718
61934332
58310068
95575057
51321104
65809650
74576549
51974220
45384258
69478076
76621993
88984964
83477324
46544450
54048974
64307136
51416697
-1
53391567
91200503
68569367
81143004
70629330
89233328
65621154
66948899
92614091
69757351
...

result:

ok 60000 lines

Test #90:

score: 0
Accepted
time: 230ms
memory: 65828kb

input:

60000 20283 60000
44332374 1 8805560 84151994
42640311 2 16708787 87174972
40358149 3 1990151 96793337
63028923 4 5783502 95423596
61353536 5 8944226 92579861
65122909 6 11059607 87266873
36908657 7 5408757 93010554
55630318 8 7160124 83960192
63547966 9 17526732 97980070
36516867 10 3903943 9056879...

output:

92191999
-1
72643913
-1
-1
55815473
98469421
-1
77229479
-1
-1
61602285
85201886
-1
-1
-1
60353778
-1
63956580
68008694
90056653
89992194
67260799
86460366
-1
51826870
-1
-1
-1
-1
78417781
62193258
68395618
-1
96582135
-1
-1
51685844
-1
-1
73947714
54370604
72962145
-1
-1
80535533
62600745
73094731
...

result:

ok 60000 lines

Test #91:

score: 0
Accepted
time: 267ms
memory: 69020kb

input:

60000 30245 60000
56586759 1 70656 90725255
63653216 2 12721119 95074262
63511027 3 9870766 85826227
62820395 4 4448570 99563341
44950010 5 1060738 96445163
65922518 6 2393163 93847061
55954225 7 17011212 80903879
66634594 8 6447235 92428471
45206104 9 17649557 84615256
52164344 10 5997635 84946783
...

output:

87187134
-1
-1
-1
58268459
92219910
51513742
-1
49034897
83153637
75817159
91996038
-1
-1
-1
-1
92727685
-1
62422043
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
83253213
62115189
82612630
-1
51355946
-1
-1
79888005
-1
-1
87987665
67102091
90784217
86077779
91503480
-1
67815314
-1
-1
66782288
81195103
-1
764585...

result:

ok 60000 lines

Test #92:

score: 0
Accepted
time: 226ms
memory: 62232kb

input:

60000 6329 60000
34498149 1 14974904 83685300
37496455 2 11686690 85640667
65750949 3 10443887 94429579
62026638 4 14942837 97478275
35814731 5 10722264 97199152
38613944 6 7511738 89702382
45293992 7 9877993 98461712
58551288 8 13539231 84423655
37829839 9 4581944 85022210
52387956 10 7469405 91145...

output:

68913951
-1
80224236
67033071
75180367
86773851
-1
-1
-1
58977296
50511499
-1
-1
75877069
69034280
78103276
-1
-1
88030690
76637348
-1
-1
-1
-1
89521368
67786858
49424016
-1
-1
80065107
77176521
88026358
67961905
54600350
-1
-1
-1
-1
98263414
-1
-1
60634981
-1
65847737
85763865
68492884
-1
94298217
...

result:

ok 60000 lines

Test #93:

score: 0
Accepted
time: 85ms
memory: 70360kb

input:

60000 60000 60000
100000000 1 1 100000000
100000000 2 1 100000000
100000000 3 1 100000000
100000000 4 1 100000000
100000000 5 1 100000000
100000000 6 1 100000000
100000000 7 1 100000000
100000000 8 1 100000000
100000000 9 1 100000000
100000000 10 1 100000000
100000000 11 1 100000000
100000000 12 1 1...

output:

99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
999...

result:

ok 60000 lines

Test #94:

score: 0
Accepted
time: 340ms
memory: 76460kb

input:

60000 60000 60000
16339245 1 2218138 77791950
47248877 2 18813525 90071122
2654615 3 12259018 95574172
69984277 4 15161524 82900076
99851796 5 15758755 77921090
70271618 6 6324312 67399339
4577070 7 8309705 80123332
71277394 8 18729993 81890129
71343340 9 6583393 99431819
11320368 10 11085365 694986...

output:

-1
-1
-1
-1
-1
95270274
-1
-1
-1
-1
94373844
-1
-1
67745083
-1
-1
-1
-1
56903073
-1
-1
-1
76322217
83646981
90739863
-1
-1
68469133
-1
80833421
-1
91659503
-1
89209594
-1
-1
-1
82192307
-1
74569307
-1
-1
52425375
80045773
-1
-1
55246473
-1
88268482
-1
99099616
-1
-1
-1
-1
-1
63184598
-1
-1
-1
-1
-1
...

result:

ok 60000 lines

Test #95:

score: 0
Accepted
time: 353ms
memory: 69700kb

input:

60000 30074 60000
89888090 1 4180397 49507769
20333619 1 34892071 63427705
17502748 1 44045027 88682201
1698279 2 29087134 86152459
91720076 3 26244615 85650552
67073044 4 8767602 54174880
3776236 4 48054218 76508224
3649823 5 1814572 68775379
83368360 5 41896456 96524612
51226727 6 12329678 4559298...

output:

-1
-1
97030854
-1
80101408
-1
-1
-1
-1
-1
69737525
-1
-1
53245530
-1
50889530
56101558
-1
-1
64842625
-1
60134092
88841267
82127034
-1
-1
-1
65933370
-1
-1
-1
-1
-1
-1
-1
-1
95345904
-1
-1
56007127
-1
-1
57892729
-1
99340639
-1
-1
-1
74004519
73230282
-1
-1
-1
-1
-1
-1
-1
99194792
-1
-1
70323372
-1
...

result:

ok 60000 lines

Test #96:

score: 0
Accepted
time: 279ms
memory: 67456kb

input:

60000 19995 60000
63436934 1 6959658 55373917
50995801 1 27354459 75458812
7205716 1 49175831 82475200
22632434 2 21369093 68047582
73280964 2 32008927 78985766
4280471 3 5096275 48922580
45174572 3 38284414 65249708
62183941 3 57816618 83845014
81108713 4 11010190 52868597
1492412 4 20745689 754387...

output:

51936906
52300668
63899210
-1
-1
-1
93403461
58615560
57338264
-1
-1
-1
75436567
56335080
51050541
-1
-1
-1
63703132
74853247
95815864
85135658
-1
-1
83840928
-1
86595657
-1
96488233
-1
-1
-1
87048930
-1
84874624
-1
-1
-1
56033563
-1
-1
-1
61475028
-1
81997339
83943157
76320633
74364577
83950269
745...

result:

ok 60000 lines

Test #97:

score: 0
Accepted
time: 269ms
memory: 63040kb

input:

60000 6662 60000
54473104 1 4041439 31658630
253754 1 15051368 56216917
54461353 1 37509729 62782282
93350711 1 53203386 79254522
15135489 1 62892001 98696213
36952068 2 179348 31051959
51505177 2 23258340 47451637
37280982 2 39622108 59859676
93533881 2 50715903 83839638
13748100 2 62929693 8716606...

output:

93294480
54447835
67467489
91277049
80857851
-1
-1
85077237
53708010
94959951
54394501
-1
70091637
59034079
72271314
-1
-1
57403838
63781970
80277715
91714490
59539431
88874138
-1
74134708
-1
98321315
-1
86510418
64126282
60920452
89742753
68288559
94318271
64493170
89458391
-1
-1
71341139
63340682
...

result:

ok 60000 lines

Test #98:

score: 0
Accepted
time: 230ms
memory: 61304kb

input:

60000 600 60000
66244725 1 511151 3615528
66761988 1 2302777 6138666
42345137 1 4370239 6979741
88211058 1 5863140 9374220
28715134 1 6806270 11762992
13421143 1 9108644 11899132
92024843 1 10261440 14448004
22154421 1 12512135 16182172
31195210 1 15242785 17883268
61566865 1 16830977 19336547
50322...

output:

54598297
58665123
77476958
53404671
73385013
92157577
69712546
76297101
92733790
73326269
71060930
71326833
84745568
97378844
55276251
76294702
71676212
78850981
75236072
50766440
77626037
72354648
97226126
93934633
71255063
91256199
-1
60017604
67454004
66907429
79775158
90753688
67057495
70895326
...

result:

ok 60000 lines

Test #99:

score: 0
Accepted
time: 145ms
memory: 60320kb

input:

60000 6007 60000
47 1 2 10
32 1 7 15
39 1 11 19
2 1 13 22
1 1 17 25
33 1 21 30
13 1 26 35
27 1 32 39
39 1 33 42
34 2 4 9
31 2 5 16
23 2 9 17
43 2 16 22
40 2 20 27
28 2 22 29
42 2 26 33
48 2 32 39
1 2 34 44
26 3 2 11
14 3 8 16
12 3 10 20
36 3 13 24
13 3 18 27
1 3 23 29
48 3 25 33
40 3 30 37
26 3 33 4...

output:

26
39
33
28
38
31
40
-1
-1
-1
-1
40
38
32
-1
47
-1
-1
-1
34
28
48
-1
44
-1
-1
-1
-1
-1
-1
30
29
-1
-1
-1
35
-1
-1
38
45
-1
-1
-1
-1
29
45
-1
-1
47
26
34
-1
48
27
-1
30
-1
35
41
-1
-1
41
-1
-1
-1
-1
28
28
47
-1
-1
-1
-1
36
-1
49
42
-1
36
38
-1
32
-1
-1
48
-1
-1
33
-1
32
29
-1
44
-1
46
43
39
-1
26
-1
...

result:

ok 60000 lines

Subtask #6:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Test #100:

score: 20
Accepted
time: 2380ms
memory: 164088kb

input:

300000 300000 300000
52904600 119851 47416462 53971948
7584090 147657 4355993 75127981
55580602 46285 1633651 61626065
79835000 32875 41820010 90114893
3903501 93162 3772222 82847539
86647843 36581 38476067 83295331
80618008 222316 18350531 67531245
79886464 115972 38844346 57038306
40892832 176067 ...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 300000 lines

Test #101:

score: 0
Accepted
time: 424ms
memory: 77844kb

input:

300000 6 300000
7 1 13 13
11 5 10 10
4 1 1 6
12 2 5 11
15 1 11 12
5 2 13 13
4 2 4 5
11 6 12 13
13 6 4 6
7 5 7 11
13 1 9 13
10 1 10 11
6 3 1 15
10 1 15 15
11 6 9 15
11 1 8 14
12 3 12 13
10 4 3 3
14 6 10 10
13 2 4 7
6 4 14 14
8 6 9 15
6 3 11 15
3 3 5 13
15 4 11 11
8 4 10 13
15 5 15 15
8 6 12 13
13 2 4...

output:

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
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
0
0
...

result:

ok 300000 lines

Test #102:

score: 0
Accepted
time: 2217ms
memory: 101932kb

input:

300000 10 300000
91481511 10 94185117 98472412
65179147 8 69471209 71147821
66049475 6 47293355 53562328
71079281 6 11864593 87726880
49377644 1 74084923 97389582
83268160 9 143805 87522745
32756521 6 53762849 73604451
14688668 5 37806179 70145168
95062463 10 21760371 89999326
92078572 4 89990582 98...

output:

100408
16596
21745
16077
10330
37022
9742
23086
59180
33269
26483
8966
49669
11316
13699
7108
13384
2535
15969
19732
140695
18465
22376
29547
64159
14643
4232258
32437
12271
89578
42965
22961
11522
13874
11140
15196
6783
70032
13564
24609
22291
193379
12327
11988
8067
122843
15308
37532
20785
122964...

result:

ok 300000 lines

Test #103:

score: 0
Accepted
time: 2198ms
memory: 144212kb

input:

300000 300000 300000
75210928 148689 85333233 94617743
69297943 163454 76188450 91065675
75927773 6807 26627634 96591048
68495545 291066 6128017 7458750
44426099 154171 96094980 97848397
87730537 227199 95401760 99007889
44887054 245954 53661139 68684519
83173221 10642 22375900 22899475
24911498 285...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 300000 lines

Test #104:

score: 0
Accepted
time: 2219ms
memory: 135916kb

input:

300000 100000 300000
98008766 91702 38664450 87267288
69247097 95968 4251925 75585842
11831835 18571 6237427 81884190
18985278 28442 17285677 54625570
10107152 41283 24852653 66855926
46682835 34417 45048622 68573846
50327387 33219 16338494 87360482
60817555 23786 5722179 70433189
56309752 27535 126...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 300000 lines

Test #105:

score: 0
Accepted
time: 2295ms
memory: 121820kb

input:

300000 11 300000
12662443 5 10485621 67897649
12677177 3 20905621 53399304
68275463 3 28789076 69123811
78159402 3 43132424 61330909
66013277 1 45917039 79899071
86877054 10 12627112 68446762
50960655 9 49937208 89645726
31836854 7 4465543 94598395
57680317 10 9954272 58730823
45089938 9 20275444 50...

output:

10201
48692
6803
5710
19686
10767
6043
58503
5957
3523
3754
18195
73574
12299
21802
33287
87806
5370
6771
3391
3646
11806
8399
8126
71128
10977
13344
9239
10855
212286
13899
4252
67214
90925
6200
4318
16362
87829
11773
4975
12597
7295
2692
11020
18933
43225
16732
8863
27860
23034
1103573
9974
20185
...

result:

ok 300000 lines

Test #106:

score: 0
Accepted
time: 1374ms
memory: 93784kb

input:

300000 20 300000
12474647 12 13868342 18721402
6340115 10 1509019 7527740
2409737 2 13866085 16876497
10072653 17 15790583 16208135
11392117 1 10516795 16105642
1542366 4 1731358 12817456
2266150 14 6131473 6984207
13053616 10 1614474 12861064
414499 17 3215233 4872631
12391147 19 14733043 16644617
...

output:

22309
41980
33375
141896
19220
45323
53231
68395
40707
22784
38378
38386
140797
47902
100227
17555
61291
36332
22403
38827
125292
43121
905681
41192
292868
83394
62694
53318
54194
36303
73283
24514
28289
41122
62720
42582
40661
56041
32480
62820
40569
40476
77621
33265
37361
47680
95062
40401
56904
...

result:

ok 300000 lines

Test #107:

score: 0
Accepted
time: 1574ms
memory: 93632kb

input:

300000 3 300000
8668735 1 17907302 18378787
5808318 1 12805695 15737111
5315007 1 4321686 6888845
17245571 2 8156625 9458013
8284085 1 12392442 19856891
10489823 1 11441983 15237115
16824562 1 6890355 12523891
14381250 3 10872204 15837245
4565896 3 19616803 19862623
17817950 2 538359 982239
14171334...

output:

2098
433
5679
14824
1286
1034
4006
2761
840
1150
11817
2705
1267
1338
1693
4919
4819
5743
506
2471
3986
2654
4286
4985
6748
3312
2470
1209
5274
1521
754
4917
3421
1852
612
3579
1530
403
5128
959
6018
3262
3490
3781
1176
3957
3545
601
2080
5725
2456
3030
10701
5428
342
5760
3333
5807
5408
1923
1853
1...

result:

ok 300000 lines

Test #108:

score: 0
Accepted
time: 1043ms
memory: 91808kb

input:

300000 5 300000
959116 5 705430 1053293
141954 2 633871 1734309
982497 2 1324183 1452809
407965 1 629310 1782423
1801084 4 1230627 1238004
318363 1 699262 1387333
395498 2 898327 1067004
310571 1 718156 1650835
931447 2 1719695 1872582
1122361 2 307686 1068669
1850544 2 474218 1718038
5489 2 93768 5...

output:

8137
4992
2338
17478
6312
7978
5418
49070
6494
37203
4615
11737
1337
18051
6467
3742
8251
10958
6721
4247
76114
10936
5364
4039
4543
12785
5474
5421
4002
5599
5025
10293
3959
7054
5748
24654
3427
7232
8248
8084
1394
9807
3446
34199
2160
8298
6890
2294
9003
5875
5912
27242
10534
4619
11202
5222
8362
...

result:

ok 300000 lines

Test #109:

score: 0
Accepted
time: 1116ms
memory: 92432kb

input:

300000 3 300000
691454 1 2461947 3325037
2188998 2 1808249 3192924
35972 3 523145 2449986
848773 1 1424773 1560211
2055763 3 1146145 1956010
1363252 3 1499596 3164670
330767 3 1196207 2187507
2562074 1 384445 1792222
205886 3 857761 2152734
3121023 3 1811220 3001454
1770027 2 1788280 2553662
2847564...

output:

3136
2009
630
4310
3811
2168
2245
2735
1656
2053
4281
22699
812
3143
12415
7434
8268
4211
3003
47620
2831
1380
2426
5502
218718
2886
2201
3508
4504
1560
21542
39355
1243
1336
1303
1431
2916
647
14898
3072
928
1533
11583
4021
2783
1231
634
4741
1925
259
7516
3916
4079
1589
884
3535
803
719
7076
7877
...

result:

ok 300000 lines

Test #110:

score: 0
Accepted
time: 1528ms
memory: 114864kb

input:

299809 100447 300000
55043238 1 16957 99879097
61602797 2 33567 99876696
55895916 3 43270 99991904
64229705 4 74867 99893602
64885385 5 1078 99845881
64963237 6 202667 99954960
55098142 7 205288 99947480
46778002 8 78971 99918209
34210239 9 143559 99889367
43803282 10 221186 99979742
57043967 11 184...

output:

90639907
72648060
78324219
83942727
81805935
84266073
72994455
91058374
78992130
97977150
49306328
52921759
80853936
68271230
84363347
68688344
64220052
84454330
83582026
82813343
90876199
55514318
81774577
81198846
78434644
51592332
56864038
52951744
56193815
94940247
86070711
69698395
63473425
952...

result:

ok 300000 lines

Test #111:

score: 0
Accepted
time: 1670ms
memory: 126972kb

input:

299769 150387 300000
35096617 1 152277 99911607
35134609 2 219873 99879274
38417646 3 16354 99847335
45651459 4 149101 99759872
53712994 5 161628 99777805
46493191 6 161924 99780726
59113780 7 148322 99987352
54070754 8 137217 99876586
44985460 9 224477 99785885
49825861 10 126614 99788634
48604776 ...

output:

94519451
55791175
80379013
71488022
92130849
69583629
50381634
62646165
80219233
57373997
77262457
73158735
65469862
72015765
84398638
84882413
83797955
87163540
51096370
86815932
71457867
93775973
58111789
69334167
47918368
99490897
65240621
86537490
76719557
62772997
89115009
52888499
61251033
731...

result:

ok 300000 lines

Test #112:

score: 0
Accepted
time: 1363ms
memory: 98196kb

input:

299880 30520 300000
58369705 1 72367 99845094
48207657 2 46109 99814052
48032002 3 121597 99932264
59495554 4 3201 99985816
37630398 5 184745 99903130
61503104 6 42511 99899937
55370596 7 173100 99952901
42125173 8 166410 99887829
51101130 9 103186 99867640
63786587 10 602 99869653
55639878 11 12560...

output:

56083747
96853896
66897184
48599546
92347505
70470384
68258585
76856725
92648610
50633317
88628333
68272501
88572982
75926404
79028179
66213570
55980928
70772304
92872112
86738240
92625930
90656871
54992923
61758207
87591989
68596166
59905122
73078698
96868684
92848451
67313128
87824686
82776441
739...

result:

ok 300000 lines

Test #113:

score: 0
Accepted
time: 1629ms
memory: 115672kb

input:

300000 100632 300000
49276475 1 11857763 93176195
61485399 2 15863819 80072237
37550613 3 9319780 89415171
48909648 4 7046124 98646482
62475214 5 2065111 91073888
65257792 6 5581173 85626609
49619192 7 14728557 88537030
43469701 8 7141415 98964270
55374441 9 12676338 99925385
41058688 10 14973140 80...

output:

91766961
56859028
-1
95846625
95454401
-1
86086606
-1
77486278
-1
71509517
84904579
72795627
-1
-1
62299498
61065120
-1
63551214
-1
-1
-1
85826223
-1
-1
82882588
-1
-1
-1
-1
67867388
66702062
84208383
55035788
-1
78121411
75223125
-1
-1
-1
80336518
-1
57330845
70809451
-1
54620029
-1
-1
-1
49267727
...

result:

ok 300000 lines

Test #114:

score: 0
Accepted
time: 1794ms
memory: 127400kb

input:

300000 150548 300000
40043557 1 19680146 84834390
52907124 2 3227211 94047361
52420459 3 19714532 93007452
60429496 4 8322458 82254962
43239629 5 3440093 96648456
40654993 6 6196698 99018973
42526295 7 10497206 97939664
65567868 8 7288031 82963829
54948564 9 13312759 98496113
42518660 10 5756999 868...

output:

-1
79765623
-1
-1
67780095
-1
-1
60515522
81779941
93059735
75422004
73178916
-1
-1
54874610
-1
-1
76250455
54255063
78111533
53268667
-1
-1
85810485
-1
56968300
-1
81251831
-1
88108009
97535566
82604579
-1
88933072
77387982
-1
-1
95901956
90320591
54952983
-1
-1
-1
60702953
59142410
-1
53258918
805...

result:

ok 300000 lines

Test #115:

score: 0
Accepted
time: 1437ms
memory: 97992kb

input:

300000 30735 300000
44351853 1 17080341 81340053
56710513 2 12757824 88863553
33539293 3 18532068 86726582
49500281 4 4431699 90805092
66219296 5 5074768 98922652
59786662 6 12525732 89739378
57792562 7 5027599 80407027
50431868 8 4608429 80246791
43112933 9 16728877 99071881
57118368 10 5584231 988...

output:

96537312
-1
-1
91480448
61629388
59284663
56644441
91018991
-1
85467052
67344593
90621609
52001850
92529875
-1
55546888
-1
95088318
78602672
84128710
-1
-1
75486756
-1
57306592
52184932
71694631
84635220
-1
-1
73444488
97144009
69828394
77214435
90307741
-1
-1
88383988
64345087
63891020
-1
71139551
...

result:

ok 300000 lines

Test #116:

score: 0
Accepted
time: 505ms
memory: 143620kb

input:

300000 300000 300000
100000000 1 1 100000000
100000000 2 1 100000000
100000000 3 1 100000000
100000000 4 1 100000000
100000000 5 1 100000000
100000000 6 1 100000000
100000000 7 1 100000000
100000000 8 1 100000000
100000000 9 1 100000000
100000000 10 1 100000000
100000000 11 1 100000000
100000000 12 ...

output:

99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
99999999
999...

result:

ok 300000 lines

Test #117:

score: 0
Accepted
time: 2375ms
memory: 164816kb

input:

300000 300000 300000
8009415 1 16871035 95133326
59144253 2 6508628 73768178
54050740 3 21074471 79515575
84829503 4 23774484 83575087
31219816 5 32781460 86070156
6534420 6 28538112 79245965
33975630 7 12512451 90417794
6083508 8 25504042 94187686
60704126 9 23595430 75945914
87318356 10 16648379 9...

output:

54234672
-1
-1
64534566
-1
-1
-1
-1
-1
62358832
-1
90673825
-1
65638990
62593614
-1
51229349
-1
-1
98059630
-1
67318604
-1
-1
-1
-1
-1
92423745
-1
-1
-1
68340409
50082710
-1
-1
68292996
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
71634850
-1
77283933
-1
-1
-1
-1
69163266
-1
66843054
-1
-1
-1
52444886
93011383
...

result:

ok 300000 lines

Test #118:

score: 0
Accepted
time: 2300ms
memory: 137752kb

input:

300000 150044 300000
41366772 1 499961 64332802
60916136 1 38844177 89212705
1038591 2 24389317 55228948
44485839 2 32978127 77620851
5196909 3 5194861 50996940
51013545 3 24525371 68646056
657368 3 41954059 85259583
13575174 4 343427 49838239
57750007 4 37554177 78345567
21191017 4 43178552 9470379...

output:

-1
-1
-1
80737008
-1
-1
-1
-1
81204645
-1
-1
-1
-1
92437210
69861632
-1
-1
-1
-1
-1
-1
78374955
-1
-1
-1
80030451
-1
57964931
-1
-1
87917503
-1
89475085
-1
-1
-1
-1
-1
-1
-1
-1
68171195
-1
69457216
-1
53605998
59618509
-1
-1
-1
-1
64609805
-1
-1
-1
-1
-1
89082857
-1
-1
62337106
76419930
76798283
-1
...

result:

ok 300000 lines

Test #119:

score: 0
Accepted
time: 2199ms
memory: 125840kb

input:

300000 99957 300000
14915616 1 23279222 50198950
86545613 1 41306565 91243812
76034767 2 20974850 50956558
65419995 2 41926771 84515982
61723949 3 8536839 52921241
35648490 3 22118978 70404977
23329477 3 56720943 97486965
87005896 4 4839642 74078040
50037948 4 34665255 78766912
24950071 5 13890503 4...

output:

-1
50224307
59548623
85857242
-1
78665613
52855422
73520861
-1
94304338
71361029
59101226
81121481
65499313
-1
67549975
90826303
-1
-1
-1
-1
-1
69048479
92921689
-1
-1
-1
58345290
-1
-1
-1
-1
63367521
80740291
99993393
73946046
-1
-1
-1
75691633
-1
92336988
-1
97010198
85767203
67544769
-1
82224192
...

result:

ok 300000 lines

Test #120:

score: 0
Accepted
time: 1978ms
memory: 102320kb

input:

300000 33353 300000
919082 1 2503918 13761991
95612079 1 12813084 25946833
94185278 1 13547058 28862917
4555348 1 25963791 39251196
39770977 1 28713033 42799178
30568619 1 36072482 49499884
33836402 1 44282067 57559964
38273876 1 49538016 63367800
30013426 1 59729846 66899510
37580500 1 65584342 778...

output:

-1
-1
74604486
74182905
74030514
86632190
54214235
80481997
86387545
83098803
91672264
97336576
71558199
68290214
55068456
-1
73078681
54942174
73454715
96121996
-1
-1
95204682
96281229
65340194
-1
-1
-1
59537983
75298254
-1
-1
61395819
56911448
51741626
90385984
82894131
95870760
82813864
-1
867004...

result:

ok 300000 lines

Test #121:

score: 0
Accepted
time: 1554ms
memory: 92340kb

input:

300000 3006 300000
5906439 1 430254 1502942
78657364 1 964327 2834340
89773824 1 1684151 3560271
30998618 1 2799663 4250786
88784551 1 3371018 5138110
236067 1 4412237 5581423
54543429 1 4496140 6582537
58417223 1 5315714 6794289
45120741 1 6613363 7784436
30496100 1 7215293 8213554
90161621 1 76263...

output:

81515220
67907738
68509752
63748673
77777255
83996965
84133412
79359166
56977991
82745982
91557215
87399298
82608304
77124286
88172989
76663820
83198827
53350099
82882626
64422982
94840843
84908134
89863929
99923650
81871369
86201020
85407456
83653256
97198844
87738669
91983696
80124641
76243281
676...

result:

ok 300000 lines

Test #122:

score: 0
Accepted
time: 1095ms
memory: 82676kb

input:

300000 30013 300000
16 1 4 10
22 1 5 13
3 1 9 19
28 1 16 22
33 1 18 25
35 1 22 32
30 1 28 35
39 1 29 39
26 1 35 44
14 1 38 47
41 2 1 6
42 2 4 7
46 2 6 9
27 2 7 12
29 2 9 14
45 2 11 16
10 2 13 17
31 2 16 20
15 2 17 21
39 2 19 23
48 2 22 25
21 2 24 28
27 2 26 29
4 2 28 31
26 2 30 34
36 3 2 13
1 3 10 1...

output:

35
-1
38
49
39
-1
26
33
30
-1
35
-1
26
33
-1
32
-1
39
45
48
-1
46
29
-1
25
-1
25
49
-1
-1
-1
37
-1
-1
34
27
26
31
44
29
41
35
-1
-1
-1
28
-1
47
-1
-1
36
35
37
37
38
-1
-1
27
-1
-1
-1
-1
37
-1
47
28
-1
47
40
36
38
38
36
32
32
-1
-1
-1
42
44
42
-1
-1
-1
-1
42
46
-1
31
-1
42
-1
40
-1
31
35
-1
-1
-1
39
...

result:

ok 300000 lines

Test #123:

score: 0
Accepted
time: 622ms
memory: 89664kb

input:

272799 7 300000
979 1 57 4235
1411 1 2612 6153
612 1 3593 7977
286 1 6237 9614
7417 2 2049 7146
3585 2 3999 9829
6194 3 1022 3691
8758 3 2516 5700
7992 3 3913 8015
2864 3 5278 8796
3664 4 892 3963
9739 4 2087 5496
6141 4 4272 6097
1090 4 4743 7903
9139 4 6772 8644
9805 5 2258 7295
1525 5 3781 8389
2...

output:

-1
-1
6086
-1
-1
-1
6922
5161
-1
-1
5686
4790
7392
5629
4493
8224
3824
-1
5586
-1
-1
4756
6361
-1
6517
9340
7249
-1
5962
-1
-1
-1
4162
6507
5950
7047
7070
6563
-1
-1
6033
5301
1521
-1
2360
-1
7373
-1
8223
8592
-1
4101
1814
3037
7874
-1
1609
-1
3862
-1
3392
-1
-1
5037
-1
-1
4826
5361
-1
7232
5935
275...

result:

ok 300000 lines

Test #124:

score: 0
Accepted
time: 723ms
memory: 89664kb

input:

288032 10 300000
28592 1 1591 5272
24427 1 3028 8423
30768 1 5485 8757
56783 1 7804 12024
14996 1 9650 14448
21708 1 12201 15830
39974 1 14266 19093
72926 1 15295 20476
86390 1 19326 23725
63782 1 19803 25066
54679 1 22028 28119
2539 1 24288 28782
79967 1 28011 32333
39220 1 29088 33039
4331 1 30823...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 300000 lines

Test #125:

score: 0
Accepted
time: 728ms
memory: 89832kb

input:

284797 5 300000
50906 1 979 2794
79603 1 1844 4722
60167 1 3505 5573
78805 1 3894 6372
2271 1 5319 7910
23577 1 7266 9258
51587 1 7843 10738
12057 1 9323 11543
22185 1 10860 12627
33862 1 12193 13864
76571 1 12658 14897
18658 1 14734 16772
20406 1 15008 17616
72102 1 16401 19361
50956 1 17426 20914
...

output:

58036
23369
59703
24174
31685
56665
39228
-1
34301
39980
52956
65440
23722
19499
19903
11148
40107
70458
11745
57896
14973
27702
46074
84008
53585
77188
58773
38183
36770
44287
36942
40073
15448
31454
75936
92275
85321
52302
46387
85648
80680
32055
59633
21225
41111
29672
64195
23496
31693
41663
367...

result:

ok 300000 lines

Test #126:

score: 0
Accepted
time: 850ms
memory: 90104kb

input:

292475 20 300000
630501 1 3663 26027
777864 1 17873 34823
290646 1 30291 49931
660941 1 40918 58717
771566 1 48314 70428
193569 1 55158 79245
616597 1 67978 95139
980779 1 81241 103721
394132 1 94217 119215
616888 1 102485 129149
111001 1 117617 133505
23992 1 124591 145568
508023 1 133268 155736
95...

output:

586728
435949
898865
759757
398383
606307
692908
428968
522756
409818
522385
648181
761548
488386
665337
328522
769485
470152
725034
501887
468629
786448
438426
717186
551146
507590
600347
433004
770394
654884
876095
706379
515706
867714
428501
481488
744598
881764
475375
876545
486774
823863
655890...

result:

ok 300000 lines

Test #127:

score: 0
Accepted
time: 962ms
memory: 90704kb

input:

298144 200 300000
1417327 1 85345 225892
181633 1 154335 329822
344992 1 195372 445444
43051 1 323047 507270
1814850 1 414659 613538
574461 1 469655 715961
519280 1 575701 773550
2209568 1 739220 905771
1592144 1 825437 972494
2367331 1 912927 1049537
3059267 1 952767 1199479
192657 1 1099503 124011...

output:

3203062
2119347
3012309
2243351
2974364
2354361
2085547
1735147
1700501
1703291
2074568
2159714
2063247
2064802
2222635
-1
1640645
3053558
2921032
1924940
2364733
1669366
3191894
2479264
-1
-1
2845742
3048292
2798300
2395405
2000347
1864452
3104614
2181997
3160844
2867216
2037083
2486949
3235349
218...

result:

ok 300000 lines

Test #128:

score: 0
Accepted
time: 893ms
memory: 90020kb

input:

293132 10 300000
1045056 1 2582 7652
3158909 1 5791 10980
1238926 1 7795 13329
127176 1 11727 16732
2340415 1 13077 19654
927736 1 18321 24910
2186443 1 19350 25832
2443699 1 24813 30691
2672610 1 26309 32324
2119067 1 30666 35702
3288536 1 34369 40751
2357532 1 37954 43343
1734203 1 40459 45324
864...

output:

2169291
1254863
2436226
1254120
-1
2027866
2408839
2946937
1457385
2421278
2429887
1037138
1630660
2030406
1014649
1219269
1168318
2759010
1555683
946875
1554119
1823108
2174454
1795957
2029198
1996049
1855028
2733152
2460463
2710025
2637694
2825484
1222863
1211552
1299527
2864702
1330121
1494373
88...

result:

ok 300000 lines

Test #129:

score: 0
Accepted
time: 978ms
memory: 91328kb

input:

298747 1000 300000
2357224 1 113155 445797
743342 1 228827 738991
244403 1 529366 988326
2584285 1 724592 1294197
781041 1 1106099 1441918
3002306 1 1279064 1679031
2778833 1 1354950 1971941
2680917 1 1639909 2199144
1907826 1 1977323 2353367
3117009 1 2089921 2472822
558462 1 2413906 2881508
165923...

output:

-1
2106790
-1
2129394
3271130
3123544
-1
2785893
2381509
-1
3303705
2062221
3006948
2101467
3239608
1669555
-1
2543834
2479037
1834161
-1
2866391
1981824
2202340
1810830
2764900
2097643
2099614
2277158
-1
3126256
2720949
3092504
2350100
2649569
2936172
1816342
2763478
2506963
2379535
2908945
3182014...

result:

ok 300000 lines