QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#767662#1164. Best Meeting Places0x3fAC ✓112ms16700kbC++14983b2024-11-20 21:38:352024-11-20 21:38:40

Judging History

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

  • [2024-11-20 21:38:40]
  • 评测
  • 测评结果:AC
  • 用时:112ms
  • 内存:16700kb
  • [2024-11-20 21:38:35]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N = 3e5 + 10;
int n, k, id, p[N];
ll cost[N];
priority_queue<ll, vector<ll>, greater<ll>> q;

struct edge {
	int u, v; ll w;
	bool operator < (const edge &o) const {
		return w < o.w;
	}
}e[N];

int find(int x) {
	if(x == p[x]) return x;
	else return p[x] = find(p[x]);
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i < n; i++) {
		int u, v;
		ll w;
		cin >> u >> v >> w;
		e[++id] = {u, v, w};
	}
	for(int i = 1; i <= n; i++) p[i] = i;
	sort(e + 1, e + id + 1);
	for(int i = 1; i < n; i++) {
		int u = e[i].u, v = e[i].v;
		ll w = e[i].w;
		u = find(u), v = find(v);
		if(u < v) swap(u, v);
		p[u] = v;
		cost[u] = w;
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += cost[i];
		q.push(cost[i]);
		if(i > k) {
			ans -= q.top();
			q.pop();
		}
		cout << ans << "\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7696kb

input:

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

output:

0
4
13
21
23
23
30
31
33
34

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 5652kb

input:

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

output:

0
8
14
16
16
16
18
18

result:

ok 8 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 5656kb

input:

3 3
1 2 1
2 3 1

output:

0
1
2

result:

ok 3 number(s): "0 1 2"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7760kb

input:

3 3
1 2 1
2 3 2

output:

0
1
3

result:

ok 3 number(s): "0 1 3"

Test #5:

score: 0
Accepted
time: 0ms
memory: 7700kb

input:

1 1

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 82ms
memory: 12488kb

input:

300000 91362
1 2 28477
1 3 1120
1 4 195435
1 5 18180
1 6 96438
1 7 213661
1 8 105906
1 9 270229
1 10 111645
1 11 131900
1 12 84735
1 13 241768
1 14 217875
1 15 166742
1 16 229095
1 17 76500
1 18 183455
1 19 169219
1 20 182463
1 21 195191
1 22 11784
1 23 118498
1 24 144515
1 25 183441
1 26 177597
1 2...

output:

0
28477
29597
225032
243212
339650
553311
659217
929446
1041091
1172991
1257726
1499494
1717369
1884111
2113206
2189706
2373161
2542380
2724843
2920034
2931818
3050316
3194831
3378272
3555869
3776978
3936356
4197705
4350102
4494264
4537191
4764898
4957649
5248516
5535494
5779495
5861283
6157050
6365...

result:

ok 300000 numbers

Test #7:

score: 0
Accepted
time: 80ms
memory: 12568kb

input:

300000 74786
1 2 277322
1 3 181674
1 4 124913
1 5 267434
1 6 99407
1 7 185644
1 8 157190
1 9 237089
1 10 148531
1 11 68148
1 12 287583
1 13 174562
1 14 120117
1 15 169769
1 16 177012
1 17 148415
1 18 87909
1 19 99941
1 20 179407
1 21 158940
1 22 159562
1 23 126007
1 24 86194
1 25 97298
1 26 63613
1 ...

output:

0
277322
458996
583909
851343
950750
1136394
1293584
1530673
1679204
1747352
2034935
2209497
2329614
2499383
2676395
2824810
2912719
3012660
3192067
3351007
3510569
3636576
3722770
3820068
3883681
3923203
4040146
4183103
4202667
4366055
4662357
4699652
4735836
4928812
5210390
5389121
5400984
5483988...

result:

ok 300000 numbers

Test #8:

score: 0
Accepted
time: 92ms
memory: 12020kb

input:

300000 58210
1 2 101974
1 3 186420
1 4 54390
1 5 216688
1 6 278183
1 7 281819
1 8 173882
1 9 71244
1 10 52713
1 11 128588
1 12 147327
1 13 274652
1 14 146550
1 15 207388
1 16 124929
1 17 96137
1 18 35467
1 19 197959
1 20 43648
1 21 122688
1 22 50444
1 23 813
1 24 284769
1 25 276563
1 26 206525
1 27 ...

output:

0
101974
288394
342784
559472
837655
1119474
1293356
1364600
1417313
1545901
1693228
1967880
2114430
2321818
2446747
2542884
2578351
2776310
2819958
2942646
2993090
2993903
3278672
3555235
3761760
3928207
3994203
4159985
4355227
4537841
4744413
5023999
5036319
5131404
5283390
5529554
5771492
5809030...

result:

ok 300000 numbers

Test #9:

score: 0
Accepted
time: 98ms
memory: 12504kb

input:

300000 130925
1 2 62628
2 3 243593
3 4 59789
4 5 170536
5 6 136601
1 7 91015
7 8 180463
8 9 142490
9 10 176502
10 11 283337
1 12 40785
12 13 46580
13 14 93096
14 15 228444
15 16 33933
1 17 102405
17 18 259741
18 19 19927
19 20 202214
20 21 223078
1 22 15946
22 23 12146
23 24 169634
24 25 180047
25 2...

output:

0
62628
306221
366010
536546
673147
764162
944625
1087115
1263617
1546954
1587739
1634319
1727415
1955859
1989792
2092197
2351938
2371865
2574079
2797157
2813103
2825249
2994883
3174930
3258550
3428157
3703493
3717828
3754827
3887555
3923049
4162176
4192402
4397850
4666823
4785254
4950575
5138927
52...

result:

ok 300000 numbers

Test #10:

score: 0
Accepted
time: 91ms
memory: 12488kb

input:

300000 114349
1 2 178769
2 3 124147
3 4 121970
4 5 295597
5 6 182673
1 7 62999
7 8 231747
8 9 285158
9 10 80684
10 11 43776
1 12 243632
12 13 279374
13 14 286825
14 15 231471
15 16 281850
1 17 174320
17 18 164196
18 19 117946
19 20 242263
20 21 11018
1 22 163724
22 23 19655
23 24 68209
24 25 93904
2...

output:

0
178769
302916
424886
720483
903156
966155
1197902
1483060
1563744
1607520
1851152
2130526
2417351
2648822
2930672
3104992
3269188
3387134
3629397
3640415
3804139
3823794
3892003
3985907
4079735
4110859
4211056
4248215
4285084
4437038
4558610
4607325
4780984
4888541
5160626
5213787
5266079
5374373
...

result:

ok 300000 numbers

Test #11:

score: 0
Accepted
time: 100ms
memory: 13524kb

input:

300000 230477
1 2 127613
2 3 128893
3 4 51448
4 5 112147
5 6 61450
1 7 291878
7 8 248439
8 9 119313
9 10 284866
10 11 104216
1 12 236080
12 13 246760
13 14 189066
14 15 269091
15 16 229767
1 17 122042
17 18 111754
18 19 48668
19 20 239208
20 21 107471
1 22 11501
22 23 202972
23 24 9888
24 25 273169
...

output:

0
127613
256506
307954
420101
481551
773429
1021868
1141181
1426047
1530263
1766343
2013103
2202169
2471260
2701027
2823069
2934823
2983491
3222699
3330170
3341671
3544643
3554531
3827700
3931736
3957081
4182138
4400905
4604941
4900313
5064860
5231674
5381469
5523839
5657820
5945711
6095374
6290905
...

result:

ok 300000 numbers

Test #12:

score: 0
Accepted
time: 87ms
memory: 11976kb

input:

300000 4377
1 2 158694
2 3 201051
3 4 210268
4 5 164709
5 6 285275
6 7 287345
7 8 166107
8 9 152225
9 10 132346
10 11 172110
1 12 137651
12 13 279680
13 14 288303
14 15 216576
15 16 109019
16 17 131019
17 18 151995
18 19 245160
19 20 99550
20 21 245980
1 22 160051
22 23 221532
23 24 221307
24 25 830...

output:

0
158694
359745
570013
734722
1019997
1307342
1473449
1625674
1758020
1930130
2067781
2347461
2635764
2852340
2961359
3092378
3244373
3489533
3589083
3835063
3995114
4216646
4437953
4521028
4761699
4839529
4961997
5201969
5361357
5411663
5421358
5466821
5570848
5609828
5894124
6036307
6116659
623139...

result:

ok 300000 numbers

Test #13:

score: 0
Accepted
time: 86ms
memory: 16700kb

input:

300000 287801
1 2 274835
2 3 81605
3 4 139746
4 5 289770
5 6 164052
6 7 216224
7 8 182799
8 9 286380
9 10 203824
10 11 232550
1 12 297394
12 13 79771
13 14 182032
14 15 86899
15 16 56936
16 17 202933
17 18 56449
18 19 43178
19 20 263791
20 21 209728
1 22 7829
22 23 104849
23 24 128394
24 25 296932
2...

output:

0
274835
356440
496186
785956
950008
1166232
1349031
1635411
1839235
2071785
2369179
2448950
2630982
2717881
2774817
2977750
3034199
3077377
3341168
3550896
3558725
3663574
3791968
4088900
4348291
4420342
4624567
4746148
4905407
5099132
5319098
5474148
5721607
5962696
5984696
6061609
6196228
6230906...

result:

ok 300000 numbers

Test #14:

score: 0
Accepted
time: 95ms
memory: 16348kb

input:

300000 271225
1 2 223679
2 3 94863
3 4 201928
4 5 239024
5 6 34317
6 7 188208
7 8 234083
8 9 253240
9 10 108006
10 11 292989
1 12 24434
12 13 179861
13 14 84273
14 15 81414
15 16 4853
16 17 283360
17 18 4008
18 19 273900
19 20 128032
20 21 130373
1 22 31414
22 23 112359
23 24 70073
24 25 210789
25 2...

output:

0
223679
318542
520470
759494
793811
982019
1216102
1469342
1577348
1870337
1894771
2074632
2158905
2240319
2245172
2528532
2532540
2806440
2934472
3064845
3096259
3208618
3278691
3489480
3759080
3992648
4021734
4166139
4325268
4538219
4676967
4941604
5165200
5432590
5449190
5460833
5692822
5990545
...

result:

ok 300000 numbers

Test #15:

score: 0
Accepted
time: 96ms
memory: 12452kb

input:

300000 77873
1 2 176698
2 3 192710
3 4 151879
4 5 89559
5 6 53434
6 7 188025
7 8 99826
8 9 93293
9 10 253225
10 11 58894
11 12 37831
12 13 75651
13 14 153141
14 15 112410
15 16 128656
16 17 283031
17 18 180735
18 19 282154
19 20 151239
20 21 241535
21 22 50878
22 23 70298
23 24 14429
24 25 279300
25...

output:

0
176698
369408
521287
610846
664280
852305
952131
1045424
1298649
1357543
1395374
1471025
1624166
1736576
1865232
2148263
2328998
2611152
2762391
3003926
3054804
3125102
3139531
3418831
3647944
3808199
4091995
4199004
4221037
4391884
4586161
4618489
4650925
4854913
5008669
5011002
5265829
5403890
5...

result:

ok 300000 numbers

Test #16:

score: 0
Accepted
time: 88ms
memory: 12116kb

input:

300000 61297
1 2 292838
2 3 73264
3 4 214061
4 5 38812
5 6 232211
6 7 284201
7 8 151110
8 9 227449
9 10 157407
10 11 119333
11 12 64871
12 13 175741
13 14 222678
14 15 239629
15 16 76573
16 17 187650
17 18 252486
18 19 80172
19 20 15480
20 21 205284
21 22 198655
22 23 245104
23 24 88812
24 25 17349
...

output:

0
292838
366102
580163
618975
851186
1135387
1286497
1513946
1671353
1790686
1855557
2031298
2253976
2493605
2570178
2757828
3010314
3090486
3105966
3311250
3509905
3755009
3843821
3861170
3976300
4130777
4239434
4536563
4725762
4915835
5196191
5470810
5646679
5752776
5768428
6005491
6190393
6415692...

result:

ok 300000 numbers

Test #17:

score: 0
Accepted
time: 90ms
memory: 12096kb

input:

300000 44721
1 2 117490
2 3 78010
3 4 267731
4 5 288066
5 6 278283
6 7 256184
7 8 35098
8 9 61604
9 10 61590
10 11 188285
11 12 57319
12 13 108535
13 14 249112
14 15 277248
15 16 157194
16 17 135372
17 18 32748
18 19 143598
19 20 188233
20 21 169032
21 22 46433
22 23 252613
23 24 30491
24 25 63910
2...

output:

0
117490
195500
463231
751297
1029580
1285764
1320862
1382466
1444056
1632341
1689660
1798195
2047307
2324555
2481749
2617121
2649869
2793467
2981700
3150732
3197165
3449778
3480269
3544179
3802221
3818215
3919029
3930471
4119540
4196136
4386762
4470968
4622973
4755371
4774135
4945927
5185096
533033...

result:

ok 300000 numbers

Test #18:

score: 0
Accepted
time: 93ms
memory: 12532kb

input:

300000 105958
1 2 173172
2 3 156598
3 4 188478
4 5 174850
5 6 90837
6 7 16126
7 8 218383
8 9 174496
9 10 209408
10 11 32256
11 12 234808
12 13 220670
13 14 188936
14 15 208424
15 16 221131
16 17 151900
17 18 103330
18 19 267436
19 20 77633
20 21 108384
21 22 179274
22 23 72385
23 24 148342
24 25 253...

output:

0
173172
329770
518248
693098
783935
800061
1018444
1192940
1402348
1434604
1669412
1890082
2079018
2287442
2508573
2660473
2763803
3031239
3108872
3217256
3396530
3468915
3617257
3642621
3682457
3915100
4143079
4433994
4709285
4944983
5118203
5268986
5526759
5765846
5928894
5940700
6232952
6330204
...

result:

ok 300000 numbers

Test #19:

score: 0
Accepted
time: 100ms
memory: 12504kb

input:

300000 89382
1 2 122016
2 3 37152
3 4 74852
4 5 132615
5 6 269614
6 7 120814
7 8 269667
8 9 8652
9 10 246294
10 11 225399
11 12 261847
12 13 20760
13 14 258473
14 15 78747
15 16 169048
16 17 232327
17 18 7785
18 19 65454
19 20 250386
20 21 72133
21 22 27051
22 23 212598
23 24 214214
24 25 71925
25 2...

output:

0
122016
159168
234020
366635
636249
757063
1026730
1035382
1281676
1507075
1768922
1789682
2048155
2126902
2295950
2528277
2536062
2601516
2851902
2924035
2951086
3163684
3377898
3449823
3632571
3726731
3912275
4050206
4192663
4447587
4531077
4667255
4935756
5076952
5110408
5348432
5570759
5755248
...

result:

ok 300000 numbers

Test #20:

score: 0
Accepted
time: 90ms
memory: 12468kb

input:

300000 72806
1 2 238157
2 3 174601
3 4 4329
4 5 249165
5 6 139878
6 7 84285
7 8 153655
8 9 151319
9 10 150477
10 11 285839
11 12 121591
12 13 253554
13 14 284907
14 15 73262
15 16 116965
16 17 4241
17 18 255343
18 19 163472
19 20 247330
20 21 168586
21 22 50637
22 23 220108
23 24 288597
24 25 285782...

output:

0
238157
412758
417087
666252
806130
890415
1044070
1195389
1345866
1631705
1753296
2006850
2291757
2365019
2481984
2486225
2741568
2905040
3152370
3320956
3371593
3591701
3880298
4166080
4359036
4447418
4457823
4653171
4662794
4936944
4939217
5017687
5262324
5262525
5457877
5463335
5483033
5754760
...

result:

ok 300000 numbers

Test #21:

score: 0
Accepted
time: 90ms
memory: 12428kb

input:

300000 123034
1 2 99608
2 3 172423
3 4 9456
4 5 282835
5 6 245866
6 7 203405
7 8 258
8 9 224221
9 10 179926
10 11 55080
11 12 66606
12 13 132472
13 14 286139
14 15 110843
15 16 105635
16 17 123692
17 18 174429
18 19 82512
19 20 7928
20 21 238913
21 22 64001
22 23 41840
23 24 292389
24 25 278375
25 2...

output:

0
99608
272031
281487
564322
810188
1013593
1013851
1238072
1417998
1473078
1539684
1672156
1958295
2069138
2174773
2298465
2472894
2555406
2563334
2802247
2866248
2908088
3200477
3478852
3555033
3779303
3954383
4166047
4259813
4346050
4374980
4487605
4632060
4800049
4833960
5011725
5162366
5390544
...

result:

ok 300000 numbers

Test #22:

score: 0
Accepted
time: 93ms
memory: 16348kb

input:

300000 273754
1 2 48453
2 3 185680
3 4 238933
4 5 232089
5 6 124643
6 7 8092
7 8 184246
8 9 191080
9 10 251405
10 11 115520
11 12 226349
12 13 232562
13 14 55677
14 15 148462
15 16 53552
16 17 36822
17 18 78883
18 19 13234
19 20 4873
20 21 202662
21 22 211779
22 23 225158
23 24 66773
24 25 192232
25...

output:

0
48453
234133
473066
705155
829798
837890
1022136
1213216
1464621
1580141
1806490
2039052
2094729
2243191
2296743
2333565
2412448
2425682
2430555
2633217
2844996
3070154
3136927
3329159
3591356
3677143
3977084
4246164
4382904
4621071
4736079
4923699
5044291
5238581
5267093
5546883
5627599
5643015
5...

result:

ok 300000 numbers

Test #23:

score: 0
Accepted
time: 100ms
memory: 12528kb

input:

300000 89882
1 2 130001
2 3 190426
3 4 168411
4 5 57150
5 6 294908
6 7 271564
7 8 235530
8 9 25236
9 10 155587
10 11 51767
11 12 253389
12 13 208461
13 14 82110
14 15 151490
15 16 134173
16 17 108736
17 18 26441
18 19 111252
19 20 169114
20 21 166410
21 22 235365
22 23 232667
23 24 8452
24 25 106089...

output:

0
130001
320427
488838
545988
840896
1112460
1347990
1373226
1528813
1580580
1833969
2042430
2124540
2276030
2410203
2518939
2545380
2656632
2825746
2992156
3227521
3460188
3468640
3574729
3847134
3927142
4051944
4168040
4171946
4420827
4446106
4743313
5007337
5236439
5268063
5315287
5458782
5694139...

result:

ok 300000 numbers

Test #24:

score: 0
Accepted
time: 91ms
memory: 13516kb

input:

300000 262027
1 2 199501
2 3 57940
3 4 138717
4 5 200385
5 6 209196
6 7 110624
7 8 294126
8 9 227561
9 10 195746
10 11 230127
11 12 107367
12 13 5752
13 14 17934
14 15 177040
15 16 199440
16 17 179770
17 18 66433
18 19 92711
19 20 138054
20 21 259947
21 22 29380
22 23 285100
23 24 103833
24 25 12364...

output:

0
199501
257441
396158
596543
805739
916363
1210489
1438050
1633796
1863923
1971290
1977042
1994976
2172016
2371456
2551226
2617659
2710370
2848424
3108371
3137751
3422851
3526684
3650328
3944360
3965650
4078305
4120469
4287624
4427368
4709671
4823603
4887589
5176392
5311711
5348913
5635346
5898508
...

result:

ok 300000 numbers

Test #25:

score: 0
Accepted
time: 89ms
memory: 12532kb

input:

300000 78155
1 2 148345
2 3 238493
3 4 68195
4 5 25446
5 6 220677
6 7 215311
7 8 10818
8 9 61716
9 10 232633
10 11 290566
11 12 99815
12 13 114355
13 14 220175
14 15 47363
15 16 147357
16 17 84388
17 18 13992
18 19 156137
19 20 2295
20 21 223695
21 22 9862
22 23 168417
23 24 45513
24 25 37501
25 26 ...

output:

0
148345
386838
455033
480479
701156
916467
927285
989001
1221634
1512200
1612015
1726370
1946545
1993908
2141265
2225653
2239645
2395782
2398077
2621772
2631634
2800051
2845564
2883065
2887305
3070112
3307628
3364104
3531130
3681588
3874162
4063089
4103211
4126827
4265259
4404487
4620995
4804099
48...

result:

ok 300000 numbers

Test #26:

score: 0
Accepted
time: 84ms
memory: 12104kb

input:

300000 61579
1 2 97190
2 3 243239
3 4 130376
4 5 274700
5 6 90942
6 7 178783
7 8 194806
8 9 28576
9 10 136815
10 11 183710
11 12 2662
12 13 214445
13 14 246608
14 15 217686
15 16 95274
16 17 32111
17 18 85742
18 19 254155
19 20 7751
20 21 187444
21 22 33447
22 23 175927
23 24 119896
24 25 251358
25 ...

output:

0
97190
340429
470805
745505
836447
1015230
1210036
1238612
1375427
1559137
1561799
1776244
2022852
2240538
2335812
2367923
2453665
2707820
2715571
2903015
2936462
3112389
3232285
3483643
3498091
3675119
3737496
3851389
3894093
4063778
4209726
4508240
4691794
4917519
5050551
5081404
5227987
5498328
...

result:

ok 300000 numbers

Test #27:

score: 0
Accepted
time: 91ms
memory: 12516kb

input:

300000 103471
1 2 73103
2 3 171431
3 4 35007
4 5 239495
5 6 297225
6 7 209031
7 8 91867
8 9 229789
9 10 73810
10 11 42067
11 12 7312
12 13 282585
13 14 106066
14 15 88349
15 16 275649
16 17 120441
17 18 46567
18 19 51819
19 20 128421
20 21 256651
21 22 290820
22 23 114585
23 24 39465
24 25 88438
25 ...

output:

0
73103
244534
279541
519036
816261
1025292
1117159
1346948
1420758
1462825
1470137
1752722
1858788
1947137
2222786
2343227
2389794
2441613
2570034
2826685
3117505
3232090
3271555
3359993
3599653
3619578
3701989
3824087
3829714
3864884
4155860
4217919
4515293
4618995
4856033
4857891
5110328
5358419
...

result:

ok 300000 numbers

Test #28:

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

input:

300000 219599
1 2 21947
2 3 51985
3 4 97188
4 5 188749
5 6 194
6 7 181014
7 8 275855
8 9 196649
9 10 277992
10 11 102507
11 12 167056
12 13 215380
13 14 8307
14 15 125968
15 16 223566
16 17 200867
17 18 251022
18 19 149837
19 20 125366
20 21 220400
21 22 138597
22 23 122095
23 24 113848
24 25 134999...

output:

0
21947
73932
171120
359869
360063
541077
816932
1013581
1291573
1394080
1561136
1776516
1784823
1910791
2134357
2335224
2586246
2736083
2861449
3081849
3220446
3342541
3456389
3591388
3673961
3855403
4019571
4031789
4204582
4258978
4503328
4674974
4948484
5086998
5318637
5555225
5729225
5931850
600...

result:

ok 300000 numbers

Test #29:

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

input:

300000 70319
1 2 146600
2 3 189434
3 4 26666
4 5 138002
5 6 178971
6 7 277190
7 8 292547
8 9 30804
9 10 14879
10 11 162946
11 12 194096
12 13 191278
13 14 202037
14 15 253187
15 16 171483
16 17 272781
17 18 198580
18 19 80560
19 20 289607
20 21 16852
21 22 153671
22 23 129604
23 24 55527
24 25 48856...

output:

0
146600
336034
362700
500702
679673
956863
1249410
1280214
1295093
1458039
1652135
1843413
2045450
2298637
2470120
2742901
2941481
3022041
3311648
3328500
3482171
3611775
3667302
3716158
3941643
4117307
4406336
4432866
4605530
4803344
4957965
5247710
5364652
5405275
5674618
5845935
5950010
6072576
...

result:

ok 300000 numbers

Test #30:

score: 0
Accepted
time: 91ms
memory: 13476kb

input:

300000 250653
1 2 28649
2 3 282345
3 4 177852
4 5 1953
5 6 26007
6 7 128604
7 8 157242
8 9 139555
9 10 66659
10 11 6520
11 12 205198
12 13 191730
13 14 97914
14 15 243564
15 16 172338
16 17 71776
17 18 68843
18 19 38414
19 20 290826
20 21 275874
21 22 265865
22 23 33109
23 24 157561
24 25 187602
25 ...

output:

0
28649
310994
488846
490799
516806
645410
802652
942207
1008866
1015386
1220584
1412314
1510228
1753792
1926130
1997906
2066749
2105163
2395989
2671863
2937728
2970837
3128398
3316000
3534666
3535911
3634673
3872673
3930987
3962385
4234489
4317590
4347775
4462932
4693785
4907543
5133984
5211090
543...

result:

ok 300000 numbers

Test #31:

score: 0
Accepted
time: 81ms
memory: 12452kb

input:

300000 101373
1 2 277494
2 3 287091
3 4 240033
4 5 294310
5 6 204783
6 7 100587
7 8 173934
8 9 106415
9 10 103546
10 11 199663
11 12 232237
12 13 291821
13 14 156
14 15 238079
15 16 120256
16 17 152202
17 18 273297
18 19 136432
19 20 287771
20 21 72326
21 22 113642
22 23 216426
23 24 231944
24 25 23...

output:

0
277494
564585
804618
1098928
1303711
1404298
1578232
1684647
1788193
1987856
2220093
2511914
2512070
2750149
2870405
3022607
3295904
3432336
3720107
3792433
3906075
4122501
4354445
4588608
4817482
4980244
5195354
5323474
5557467
5775388
5957762
5983154
6156771
6174037
6266786
6415274
6439086
66034...

result:

ok 300000 numbers

Test #32:

score: 0
Accepted
time: 95ms
memory: 13496kb

input:

300000 217501
1 2 226338
2 3 167644
3 4 169511
4 5 243564
5 6 75048
6 7 196762
7 8 57922
8 9 240570
9 10 175024
10 11 260103
11 12 100493
12 13 91911
13 14 193885
14 15 108402
15 16 68173
16 17 224117
17 18 53560
18 19 234450
19 20 27819
20 21 36075
21 22 137228
22 23 223935
23 24 297816
24 25 14802...

output:

0
226338
393982
563493
807057
882105
1078867
1136789
1377359
1552383
1812486
1912979
2004890
2198775
2307177
2375350
2599467
2653027
2887477
2915296
2951371
3088599
3312534
3610350
3758370
3830157
3987140
4159815
4169544
4403407
4464746
4600495
4611282
4761036
4980411
5243569
5326787
5580674
5832255...

result:

ok 300000 numbers

Test #33:

score: 0
Accepted
time: 97ms
memory: 13504kb

input:

300000 150583
1 2 176186
2 3 128873
3 4 242497
4 5 208341
5 6 218911
6 7 10600
7 8 45240
8 9 3957
9 10 76471
10 11 44432
11 12 142921
12 13 100348
13 14 277839
14 15 254979
15 16 140879
16 17 147717
17 18 110123
18 19 213394
19 20 271797
20 21 87420
21 22 175361
22 23 100039
23 24 53340
24 25 220131...

output:

0
176186
305059
547556
755897
974808
985408
1030648
1034605
1111076
1155508
1298429
1398777
1676616
1931595
2072474
2220191
2330314
2543708
2815505
2902925
3078286
3178325
3231665
3451796
3457744
3737613
3834853
4103190
4393680
4577426
4760805
5016210
5086817
5143261
5231462
5272702
5517278
5616351
...

result:

ok 300000 numbers

Test #34:

score: 0
Accepted
time: 94ms
memory: 13552kb

input:

300000 134008
1 2 292327
2 3 9427
3 4 296167
4 5 33403
5 6 264984
6 7 106775
7 8 229228
8 9 270817
9 10 280653
10 11 272168
11 12 2665
12 13 208951
13 14 180080
14 15 125302
15 16 88796
16 17 95439
17 18 57681
18 19 144116
19 20 136037
20 21 51168
21 22 198947
22 23 107548
23 24 295019
24 25 266692
...

output:

0
292327
301754
597921
631324
896308
1003083
1232311
1503128
1783781
2055949
2058614
2267565
2447645
2572947
2661743
2757182
2814863
2958979
3095016
3146184
3345131
3452679
3747698
4014390
4206354
4347740
4402545
4561002
4718659
4921631
5015281
5088786
5302825
5518274
5609587
5718260
5892911
6079221...

result:

ok 300000 numbers

Test #35:

score: 0
Accepted
time: 89ms
memory: 12484kb

input:

300000 117432
1 2 241171
2 3 146877
3 4 225644
4 5 149953
5 6 267953
6 7 78758
7 8 113216
8 9 104972
9 10 52131
10 11 165311
11 12 29705
12 13 9041
13 14 73809
14 15 295625
15 16 160905
16 17 167354
17 18 262135
18 19 242135
19 20 8790
20 21 271813
21 22 179428
22 23 290866
23 24 193594
24 25 4741
2...

output:

0
241171
388048
613692
763645
1031598
1110356
1223572
1328544
1380675
1545986
1575691
1584732
1658541
1954166
2115071
2282425
2544560
2786695
2795485
3067298
3246726
3537592
3731186
3735927
3770803
3906410
3910268
4083037
4116372
4338570
4509786
4692878
4883054
5000611
5086524
5297223
5401949
567549...

result:

ok 300000 numbers

Test #36:

score: 0
Accepted
time: 89ms
memory: 13552kb

input:

300000 142243
1 2 117798
2 3 53723
3 4 10656
4 5 143613
5 6 187222
6 7 286260
7 8 166119
8 9 199253
9 10 152459
10 11 140403
11 12 7759
12 13 128887
13 14 130180
14 15 150095
15 16 169619
16 17 184710
17 18 37620
18 19 84758
19 20 286815
20 21 227674
21 22 3075
22 23 128968
23 24 209078
24 25 294045...

output:

0
117798
171521
182177
325790
513012
799272
965391
1164644
1317103
1457506
1465265
1594152
1724332
1874427
2044046
2228756
2266376
2351134
2637949
2865623
2868698
2997666
3206744
3500789
3711170
3858075
4117960
4382645
4600822
4604137
4715926
5012148
5076407
5293001
5388381
5452946
5486620
5665026
5...

result:

ok 300000 numbers

Test #37:

score: 0
Accepted
time: 83ms
memory: 16336kb

input:

300000 292963
1 2 66642
2 3 58469
3 4 197029
4 5 225571
5 6 65999
6 7 215140
7 8 182811
8 9 33408
9 10 56641
10 11 68138
11 12 34799
12 13 61681
13 14 199717
14 15 277314
15 16 250240
16 17 256625
17 18 242074
18 19 182776
19 20 26864
20 21 24127
21 22 159365
22 23 3773
23 24 283461
24 25 207902
25 ...

output:

0
66642
125111
322140
547711
613710
828850
1011661
1045069
1101710
1169848
1204647
1266328
1466045
1743359
1993599
2250224
2492298
2675074
2701938
2726065
2885430
2889203
3172664
3380566
3601155
3742281
3959731
3981833
4199880
4222421
4244480
4482993
4523388
4766282
5032070
5331365
5462410
5728053
5...

result:

ok 300000 numbers

Test #38:

score: 0
Accepted
time: 97ms
memory: 12472kb

input:

300000 109091
1 2 182782
2 3 71726
3 4 126507
4 5 50633
5 6 112072
6 7 187123
7 8 66799
8 9 167563
9 10 260824
10 11 261282
11 12 70351
12 13 161771
13 14 226150
14 15 14933
15 16 22349
16 17 204347
17 18 189632
18 19 246202
19 20 23809
20 21 287875
21 22 7142
22 23 11282
23 24 49332
24 25 254463
25...

output:

0
182782
254508
381015
431648
543720
730843
797642
965205
1226029
1487311
1557662
1719433
1945583
1960516
1982865
2187212
2376844
2623046
2646855
2934730
2941872
2953154
3002486
3256949
3363554
3498901
3708507
3877625
4095542
4137309
4378151
4426251
4610078
4887785
5148174
5382198
5443318
5496199
57...

result:

ok 300000 numbers

Test #39:

score: 0
Accepted
time: 78ms
memory: 13512kb

input:

300000 222212
1 2 177178
1 3 106146
2 4 229201
2 5 43366
3 6 276576
3 7 35634
4 8 86854
4 9 172006
5 10 230025
5 11 19836
6 12 207893
6 13 234133
7 14 280581
7 15 194068
8 16 12480
8 17 1450
9 18 120966
9 19 109906
10 20 227852
10 21 148862
11 22 13413
11 23 254483
12 24 75042
12 25 99472
13 26 1425...

output:

0
177178
283324
512525
555891
832467
868101
954955
1126961
1356986
1376822
1584715
1818848
2099429
2293497
2305977
2307427
2428393
2538299
2766151
2915013
2928426
3182909
3257951
3357423
3500010
3521792
3553039
3600082
3693147
3953338
4239902
4456473
4601321
4793856
4876438
5119866
5281236
5394590
5...

result:

ok 300000 numbers

Test #40:

score: 0
Accepted
time: 94ms
memory: 12112kb

input:

300000 38340
1 2 126022
1 3 243596
2 4 291383
2 5 159916
3 6 22648
3 7 140322
4 8 270842
4 9 138865
5 10 1503
5 11 80276
6 12 234933
6 13 210031
7 14 7014
7 15 64391
8 16 260397
8 17 73364
9 18 201228
9 19 40628
10 20 224797
10 21 112611
11 22 36998
11 23 129288
12 24 149425
12 25 13329
13 26 152795...

output:

0
126022
369618
661001
820917
843565
983887
1254729
1393594
1395097
1475373
1710306
1920337
1927351
1991742
2252139
2325503
2526731
2567359
2792156
2904767
2941765
3071053
3220478
3233807
3386602
3402605
3558713
3795876
3888811
4035524
4275462
4301620
4589901
4808737
5018623
5196781
5245121
5278416
...

result:

ok 300000 numbers

Test #41:

score: 0
Accepted
time: 89ms
memory: 12020kb

input:

300000 21764
1 2 74867
1 3 124150
2 4 45052
2 5 284977
3 6 25617
3 7 236497
4 8 154830
4 9 273021
5 10 38389
5 11 273419
6 12 270485
6 13 142825
7 14 76551
7 15 226202
8 16 32506
8 17 21087
9 18 140275
9 19 271351
10 20 89038
10 21 76359
11 22 184776
11 23 136797
12 24 91104
12 25 184082
13 26 16300...

output:

0
74867
199017
244069
529046
554663
791160
945990
1219011
1257400
1530819
1801304
1944129
2020680
2246882
2279388
2300475
2440750
2712101
2801139
2877498
3062274
3199071
3290175
3474257
3637260
3780188
4061157
4312633
4572734
4862865
5013074
5114227
5378644
5499589
5747179
5992770
6271185
6391718
64...

result:

ok 300000 numbers

Test #42:

score: 0
Accepted
time: 60ms
memory: 11792kb

input:

300000 2
1 2 2
2 3 3
3 4 4
4 5 5
5 6 6
6 7 7
7 8 8
8 9 9
9 10 10
10 11 11
11 12 12
12 13 13
13 14 14
14 15 15
15 16 16
16 17 17
17 18 18
18 19 19
19 20 20
20 21 21
21 22 22
22 23 23
23 24 24
24 25 25
25 26 26
26 27 27
27 28 28
28 29 29
29 30 30
30 31 31
31 32 32
32 33 33
33 34 34
34 35 35
35 36 36
3...

output:

0
2
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
101
103
105
107
109
111
113
115
117
119
121
123
125
127
129
131
133
135
137
139
141
143
145
147
149
151
153
155
157
159
161
163
165
167
169
171
173
175
177...

result:

ok 300000 numbers

Test #43:

score: 0
Accepted
time: 62ms
memory: 11872kb

input:

300000 10
1 2 2
2 3 3
3 4 4
4 5 5
5 6 6
6 7 7
7 8 8
8 9 9
9 10 10
10 11 11
11 12 12
12 13 13
13 14 14
14 15 15
15 16 16
16 17 17
17 18 18
18 19 19
19 20 20
20 21 21
21 22 22
22 23 23
23 24 24
24 25 25
25 26 26
26 27 27
27 28 28
28 29 29
29 30 30
30 31 31
31 32 32
32 33 33
33 34 34
34 35 35
35 36 36
...

output:

0
2
5
9
14
20
27
35
44
54
65
75
85
95
105
115
125
135
145
155
165
175
185
195
205
215
225
235
245
255
265
275
285
295
305
315
325
335
345
355
365
375
385
395
405
415
425
435
445
455
465
475
485
495
505
515
525
535
545
555
565
575
585
595
605
615
625
635
645
655
665
675
685
695
705
715
725
735
745
75...

result:

ok 300000 numbers

Test #44:

score: 0
Accepted
time: 61ms
memory: 11872kb

input:

300000 4
1 2 2
2 3 3
3 4 4
4 5 5
5 6 6
6 7 7
7 8 8
8 9 9
9 10 10
10 11 11
11 12 12
12 13 13
13 14 14
14 15 15
15 16 16
16 17 17
17 18 18
18 19 19
19 20 20
20 21 21
21 22 22
22 23 23
23 24 24
24 25 25
25 26 26
26 27 27
27 28 28
28 29 29
29 30 30
30 31 31
31 32 32
32 33 33
33 34 34
34 35 35
35 36 36
3...

output:

0
2
5
9
14
18
22
26
30
34
38
42
46
50
54
58
62
66
70
74
78
82
86
90
94
98
102
106
110
114
118
122
126
130
134
138
142
146
150
154
158
162
166
170
174
178
182
186
190
194
198
202
206
210
214
218
222
226
230
234
238
242
246
250
254
258
262
266
270
274
278
282
286
290
294
298
302
306
310
314
318
322
32...

result:

ok 300000 numbers

Test #45:

score: 0
Accepted
time: 55ms
memory: 13472kb

input:

300000 222212
1 2 177178
2 3 177178
3 4 177178
4 5 177178
5 6 177178
6 7 177178
7 8 177178
8 9 177178
9 10 177178
10 11 177178
11 12 177178
12 13 177178
13 14 177178
14 15 177178
15 16 177178
16 17 177178
17 18 177178
18 19 177178
19 20 177178
20 21 177178
21 22 177178
22 23 177178
23 24 177178
24 2...

output:

0
177178
354356
531534
708712
885890
1063068
1240246
1417424
1594602
1771780
1948958
2126136
2303314
2480492
2657670
2834848
3012026
3189204
3366382
3543560
3720738
3897916
4075094
4252272
4429450
4606628
4783806
4960984
5138162
5315340
5492518
5669696
5846874
6024052
6201230
6378408
6555586
6732764...

result:

ok 300000 numbers

Test #46:

score: 0
Accepted
time: 66ms
memory: 12144kb

input:

300000 38340
1 2 126022
2 3 126022
3 4 126022
4 5 126022
5 6 126022
6 7 126022
7 8 126022
8 9 126022
9 10 126022
10 11 126022
11 12 126022
12 13 126022
13 14 126022
14 15 126022
15 16 126022
16 17 126022
17 18 126022
18 19 126022
19 20 126022
20 21 126022
21 22 126022
22 23 126022
23 24 126022
24 25...

output:

0
126022
252044
378066
504088
630110
756132
882154
1008176
1134198
1260220
1386242
1512264
1638286
1764308
1890330
2016352
2142374
2268396
2394418
2520440
2646462
2772484
2898506
3024528
3150550
3276572
3402594
3528616
3654638
3780660
3906682
4032704
4158726
4284748
4410770
4536792
4662814
4788836
4...

result:

ok 300000 numbers

Test #47:

score: 0
Accepted
time: 61ms
memory: 12012kb

input:

300000 21764
1 2 74867
2 3 74867
3 4 74867
4 5 74867
5 6 74867
6 7 74867
7 8 74867
8 9 74867
9 10 74867
10 11 74867
11 12 74867
12 13 74867
13 14 74867
14 15 74867
15 16 74867
16 17 74867
17 18 74867
18 19 74867
19 20 74867
20 21 74867
21 22 74867
22 23 74867
23 24 74867
24 25 74867
25 26 74867
26 2...

output:

0
74867
149734
224601
299468
374335
449202
524069
598936
673803
748670
823537
898404
973271
1048138
1123005
1197872
1272739
1347606
1422473
1497340
1572207
1647074
1721941
1796808
1871675
1946542
2021409
2096276
2171143
2246010
2320877
2395744
2470611
2545478
2620345
2695212
2770079
2844946
2919813
...

result:

ok 300000 numbers

Test #48:

score: 0
Accepted
time: 93ms
memory: 13492kb

input:

300000 222212
156310 45213 119474
45213 173895 296639
173895 165667 258230
165667 122795 208246
122795 97302 194651
97302 266636 226961
266636 273533 184540
273533 194165 289355
194165 198054 194977
198054 189331 122952
189331 69613 74498
69613 117058 158804
117058 299497 251017
299497 148591 78476
...

output:

0
300000
599971
899965
1199963
1499960
1799911
2099907
2399865
2699860
2999763
3299733
3598451
3898398
4198390
4498359
4794993
5094612
5394598
5694587
5994525
6294373
6594252
6894243
7193821
7493770
7793726
8093694
8393666
8693602
8993573
9293403
9593395
9893346
10193247
10493237
10793115
11092518
1...

result:

ok 300000 numbers

Test #49:

score: 0
Accepted
time: 94ms
memory: 12108kb

input:

300000 38340
201098 90816 236777
90816 206580 168298
206580 78403 239110
78403 184630 114275
184630 274275 285141
274275 192465 110572
192465 202916 283379
202916 117453 18387
117453 148410 2520
148410 267164 147228
267164 73727 213684
73727 139707 45517
139707 127690 276730
127690 174582 23814
1745...

output:

0
299999
599999
899989
1199989
1499775
1799771
2099759
2399751
2699729
2999572
3299523
3599464
3899425
4199403
4499374
4799319
5099247
5399240
5695272
5994502
6294474
6594434
6894419
7192804
7492741
7792697
8092632
8392622
8692111
8992049
9291982
9591930
9891918
10191910
10491878
10791860
11088731
1...

result:

ok 300000 numbers

Test #50:

score: 0
Accepted
time: 87ms
memory: 11924kb

input:

300000 21764
271043 155530 261461
155530 87600 290795
87600 277944 43322
277944 132284 169307
132284 284477 144698
284477 191765 265990
191765 175920 182089
175920 272017 219959
272017 85037 101267
85037 105042 272721
105042 123985 42280
123985 155244 98096
155244 160113 143003
160113 151169 184302
...

output:

0
300000
599924
899762
1199266
1499265
1799184
2099134
2399132
2699051
2999050
3298981
3598790
3898789
4198768
4498752
4798745
5098737
5398494
5686352
5986304
6285804
6585685
6885664
7185606
7485594
7785592
8085510
8385421
8685214
8985197
9285147
9585129
9845127
10144093
10444060
10744001
11043949
1...

result:

ok 300000 numbers

Test #51:

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

input:

300000 5188
171845 234605 59244
234605 201741 260616
201741 292711 101533
292711 71806 209885
71806 91373 68603
91373 296547 154520
296547 145742 8283
145742 52523 1917
52523 206434 156361
206434 220155 139105
220155 107782 88140
107782 137052 261488
137052 45890 119150
45890 266283 224977
266283 25...

output:

0
299999
599997
899905
1199900
1499899
1799785
2099768
2399756
2699752
2999724
3299721
3599715
3899684
4199644
4499626
4799603
5099496
5399472
5699377
5999347
6299307
6599098
6899030
7198915
7498837
7798801
8098650
8398546
8698424
8998190
9298076
9598019
9896660
10196582
10496570
10796246
11096036
1...

result:

ok 300000 numbers

Test #52:

score: 0
Accepted
time: 96ms
memory: 12568kb

input:

300000 121316
221002 200373 42370
200373 232967 85144
232967 189624 47598
189624 25117 183491
25117 64583 51589
64583 196881 109402
196881 265000 146722
265000 176529 163212
176529 278942 107515
278942 74760 166127
74760 124376 258765
124376 278104 294168
278104 237625 104760
237625 196446 206956
19...

output:

0
299990
599971
899963
1199947
1499904
1799841
2099805
2399776
2699574
2999574
3299563
3599524
3899439
4199426
4499257
4799235
5099225
5399137
5699114
5999099
6298251
6598104
6898042
7197293
7497149
7797127
8096618
8396540
8696081
8995184
9294677
9594423
9894371
10193858
10493795
10786737
11086610
1...

result:

ok 300000 numbers

Test #53:

score: 0
Accepted
time: 78ms
memory: 11880kb

input:

300000 2
156310 45213 119474
45213 173895 296639
173895 165667 258230
165667 122795 208246
122795 97302 194651
97302 266636 226961
266636 273533 184540
273533 194165 289355
194165 198054 194977
198054 189331 122952
189331 69613 74498
69613 117058 158804
117058 299497 251017
299497 148591 78476
14859...

output:

0
300000
599971
599994
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
599998
5999...

result:

ok 300000 numbers

Test #54:

score: 0
Accepted
time: 80ms
memory: 11812kb

input:

300000 10
201098 90816 236777
90816 206580 168298
206580 78403 239110
78403 184630 114275
184630 274275 285141
274275 192465 110572
192465 202916 283379
202916 117453 18387
117453 148410 2520
148410 267164 147228
267164 73727 213684
73727 139707 45517
139707 127690 276730
127690 174582 23814
174582 ...

output:

0
299999
599999
899989
1199989
1499775
1799771
2099759
2399751
2699729
2999572
2999737
2999835
2999855
2999882
2999892
2999892
2999892
2999914
2999914
2999914
2999914
2999914
2999921
2999921
2999921
2999921
2999921
2999933
2999933
2999933
2999933
2999933
2999936
2999940
2999940
2999940
2999940
29999...

result:

ok 300000 numbers

Test #55:

score: 0
Accepted
time: 81ms
memory: 11872kb

input:

300000 4
271043 155530 261461
155530 87600 290795
87600 277944 43322
277944 132284 169307
132284 284477 144698
284477 191765 265990
191765 175920 182089
175920 272017 219959
272017 85037 101267
85037 105042 272721
105042 123985 42280
123985 155244 98096
155244 160113 143003
160113 151169 184302
1511...

output:

0
300000
599924
899762
1199266
1199761
1199842
1199873
1199947
1199947
1199996
1199996
1199996
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
1199997
11999...

result:

ok 300000 numbers

Test #56:

score: 0
Accepted
time: 87ms
memory: 11884kb

input:

300000 8
171845 234605 59244
234605 201741 260616
201741 292711 101533
292711 71806 209885
71806 91373 68603
91373 296547 154520
296547 145742 8283
145742 52523 1917
52523 206434 156361
206434 220155 139105
220155 107782 88140
107782 137052 261488
137052 45890 119150
45890 266283 224977
266283 25192...

output:

0
299999
599997
899905
1199900
1499899
1799785
2099768
2399756
2399866
2399930
2399955
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
2399966
23999...

result:

ok 300000 numbers

Test #57:

score: 0
Accepted
time: 84ms
memory: 11944kb

input:

300000 6
221002 200373 42370
200373 232967 85144
232967 189624 47598
189624 25117 183491
25117 64583 51589
64583 196881 109402
196881 265000 146722
265000 176529 163212
176529 278942 107515
278942 74760 166127
74760 124376 258765
124376 278104 294168
278104 237625 104760
237625 196446 206956
196446 ...

output:

0
299990
599971
899963
1199947
1499904
1799841
1799868
1799882
1799882
1799918
1799936
1799936
1799936
1799942
1799942
1799942
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
1799948
17999...

result:

ok 300000 numbers

Test #58:

score: 0
Accepted
time: 78ms
memory: 11868kb

input:

300000 125
6558 19851 9380
19851 17495 13333
17495 8182 38553
8182 40272 39277
40272 39177 36972
39177 5010 41840
5010 23736 9721
23736 38570 44844
38570 1503 38079
1503 48018 59731
48018 58272 28033
58272 17794 14521
17794 52212 49447
52212 9684 13015
9684 49129 30811
49129 9823 28171
9823 245 2378...

output:

0
59987
119966
179964
239945
299935
359932
419800
479637
539616
599607
659534
719471
779458
839454
899449
959446
1019423
1079337
1139317
1199255
1259223
1319118
1379114
1438808
1498714
1558547
1617776
1677628
1737228
1797175
1857090
1911327
1970905
2030904
2090894
2150868
2210844
2270820
2330730
239...

result:

ok 300000 numbers

Test #59:

score: 0
Accepted
time: 70ms
memory: 11884kb

input:

300000 49
42471 34021 58795
34021 9633 35664
9633 42845 8596
42845 51048 34990
51048 54363 15824
54363 1352 6986
1352 45114 15408
45114 1134 52473
1134 38475 34858
38475 41674 15092
41674 16553 21082
16553 43059 16694
43059 27305 50204
27305 29003 6815
29003 35978 25939
35978 18389 53908
18389 9147 ...

output:

0
60000
119995
179993
239992
299366
359362
419357
479352
539328
599291
659267
719181
779113
839104
898993
958987
1018906
1077338
1137306
1197269
1257263
1317241
1377210
1437073
1497028
1556971
1616961
1676954
1736945
1796933
1856517
1916450
1975870
2034815
2094346
2153381
2213337
2273284
2333183
239...

result:

ok 300000 numbers

Test #60:

score: 0
Accepted
time: 71ms
memory: 11812kb

input:

300000 77
20329 30569 12533
30569 49683 4514
49683 44770 32929
44770 25758 39612
25758 47597 54512
47597 12202 32507
12202 35772 45459
35772 50572 40761
50572 28434 59566
28434 42082 51269
42082 29750 41209
29750 24471 4321
24471 18162 32866
18162 29368 46629
29368 13896 4585
13896 49909 28123
49909...

output:

0
59997
119996
179986
239983
299978
359969
419941
479896
539891
599770
659753
719720
779624
839584
899570
959559
1019497
1079477
1139432
1199414
1259148
1319134
1379025
1438968
1498858
1558764
1618418
1678385
1738255
1798156
1858082
1918042
1977937
2037847
2097679
2156050
2215683
2275545
2334854
239...

result:

ok 300000 numbers

Test #61:

score: 0
Accepted
time: 84ms
memory: 11892kb

input:

300000 177
24163 24683 22734
24683 25351 16575
25351 15881 21750
15881 3125 24452
3125 1158 9894
1158 24819 6841
24819 23836 11168
23836 10931 28756
10931 17258 6844
17258 24699 24799
24699 10386 4438
10386 10848 27925
10848 19011 21675
19011 5243 23816
5243 582 15648
582 8803 7278
8803 8527 10251
8...

output:

0
30000
59969
89673
119667
149667
179666
209262
239180
269171
299157
329125
359119
389040
419031
449022
478819
508734
538730
568717
597848
627530
657302
687076
716948
745842
775666
805655
835546
865541
895527
925513
955278
984949
1012631
1042611
1072530
1101922
1131756
1161543
1191265
1221186
124954...

result:

ok 300000 numbers

Test #62:

score: 0
Accepted
time: 80ms
memory: 11876kb

input:

300000 101
29663 9340 21974
9340 27562 24816
27562 11910 21697
11910 14572 16435
14572 2114 25630
2114 6353 3028
6353 10526 22078
10526 5796 11953
5796 14023 12534
14023 13077 713
13077 10068 20976
10068 23625 3423
23625 14752 19818
14752 19125 23195
19125 27638 8437
27638 10490 17128
10490 20857 28...

output:

0
29999
59996
89990
119964
149957
179945
209927
239907
269862
299057
328858
358761
388715
418713
448653
478642
508501
538493
568414
598387
628306
658284
688182
718173
748100
778026
807330
837303
867195
896621
925563
955285
985249
1015220
1043402
1073384
1103360
1133234
1162950
1192866
1222831
125278...

result:

ok 300000 numbers

Test #63:

score: 0
Accepted
time: 78ms
memory: 11868kb

input:

300000 25
16551 294 3918
294 25274 11570
25274 15379 17053
15379 13217 21121
13217 13747 28663
13747 21808 24623
21808 21801 2987
21801 29176 3662
29176 4822 9711
4822 27224 23923
27224 13354 16026
13354 6259 21625
6259 16193 13368
16193 308 18381
308 9605 18522
9605 9224 26979
9224 29978 29171
2997...

output:

0
30000
59980
89979
119979
149975
179974
209940
239927
269899
299794
329741
359550
389526
419445
449339
479318
509308
537284
567262
597209
627101
657076
687074
717024
746953
748862
749036
749083
749083
749175
749175
749278
749382
749382
749382
749382
749382
749382
749446
749446
749446
749446
749446
...

result:

ok 300000 numbers

Test #64:

score: 0
Accepted
time: 74ms
memory: 11868kb

input:

300000 58
574 2891 927
2891 2116 1838
2116 1237 151
1237 2872 2030
2872 2180 832
2180 305 1794
305 32 2532
32 1119 1614
1119 1572 1266
1572 1188 410
1188 1409 2700
1409 871 1572
871 1737 1521
1737 2376 899
2376 2993 2676
2993 126 1037
126 171 2235
171 1172 1626
1172 1988 1193
1988 627 2342
627 2832 ...

output:

0
2994
5993
8982
11972
14952
17915
20910
23890
26875
29821
32808
35789
38772
41749
44728
47665
50577
53569
56320
59299
62180
65163
67569
70543
73196
76035
79003
82002
84970
87937
90874
93767
96597
99574
102368
105068
107970
110904
113839
116821
118438
121243
124212
127051
130021
132798
135729
138708...

result:

ok 300000 numbers

Test #65:

score: 0
Accepted
time: 77ms
memory: 11900kb

input:

300000 282
1508 835 2541
835 716 1800
716 1952 2982
1952 2365 1669
2365 906 1913
906 934 483
934 2443 2653
2443 2860 1308
2860 916 1119
916 335 2321
335 2091 2266
2091 2473 1611
2473 540 1458
540 1919 570
1919 457 2072
457 1689 2666
1689 49 2449
49 1327 721
1327 2241 1455
2241 1062 2579
1062 576 286...

output:

0
2998
5949
8947
11832
14812
17810
20769
23756
26745
29739
32710
35576
38535
41534
44495
47367
50266
53235
56190
59159
62099
65090
68045
71009
73891
76845
79499
82385
85334
88205
91120
92759
95357
98342
101283
104238
107222
110189
113140
116033
118826
121784
124620
127520
130496
133328
136009
138677...

result:

ok 300000 numbers

Test #66:

score: 0
Accepted
time: 69ms
memory: 11872kb

input:

300000 206
2370 1197 450
1197 671 2250
671 1839 1405
1839 2562 2500
2562 1840 1889
1840 1989 275
1989 1591 2773
1591 1292 1002
1292 2307 1677
2307 1818 2335
1818 1032 1128
1032 2401 58
2401 2396 691
2396 1587 1434
1587 701 2572
701 1727 1295
1727 1370 1471
1370 421 2601
421 468 1717
468 272 2112
272...

output:

0
2996
5991
8991
11986
14974
17871
20862
23852
26837
29771
32750
35679
38666
41624
44618
47538
50337
52401
55332
58123
61068
64066
66838
69829
72761
75742
78717
81631
84425
87397
90222
93211
94486
97399
100378
103361
106329
109216
112193
115107
117630
120568
123456
126322
129278
132202
134373
137214...

result:

ok 300000 numbers

Test #67:

score: 0
Accepted
time: 79ms
memory: 11872kb

input:

300000 127
368 485 136
485 132 315
132 430 463
430 183 248
183 189 430
189 60 454
60 297 391
297 437 442
437 487 17
487 545 350
545 498 184
498 72 250
72 398 448
398 282 272
282 67 124
67 4 219
4 16 251
16 91 411
91 474 478
474 13 240
13 32 240
32 434 441
434 486 99
486 448 89
448 357 297
357 444 46...

output:

0
541
1056
1599
2140
2679
3046
3584
4113
4640
5184
5712
6190
6696
7224
7475
8010
8536
9065
9596
10075
10568
10743
11247
11600
12020
12500
12984
13386
13916
14431
14671
15016
15435
15962
16428
16934
17459
17941
18438
18909
19212
19687
20212
20625
20865
21396
21892
22281
22696
22906
23397
23892
24405
...

result:

ok 300000 numbers

Test #68:

score: 0
Accepted
time: 78ms
memory: 11944kb

input:

300000 155
134 389 33
389 218 511
218 53 88
53 259 35
259 393 102
393 273 65
273 331 280
331 228 42
228 351 356
351 422 540
422 311 516
311 278 377
278 515 299
515 57 335
57 472 299
472 358 66
358 423 160
423 12 502
12 14 405
14 417 342
417 107 539
107 506 168
506 453 196
453 403 351
403 437 164
437...

output:

0
543
1082
1625
2062
2598
3138
3682
4188
4618
5150
5689
6215
6620
7104
7638
8174
8709
9115
9642
9974
10324
10715
11235
11382
11844
12241
12733
13271
13784
14288
14770
15292
15766
16287
16818
17271
17799
18321
18770
18803
18960
19242
19757
20279
20530
21060
21541
22020
22499
23034
23487
24027
24533
2...

result:

ok 300000 numbers

Test #69:

score: 0
Accepted
time: 71ms
memory: 11860kb

input:

300000 79
145 522 508
522 106 162
106 230 225
230 221 402
221 108 284
108 3 288
3 231 202
231 52 221
52 156 150
156 26 151
26 18 235
18 360 504
360 96 251
96 61 365
61 49 475
49 488 425
488 377 34
377 284 116
284 40 332
40 170 444
170 433 294
433 204 506
204 157 259
157 180 35
180 323 31
323 197 209...

output:

0
545
1051
1438
1954
2492
3032
3560
4096
4592
5126
5666
6210
6729
7242
7653
8198
8433
8966
9485
9708
10058
10600
11039
11450
11671
12197
12601
13090
13600
13771
13813
14337
14873
15353
15866
16071
16614
17082
17586
18093
18556
19025
19432
19796
20220
20459
20846
21271
21619
22095
22246
22748
23169
2...

result:

ok 300000 numbers

Test #70:

score: 0
Accepted
time: 61ms
memory: 11812kb

input:

300000 225
106 3 65
3 97 7
97 100 104
100 54 12
54 89 66
89 149 137
149 42 106
42 147 132
147 148 41
148 15 104
15 146 107
146 128 82
128 49 21
49 131 46
131 141 21
141 7 148
7 70 102
70 102 146
102 31 15
31 85 86
85 112 83
112 96 69
96 110 77
110 75 137
75 30 5
30 63 83
63 79 49
79 74 73
74 135 122...

output:

0
143
293
397
536
634
782
925
984
1119
1233
1379
1393
1528
1665
1804
1898
1971
2106
2115
2244
2319
2426
2439
2545
2585
2697
2774
2915
3037
3174
3197
3339
3354
3426
3572
3712
3852
3938
3970
4074
4206
4327
4431
4472
4520
4643
4792
4899
5041
5106
5234
5354
5458
5566
5614
5713
5815
5846
5968
6028
6031
6...

result:

ok 300000 numbers

Test #71:

score: 0
Accepted
time: 83ms
memory: 11892kb

input:

300000 253
112 127 88
127 123 59
123 12 95
12 106 106
106 125 99
125 124 117
124 47 50
47 5 12
5 86 78
86 50 113
50 9 41
9 142 116
142 61 11
61 37 131
37 96 85
96 19 138
19 82 112
82 85 22
85 14 89
14 83 43
83 24 82
24 77 42
77 49 105
49 111 14
111 148 85
148 110 125
110 57 28
57 52 82
52 16 129
16 ...

output:

0
149
296
431
569
717
866
960
1073
1200
1313
1430
1568
1703
1851
1980
2120
2194
2306
2441
2587
2715
2851
2933
3056
3177
3269
3331
3412
3417
3520
3641
3754
3892
4018
4101
4232
4376
4436
4463
4572
4646
4710
4842
4897
4904
4916
4990
5095
5136
5253
5378
5468
5551
5641
5678
5760
5885
5920
5995
6111
6220
...

result:

ok 300000 numbers

Test #72:

score: 0
Accepted
time: 84ms
memory: 11888kb

input:

300000 177
25 17 26
17 33 57
33 42 40
42 89 49
89 64 78
64 54 88
54 38 1
38 123 97
123 30 76
30 150 121
150 87 117
87 145 83
145 19 2
19 53 13
53 98 91
98 59 74
59 88 72
88 109 144
109 92 6
92 9 104
9 61 35
61 56 23
56 127 29
127 26 33
26 36 54
36 62 72
62 21 46
21 100 46
100 50 91
50 35 65
35 10 34...

output:

0
145
290
427
574
678
776
922
1072
1163
1313
1382
1526
1666
1740
1884
2028
2173
2294
2383
2455
2593
2686
2815
2841
2876
3024
3142
3193
3290
3401
3545
3602
3613
3647
3701
3795
3883
3989
4103
4236
4276
4422
4444
4529
4559
4591
4617
4701
4766
4856
4974
4987
4988
5103
5136
5217
5256
5347
5365
5388
5434
...

result:

ok 300000 numbers

Test #73:

score: 0
Accepted
time: 78ms
memory: 11816kb

input:

300000 286
31 53 52
53 21 31
21 4 7
4 30 36
30 50 41
50 35 58
35 54 54
54 22 15
22 45 28
45 33 9
33 7 25
7 32 23
32 10 30
10 24 30
24 55 35
55 2 53
2 38 36
38 34 46
34 9 17
9 49 30
49 19 7
19 43 5
43 1 22
1 37 11
37 27 29
27 3 24
3 52 56
52 18 25
18 20 57
20 57 16
57 60 55
60 47 12
47 8 34
8 25 19
2...

output:

0
46
75
133
190
245
298
354
384
414
468
523
575
613
635
681
699
755
777
832
839
867
897
927
946
977
1001
1028
1029
1065
1117
1140
1165
1182
1236
1247
1258
1294
1321
1376
1418
1464
1469
1482
1491
1512
1546
1568
1575
1616
1617
1642
1673
1688
1723
1770
1786
1825
1873
1885
2002
2120
2236
2325
2441
2549
...

result:

ok 300000 numbers

Test #74:

score: 0
Accepted
time: 81ms
memory: 11872kb

input:

300000 210
16 51 13
51 12 18
12 7 40
7 52 31
52 38 43
38 2 41
2 59 10
59 27 26
27 25 10
25 9 28
9 39 27
39 11 12
11 6 4
6 34 50
34 1 10
1 55 30
55 58 37
58 60 38
60 57 31
57 41 22
41 29 18
29 28 18
28 31 2
31 50 51
50 37 13
37 21 7
21 44 10
44 56 60
56 8 3
8 49 37
49 5 58
5 53 29
53 42 59
42 17 38
1...

output:

0
50
110
164
223
251
294
352
379
432
436
476
535
594
604
622
661
710
736
746
797
814
835
836
862
863
873
911
929
945
947
1006
1030
1040
1086
1108
1115
1156
1168
1187
1205
1243
1255
1265
1277
1289
1292
1305
1342
1355
1368
1399
1428
1467
1497
1500
1522
1559
1569
1600
1720
1836
1955
2062
2182
2288
2407...

result:

ok 300000 numbers

Test #75:

score: 0
Accepted
time: 78ms
memory: 11836kb

input:

300000 134
14 26 27
26 12 41
12 55 57
55 37 19
37 40 37
40 10 48
10 22 45
22 51 37
51 41 1
41 54 3
54 29 46
29 33 21
33 48 46
48 39 1
39 16 21
16 38 7
38 7 14
7 34 14
34 17 8
17 5 29
5 2 29
2 11 3
11 57 19
57 1 24
1 30 50
30 47 33
47 19 7
19 59 35
59 3 16
3 43 57
43 56 1
56 53 30
53 52 57
52 8 56
8 ...

output:

0
24
74
131
160
214
243
297
348
394
397
454
492
533
553
567
581
590
625
670
678
723
762
801
835
862
900
911
957
990
1007
1009
1030
1038
1054
1088
1136
1143
1164
1201
1238
1248
1305
1329
1359
1371
1378
1379
1392
1403
1404
1460
1490
1493
1512
1513
1532
1537
1553
1567
1687
1806
1902
2020
2133
2246
2340...

result:

ok 300000 numbers

Test #76:

score: 0
Accepted
time: 74ms
memory: 11868kb

input:

300000 153
21 14 2
14 24 3
24 5 2
5 4 6
4 18 24
18 23 24
23 28 14
28 1 28
1 25 12
25 27 6
27 16 27
16 26 25
26 6 29
6 22 16
22 11 12
11 30 15
30 13 11
13 29 23
29 15 22
15 10 29
10 19 27
19 2 28
2 3 12
3 20 11
20 9 7
9 7 18
7 17 13
17 8 6
8 12 24
12 41 42
41 50 36
50 47 50
47 42 47
42 32 37
32 39 45...

output:

0
29
41
69
75
104
122
135
146
174
190
214
229
232
255
282
288
312
339
346
348
360
384
386
398
423
429
443
465
476
532
582
642
693
750
801
851
897
942
975
1017
1054
1090
1137
1169
1219
1266
1312
1365
1401
1458
1490
1524
1555
1595
1631
1675
1715
1750
1792
1882
1970
2035
2107
2193
2281
2354
2424
2501
2...

result:

ok 300000 numbers

Test #77:

score: 0
Accepted
time: 66ms
memory: 11940kb

input:

300000 273
7 28 8
28 23 17
23 18 8
18 21 20
21 26 21
26 9 19
9 12 1
12 10 27
10 11 29
11 16 24
16 25 2
25 2 25
2 4 29
4 1 19
1 14 26
14 29 10
29 17 28
17 15 4
15 13 27
13 27 23
27 5 11
5 22 12
22 6 16
6 19 7
19 8 26
8 24 27
24 30 4
30 20 3
20 3 30
3 45 42
45 32 54
32 38 38
38 43 34
43 49 54
49 55 31...

output:

0
29
59
78
106
122
151
177
198
225
250
251
274
300
327
351
355
372
379
406
426
438
446
450
452
471
482
490
500
503
560
614
668
708
747
782
813
851
887
947
985
1042
1076
1126
1168
1202
1257
1294
1337
1371
1427
1460
1494
1549
1580
1613
1654
1693
1726
1777
1867
1955
2044
2117
2204
2278
2365
2452
2534
2...

result:

ok 300000 numbers

Test #78:

score: 0
Accepted
time: 66ms
memory: 11820kb

input:

300000 1
12 26 27
26 18 1
18 27 28
27 2 5
2 29 13
29 15 1
15 17 11
17 30 23
30 16 27
16 21 13
21 19 29
19 28 2
28 22 20
22 24 5
24 23 2
23 7 29
7 13 29
13 11 23
11 1 24
1 5 8
5 3 19
3 10 11
10 4 17
4 8 12
8 6 9
6 20 6
20 25 2
25 14 16
14 9 16
9 41 55
41 48 33
48 56 39
56 53 43
53 57 32
57 37 55
37 4...

output:

0
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
29
55
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
57
85
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
90
120
120
120
120
120
120
120
120...

result:

ok 300000 numbers

Test #79:

score: 0
Accepted
time: 67ms
memory: 11888kb

input:

300000 44
4 2 5
2 1 3
1 3 5
3 5 3
5 9 8
9 10 9
10 6 10
6 8 6
8 7 6
7 14 11
14 11 13
11 12 15
12 15 13
15 13 11
13 20 18
20 18 18
18 17 20
17 16 20
16 19 17
19 23 23
23 24 22
24 25 23
25 22 23
22 21 24
21 28 29
28 26 28
26 27 29
27 29 29
29 30 30
30 33 35
33 32 32
32 35 35
35 34 31
34 31 34
31 37 36
...

output:

0
3
8
13
16
26
32
38
46
55
68
83
96
107
118
138
158
176
193
211
235
258
281
303
326
355
384
412
441
471
506
541
573
607
638
676
712
749
786
826
871
915
956
998
1040
1087
1131
1173
1216
1257
1304
1351
1393
1435
1476
1525
1572
1617
1658
1697
1744
1791
1835
1876
1918
1965
2009
2055
2097
2135
2181
2225
...

result:

ok 300000 numbers

Test #80:

score: 0
Accepted
time: 68ms
memory: 11876kb

input:

300000 164
1 2 4
2 5 2
5 3 4
3 4 5
4 6 10
6 8 6
8 10 8
10 9 7
9 7 7
7 14 14
14 11 14
11 15 11
15 12 11
12 13 12
13 20 18
20 16 20
16 18 16
18 17 20
17 19 20
19 24 22
24 23 25
23 22 22
22 25 21
25 21 25
21 30 28
30 27 29
27 29 29
29 28 29
28 26 30
26 31 32
31 32 33
32 34 33
34 35 34
35 33 34
33 40 39...

output:

0
4
8
13
15
25
33
39
46
53
67
78
90
104
115
135
155
171
191
209
234
259
281
303
324
354
383
412
441
469
501
534
568
601
635
674
710
749
785
823
867
909
950
993
1037
1087
1134
1183
1231
1278
1333
1387
1442
1493
1545
1604
1662
1718
1774
1831
1894
1956
2017
2079
2140
2209
2277
2346
2412
2480
2555
2629
...

result:

ok 300000 numbers

Test #81:

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

input:

300000 192
2 5 1
5 3 5
3 4 1
4 1 1
1 6 8
6 8 8
8 7 7
7 10 6
10 9 6
9 15 13
15 13 13
13 12 12
12 11 11
11 14 14
14 19 17
19 17 16
17 18 20
18 20 19
20 16 19
16 24 23
24 22 21
22 21 21
21 23 21
23 25 21
25 29 26
29 28 27
28 30 30
30 26 30
26 27 29
27 33 34
33 32 32
32 34 35
34 35 34
35 31 32
31 36 36
...

output:

0
5
6
7
8
16
24
31
37
43
56
67
79
93
106
126
143
162
178
197
220
241
262
283
304
334
363
390
416
446
481
515
547
581
613
649
689
725
761
801
846
891
932
976
1017
1066
1114
1160
1207
1255
1310
1365
1419
1473
1524
1583
1640
1698
1756
1813
1876
1940
2002
2065
2127
2197
2264
2334
2401
2468
2541
2612
268...

result:

ok 300000 numbers

Test #82:

score: 0
Accepted
time: 76ms
memory: 11880kb

input:

300000 283
2 3 2
3 1 3
1 6 6
6 5 4
5 4 4
4 8 9
8 7 9
7 9 7
9 10 11
10 12 12
12 11 11
11 14 14
14 15 14
15 13 15
13 16 16
16 17 16
17 18 18
18 21 20
21 19 20
19 20 21
20 23 23
23 22 22
22 24 22
24 25 27
25 27 27
27 26 26
26 28 28
28 29 28
29 30 29
30 33 32
33 32 32
32 31 31
31 34 35
34 36 34
36 35 35...

output:

0
3
5
11
15
19
28
37
44
55
67
78
93
107
121
137
153
171
191
212
232
255
277
299
326
353
379
407
435
464
496
527
559
594
629
663
700
737
774
816
857
897
941
984
1027
1075
1121
1169
1218
1268
1317
1370
1423
1476
1532
1587
1642
1702
1762
1820
1881
1944
2006
2070
2134
2198
2267
2335
2404
2475
2547
2619
...

result:

ok 300000 numbers

Test #83:

score: 0
Accepted
time: 77ms
memory: 11816kb

input:

300000 208
2 3 1
3 1 1
1 6 4
6 4 6
4 5 4
5 7 7
7 8 9
8 9 8
9 10 11
10 11 11
11 12 12
12 13 15
13 14 13
14 15 14
15 17 17
17 18 18
18 16 17
16 19 20
19 21 20
21 20 20
20 22 24
22 24 24
24 23 23
23 25 26
25 26 25
26 27 27
27 30 30
30 29 28
29 28 30
28 31 32
31 32 31
32 33 32
33 35 34
35 36 34
36 34 35...

output:

0
1
2
8
12
16
23
32
40
51
62
74
89
102
116
134
151
168
188
208
228
252
276
299
325
350
377
407
437
465
497
528
560
595
629
663
702
739
778
820
862
902
945
990
1034
1082
1130
1178
1229
1278
1328
1380
1434
1487
1542
1599
1655
1713
1773
1832
1894
1956
2018
2084
2148
2214
2282
2350
2417
2489
2560
2630
2...

result:

ok 300000 numbers

Test #84:

score: 0
Accepted
time: 69ms
memory: 11864kb

input:

300000 132
3 1 3
1 2 1
2 4 5
4 6 6
6 5 5
5 9 8
9 7 8
7 8 8
8 11 10
11 10 10
10 12 10
12 14 14
14 15 15
15 13 14
13 17 17
17 16 17
16 18 17
18 19 20
19 20 19
20 21 21
21 24 24
24 23 23
23 22 22
22 27 25
27 25 25
25 26 27
26 30 28
30 29 29
29 28 28
28 32 31
32 33 33
33 31 31
31 35 36
35 36 36
36 34 36...

output:

0
1
4
9
15
20
28
36
44
54
64
74
89
103
117
134
151
168
188
207
228
252
274
297
322
349
374
403
431
459
492
523
554
590
626
662
701
738
777
819
859
899
944
988
1031
1078
1125
1171
1222
1273
1324
1378
1432
1484
1541
1598
1654
1714
1774
1833
1895
1956
2018
2084
2149
2214
2283
2350
2417
2489
2559
2630
2...

result:

ok 300000 numbers

Test #85:

score: 0
Accepted
time: 112ms
memory: 12480kb

input:

299999 70163
1 2 217862
1 3 133266
2 4 296183
2 5 16542
4 6 210871
4 7 297265
6 8 126494
6 9 161896
8 10 19371
8 11 31550
10 12 162216
10 13 106812
12 14 283210
12 15 167224
14 16 272638
14 17 139956
16 18 132047
16 19 65038
18 20 225349
18 21 267549
20 22 89098
20 23 298144
22 24 193511
22 25 12768...

output:

0
217862
351128
647311
663853
874724
1171989
1298483
1460379
1479750
1511300
1673516
1780328
2063538
2230762
2503400
2643356
2775403
2840441
3065790
3333339
3422437
3720581
3914092
3926860
4154983
4194352
4359664
4377886
4433455
4567691
4751446
4754326
5050888
5069573
5168559
5311292
5533733
5727849...

result:

ok 299999 numbers

Test #86:

score: 0
Accepted
time: 95ms
memory: 13532kb

input:

299999 206694
1 2 157571
1 3 146020
2 4 173124
2 5 22375
4 6 210198
4 7 13828
6 8 177549
6 9 245111
8 10 156595
8 11 15486
10 12 199737
10 13 271802
12 14 114829
12 15 249894
14 16 104013
14 17 294448
16 18 127808
16 19 3941
18 20 207172
18 21 275879
20 22 241826
20 23 166627
22 24 195674
22 25 2116...

output:

0
157571
303591
476715
499090
709288
723116
900665
1145776
1302371
1317857
1517594
1789396
1904225
2154119
2258132
2552580
2680388
2684329
2891501
3167380
3409206
3575833
3771507
3983167
4271344
4456052
4713500
4944278
5051778
5268852
5444297
5674595
5848649
5891645
5967458
6232331
6526950
6739732
6...

result:

ok 299999 numbers

Test #87:

score: 0
Accepted
time: 97ms
memory: 13516kb

input:

299999 161613
1 2 183035
1 3 181306
2 4 72597
2 5 242451
4 6 295282
4 7 7858
6 8 14361
6 9 28328
8 10 175433
8 11 117808
10 12 33115
10 13 136792
12 14 150591
12 15 181546
14 16 53775
14 17 181571
16 18 90938
16 19 61231
18 20 125770
18 21 198452
20 22 190411
20 23 153496
22 24 230468
22 25 292165
2...

output:

0
183035
364341
436938
679389
974671
982529
996890
1025218
1200651
1318459
1351574
1488366
1638957
1820503
1874278
2055849
2146787
2208018
2333788
2532240
2722651
2876147
3106615
3398780
3414380
3444428
3698156
3808861
3968291
4086592
4276258
4338119
4571278
4724341
4872837
5045607
5112405
5247996
5...

result:

ok 299999 numbers

Test #88:

score: 0
Accepted
time: 95ms
memory: 13552kb

input:

300000 222212
299999 119474 38031
299988 296639 49307
299985 258230 97268
299984 208246 184168
299983 194651 175269
299982 226961 160146
299981 184540 166641
299976 289355 224687
299974 194977 47407
299965 122952 203159
299964 74498 77635
299962 158804 52938
299961 251017 119583
299959 78476 252561
...

output:

0
299795
599389
897194
1197067
1493127
1791724
2090309
2389088
2687911
2986927
3286406
3586377
3884295
4170247
4468421
4766878
5063328
5349126
5647775
5947201
6241530
6539695
6835882
7127098
7421133
7718884
8013315
8311459
8600898
8898717
9197652
9493190
9775959
10075688
10365071
10659227
10958595
1...

result:

ok 300000 numbers

Test #89:

score: 0
Accepted
time: 93ms
memory: 12108kb

input:

300000 38340
299998 236777 158605
299997 168298 119537
299995 239110 194678
299994 114275 2149
299987 285141 250628
299986 110572 29750
299984 283379 118068
299983 18387 179043
299977 2520 77549
299975 147228 258504
299973 213684 285748
299970 45517 146578
299969 276730 26021
299967 23814 46582
2999...

output:

0
299661
598965
898825
1198656
1498550
1795275
2093051
2390880
2690799
2990243
3289783
3588098
3887694
4185511
4483305
4780267
5078987
5372384
5671137
5968340
6267650
6565056
6861915
7159934
7459421
7751457
8050425
8349522
8639150
8937640
9237403
9532750
9828634
10128088
10427294
10726686
11021542
1...

result:

ok 300000 numbers

Test #90:

score: 0
Accepted
time: 94ms
memory: 12016kb

input:

300000 21764
299997 261461 72484
299996 290795 270245
299995 43322 173815
299994 169307 60155
299991 144698 11450
299990 265990 143382
299989 182089 208834
299987 219959 139373
299986 101267 227070
299985 272721 40869
299980 42280 134073
299977 98096 104094
299976 143003 282235
299975 184302 5904
29...

output:

0
299958
597226
896966
1195600
1489388
1784418
2084134
2383921
2683272
2968755
3265754
3565380
3865096
4164568
4455753
4755566
5053840
5352960
5652240
5951529
6248654
6545173
6841157
7140214
7436088
7734404
8034341
8333675
8626197
8925735
9225272
9521649
9814715
10111338
10407040
10706378
11005180
1...

result:

ok 300000 numbers

Test #91:

score: 0
Accepted
time: 90ms
memory: 11996kb

input:

300000 5188
300000 59244 98193
299993 260616 59216
299992 101533 88200
299991 209885 281530
299990 68603 240288
299989 154520 48093
299986 8283 171283
299985 1917 15689
299984 156361 108753
299981 139105 209376
299980 88140 219490
299978 261488 121553
299974 119150 239915
299966 224977 141798
299963...

output:

0
299818
599112
895897
1195160
1494156
1793831
2091494
2390435
2689682
2988518
3287239
3584823
3882175
4180623
4480168
4778483
5075934
5372095
5672011
5971990
6265063
6561455
6856544
7156009
7455772
7754294
8053487
8350375
8650045
8943307
9240736
9535801
9832136
10123805
10421599
10677003
10972306
1...

result:

ok 300000 numbers

Test #92:

score: 0
Accepted
time: 90ms
memory: 12496kb

input:

300000 121316
299999 42370 105832
299998 85144 206281
299997 47598 290797
299995 183491 255766
299994 51589 278702
299993 109402 269151
299991 146722 226159
299986 163212 217033
299983 107515 107195
299980 166127 143023
299979 258765 86255
299975 294168 35314
299974 104760 178201
299973 206956 14402...

output:

0
298338
595920
895477
1194959
1493903
1792469
2091491
2389073
2689012
2987522
3286804
3584417
3884048
4180924
4480054
4779362
5075776
5372109
5669030
5963529
6243359
6536367
6833008
7129796
7426781
7717900
8016601
8312098
8608722
8908091
9206241
9504495
9797523
10097101
10388964
10676505
10975922
1...

result:

ok 300000 numbers

Test #93:

score: 0
Accepted
time: 98ms
memory: 12512kb

input:

300000 104740
299987 246471 190864
299986 285716 293108
299984 190160 116597
299979 194777 298213
299973 45540 138605
299972 263460 200614
299969 42056 136750
299965 114697 275563
299961 161361 43210
299960 284604 289906
299959 31194 213090
299958 5448 81980
299956 64017 256317
299954 166622 199550
...

output:

0
299963
599349
899243
1198543
1497443
1787985
2087918
2386482
2685644
2984771
3283562
3582488
3881486
4179888
4478037
4759876
5058194
5357385
5654230
5953431
6243689
6541493
6841234
7139226
7435319
7733638
8032823
8332314
8631595
8928593
9215178
9514473
9809926
10107983
10397650
10694847
10982000
1...

result:

ok 300000 numbers

Test #94:

score: 0
Accepted
time: 100ms
memory: 13616kb

input:

300000 220868
299999 106196 82944
299998 57281 266455
299995 256176 181312
299992 268126 284969
299991 125141 22541
299988 63501 167034
299986 133518 3229
299985 137696 225398
299984 49111 164199
299983 5166 244411
299982 102486 145333
299973 220391 291660
299971 127564 258488
299968 217832 70308
29...

output:

0
298020
596999
894644
1193222
1492820
1790011
2090008
2385945
2685854
2984675
3281973
3579495
3878729
4178580
4477433
4754821
5054273
5353358
5652760
5948281
6248066
6546647
6841505
7137659
7435105
7733963
8033607
8302006
8599282
8893028
9181288
9480442
9775330
10070277
10369928
10662122
10945527
1...

result:

ok 300000 numbers

Test #95:

score: 0
Accepted
time: 91ms
memory: 12512kb

input:

300000 71588
299994 145771 121580
299993 80423 81989
299985 59099 71751
299981 133011 203491
299978 176147 111664
299975 52319 279974
299966 223395 284500
299962 206955 3235
299961 94719 14977
299960 283397 71894
299959 186047 93189
299956 113676 15721
299953 20486 64757
299951 167727 80534
299950 1...

output:

0
299814
599600
899411
1199166
1498714
1797247
2096524
2396202
2695166
2994941
3292364
3589714
3887613
4183242
4482553
4779277
5075518
5374826
5672766
5968530
6267771
6561387
6859208
7156860
7443729
7732615
8016280
8311470
8605137
8903232
9197178
9494839
9794732
10087143
10384045
10681978
10980242
1...

result:

ok 300000 numbers

Test #96:

score: 0
Accepted
time: 97ms
memory: 13516kb

input:

300000 187716
299996 194894 222188
299993 268085 30428
299988 296914 37430
299984 103421 255175
299982 49301 189285
299979 235896 23675
299977 10729 199162
299974 3219 93325
299969 180299 217347
299968 215128 191883
299967 202575 28667
299965 193226 182424
299958 31804 26992
299957 50959 163348
2999...

output:

0
298782
597920
897843
1197613
1496041
1795203
2094303
2386513
2684478
2982948
3281403
3579893
3877643
4167959
4465636
4764439
5062403
5360262
5660020
5956332
6242062
6531974
6831440
7127477
7427253
7727033
8026967
8322837
8614982
8913027
9204781
9494822
9793981
10093724
10392890
10689002
10988703
1...

result:

ok 300000 numbers

Test #97:

score: 0
Accepted
time: 102ms
memory: 13544kb

input:

300000 161731
300000 170099 97232
299994 119307 135954
299989 30299 34038
299987 210603 84374
299979 5199 264588
299977 146442 178692
299974 131350 86080
299970 266972 142625
299968 65046 65703
299964 141602 42670
299963 99202 112338
299962 81887 196345
299961 211185 271263
299960 227532 175215
2999...

output:

0
299712
598619
898018
1197998
1496242
1795888
2092031
2391877
2689930
2989597
3288470
3584214
3874824
4169494
4465910
4764529
5053725
5353415
5653012
5951796
6251433
6550007
6846810
7145504
7438536
7731016
8030602
8329867
8629313
8921581
9219596
9516405
9814456
10112085
10407914
10706535
11001175
1...

result:

ok 300000 numbers

Test #98:

score: 0
Accepted
time: 89ms
memory: 16060kb

input:

299925 264962
1 2 166828
2 3 71646
3 4 168076
4 5 206791
5 6 265776
6 7 160584
7 8 89629
8 9 126631
9 10 147900
10 11 244761
11 12 271268
12 13 218383
13 14 162906
14 15 220693
15 16 199380
16 17 185350
17 18 132066
18 19 266206
19 20 188702
20 21 203612
21 22 19713
22 23 241208
23 24 82992
24 25 96...

output:

0
166828
238474
406550
613341
879117
1039701
1129330
1255961
1403861
1648622
1919890
2138273
2301179
2521872
2721252
2906602
3038668
3304874
3493576
3697188
3716901
3958109
4041101
4137123
4224960
4415867
4675339
4723882
5013522
5298163
5399402
5524098
5544221
5809806
5993188
6110466
6310461
6328865...

result:

ok 299925 numbers

Test #99:

score: 0
Accepted
time: 86ms
memory: 13500kb

input:

299925 254715
1 2 78772
2 3 280196
3 4 260108
4 5 281416
5 6 35923
6 7 181422
7 8 74492
8 9 293740
9 10 98178
10 11 212726
11 12 85458
12 13 149656
13 14 74514
14 15 77591
15 16 48222
16 17 134414
17 18 117753
18 19 220403
19 20 190222
20 21 103836
21 22 276923
22 23 224463
23 24 235825
24 25 120804...

output:

0
78772
358968
619076
900492
936415
1117837
1192329
1486069
1584247
1796973
1882431
2032087
2106601
2184192
2232414
2366828
2484581
2704984
2895206
2999042
3275965
3500428
3736253
3857057
4069177
4199780
4430138
4622301
4911886
5027624
5323137
5569720
5608476
5891662
6119248
6177631
6354596
6557091
...

result:

ok 299925 numbers

Test #100:

score: 0
Accepted
time: 83ms
memory: 16352kb

input:

299925 285764
1 2 290642
2 3 223150
3 4 100477
4 5 7852
5 6 71667
6 7 250522
7 8 59355
8 9 202221
9 10 265789
10 11 139394
11 12 151310
12 13 46600
13 14 20451
14 15 282677
15 16 203956
16 17 76512
17 18 193000
18 19 174601
19 20 233038
20 21 4059
21 22 241176
22 23 166422
23 24 130029
24 25 111257
...

output:

0
290642
513792
614269
622121
693788
944310
1003665
1205886
1471675
1611069
1762379
1808979
1829430
2112107
2316063
2392575
2585575
2760176
2993214
2997273
3238449
3404871
3534900
3646157
3682635
3711638
3912882
3955708
3986609
4199040
4354574
4640452
4656544
4950364
4997854
5255970
5444235
5572193
...

result:

ok 299925 numbers