QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#176494#2732. Vera and Modern Artlgswdn25 ✓843ms797488kbC++142.6kb2023-09-11 18:35:472023-09-11 18:35:47

Judging History

This is the latest submission verdict.

  • [2023-09-11 18:35:47]
  • Judged
  • Verdict: 25
  • Time: 843ms
  • Memory: 797488kb
  • [2023-09-11 18:35:47]
  • Submitted

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128; 
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii; 
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
ll read() {
  ll x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=2e5+5;

int n,m,ans[N],s[N<<6],tx=1,ty=1;
int cx[N<<6][2],cy[N<<6][2];
ll c[N];
struct opt {ll y; int w;};
vector<opt> p[N<<6];
vector<int> e[N<<6];

void addx(ll x,ll y,int w) {
  int h=topbit(x),u=1;
  rep(i,0,h-1) {
    bool b=x&(1ll<<i);
    if(!cx[u][b]) cx[u][b]=++tx;
    u=cx[u][b];
  }
  rep(b,0,1) {
    if(!cx[u][b]) cx[u][b]=++tx;
    int v=cx[u][b];
    p[v].eb((opt){y,w});
  }
}
void addy(ll y,int w) {
  int h=topbit(y),u=1;
  rep(i,0,h-1) {
    bool b=y&(1ll<<i);
    if(!cy[u][b]) cy[u][b]=++ty;
    u=cy[u][b];
  }
  rep(b,0,1) {
    if(!cy[u][b]) cy[u][b]=++ty;
    int v=cy[u][b]; s[v]+=w;
  }
}
void qryx(ll x,int id) {
  int h=topbit(x),u=1;
  rep(i,0,h) {
    bool b=x&(1ll<<i);
    if(!cx[u][b]) break;
    u=cx[u][b];
  }
  e[u].eb(id);
}
int qryy(ll y) {
  int h=topbit(y),u=1,ans=0;
  rep(i,0,h) {
    bool b=y&(1ll<<i);
    if(!cy[u][b]) break;
    u=cy[u][b], ans+=s[u];
  }
  return ans;
}
void dfs(int u) {
  if(!u) return;
  for(opt f:p[u]) addy(f.y,f.w);
  for(int g:e[u]) ans[g]=qryy(c[g]);
  dfs(cx[u][0]), dfs(cx[u][1]);
  for(opt f:p[u]) addy(f.y,-f.w);
}

signed main() {
  n=read(), m=read();
  rep(i,1,n) {
    ll x=read(), y=read(), val=read();
    addx(x,y,val);
  }
  rep(i,1,m) {
    ll x=read(); c[i]=read();
    qryx(x,i);
  }
  dfs(1);
  rep(i,1,m) printf("%d\n",ans[i]);
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 78ms
memory: 608984kb

input:

2000 2000
863052900322308438 585461919958425547 2603
526750366165658033 509066789767077405 7436
649435956957351345 979682059927434256 9868
830905178259479463 747566590013542340 5131
322888213739078622 787599796792931260 5343
387720552768190527 707990974300483296 5456
995284968988447437 6559282648306...

output:

8539
8343
854
5294
9664
3968
9107
4499
8382
1452
8392
5492
2149
8619
5437
9251
893
8792
6336
7180
5110
766
8539
2222
4701
3956
5173
8460
3069
8600
5324
6804
1064
3307
229
1199
2054
7956
3350
6974
6551
7179
198
4066
4633
356
9134
7184
1170
2616
8475
6425
7126
7366
8558
3044
2531
3342
2920
9428
9287
9...

result:

ok 2000 lines

Test #2:

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

input:

2000 2000
708742429912472382 657489792224291690 2908
786445592645402997 366970491269851157 6413
644824623743061293 878556194838199508 895
854342240174626476 506630596144597431 3522
490284640060217554 561102830959103106 1938
608637915455246516 881134709624987778 656
706875321854362355 325801426255009...

output:

4369
6940
5158
4159
2963
8728
3640
4731
7105
8018
2952
7355
3651
7565
6115
7246
4391
2844
9272
5265
4486
2950
6607
1193
1813
6611
9862
5653
5265
1911
337
5220
1092
3241
4696
8942
4153
1459
2985
6977
2392
5253
8954
859
2217
2389
1386
4079
4543
1221
3222
1353
3892
5028
8944
8174
7824
8078
539
4155
505...

result:

ok 2000 lines

Test #3:

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

input:

2000 2000
10 60819039 5702
3012786602512671 7176094883 852
25485144 7 5861
3098207184192 17344 755
87 158884 9867
30509 446840 1040
13706101785 74 4785
702 31473101 4340
729 297538590445889743 1787
20734250687 14086930566 5671
173623981 253459185965263 29
469839 6715142 1325
1909439723762 1617684566...

output:

15960
13249
15766
7893
25482
8286
0
26265
20374
10804
9781
4077
1518
6853
12495
14197
24779
236
7625
11412
27744
7625
13441
6402
13854
14136
27211
8286
0
9260
5925
10601
8094
16814
7085
10157
22502
4671
18957
9893
12802
0
17016
21306
7625
7379
22076
7625
0
13960
7625
7625
7625
0
8814
23926
1932
4041...

result:

ok 2000 lines

Test #4:

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

input:

2000 2000
45894 13541 2711
37412030 487660 4900
30196454574 389817 211
119345 42985683221218 7389
127 1728973986561263 3752
790840 12847262810 3141
1356409281996192 65686349678 4462
1785396 5 487
7967558 340996377158 7542
111 29412076648876 4010
23355184283436377 170170991 9115
361099 90361263738019...

output:

21038
17108
13598
15804
9664
15799
17354
10054
21136
30604
9664
18887
18887
18887
21038
24457
28141
18887
16814
9664
20230
10116
4960
19179
21136
26488
9664
18887
10991
33253
13039
9664
9664
17878
25531
9664
12821
18581
16814
10472
13546
10742
24756
22808
15804
22519
21136
9664
37079
12349
17108
185...

result:

ok 2000 lines

Test #5:

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

input:

2000 2000
2138644 18 7719
1124820 13367832532490 945
90991704 160 1366
49629002251270303 529067355 9481
30839499163862 11316 446
19237082202654687 55 1479
13341522551 1375266 4600
27466634768416 2562317 875
1000000000000000000 7204 1533
6070750319 310 195
128 38438648820523 5833
4834369105 106638377...

output:

39146
37573
23460
40491
8593
8593
8894
38131
37429
34220
42489
7797
8593
32606
25865
15529
8645
34871
34220
15529
34220
39094
39214
34220
34545
25865
34545
46147
15529
32606
15529
15529
15529
34220
32606
15529
34994
8593
8946
24883
15529
51076
15529
13420
34220
15396
42489
34942
34220
15482
33861
86...

result:

ok 2000 lines

Test #6:

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

input:

2000 2000
21279519767 1211 4932
10773909809 23009589064105 7530
5646830 1 7575
69104 3032892120148480 1107
173253389887 62 4388
68925773 2213637099 8369
87157 155 5066
569667900962 1762878 9540
28627 15143434019770 9986
17417579267458 6954805104 1652
60461726535752 13246230 6377
3119 1212914361927 3...

output:

9877
14992
6052
7953
8687
0
14262
10437
0
0
0
8210
12694
856
0
5127
2315
0
8210
5377
3812
6052
6052
0
0
2315
6052
6642
0
856
4271
2315
0
2315
14262
6052
856
6052
0
9877
856
0
7312
14262
3171
8210
2315
2315
0
8210
14262
8210
5377
0
9384
0
8210
4271
3812
2315
8687
14262
0
16735
6052
8210
14262
0
2315
...

result:

ok 2000 lines

Test #7:

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

input:

2000 2000
2137 38073 6725
355 18 8213
5830587504 2 2648
78 5 8264
424149824559596 72093549985 2933
1281696708970614 53221 6426
3 589231223 2945
678 15738720472 7289
91057713696519 1460584943111 8661
1555508538242 1790149551118669 2372
20382435790632 358326815974203 3473
96468543157 480 7175
28077249...

output:

3479
12949
4332
4332
11551
19564
9284
32807
32807
13388
11551
5652
12610
12563
9284
4332
12146
12610
9284
12949
12146
6920
7219
9284
11584
4332
4332
21659
0
6920
17791
11252
21618
4365
11584
4332
12563
4332
25265
17791
19564
4332
12610
32807
7219
11551
11584
12563
5652
11252
4332
11252
5652
11584
69...

result:

ok 2000 lines

Test #8:

score: 0
Accepted
time: 73ms
memory: 608640kb

input:

2000 2000
5851786354176 4040428 2265
2090124767 9823 6987
67 119398 7142
404045861381842460 3 4115
47 323339427358234 8545
19 45369 3431
8088146 103 2182
95668676 1 3668
1324931120984 199200407955310 1645
1732727909 1721354791 9459
57549964551968961 7524884872 3213
11920489260 535832679744 3984
4026...

output:

9554
16934
16870
20670
16187
9554
9554
11749
16363
9824
11749
9554
16187
16870
9554
9554
18654
9554
22961
16187
18654
11749
17359
9554
16159
18654
18654
16187
18654
18654
13954
9554
9554
16187
9554
9554
9554
13861
18654
9554
16187
9554
12571
23608
13954
12571
9554
11749
9554
20670
23608
9554
9554
18...

result:

ok 2000 lines

Test #9:

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

input:

2000 2000
535900078 28730525 2952
102 17650 9358
4535 3384757114 9082
12867229 174904954970818796 3058
1656 1380114853 5613
263494408554410 28685 7005
215030 1462180803 2810
812 3734266673996462 3464
452828 33 5538
7503915 436 386
78255526600570122 1701255 3079
4415561 159069185 5601
11952238 188369...

output:

0
6174
8468
9615
5266
0
0
2789
0
5266
5266
0
9615
0
9615
9615
5266
5266
5266
9615
0
5266
9615
9615
0
9615
0
0
14345
8151
5266
10765
8487
5266
9615
317
0
0
11440
5266
0
2789
9615
5266
0
0
8487
0
0
5925
9615
5266
9615
8487
0
5266
14345
9615
0
0
0
9615
9615
8487
0
17766
0
6625
17766
5266
0
0
0
2789
120...

result:

ok 2000 lines

Test #10:

score: 0
Accepted
time: 75ms
memory: 607940kb

input:

2000 2000
131890964963 2620980678199514 5450
48642228835614046 533511702086 2191
107286339040564510 228499 3277
1 75542183 285
767960049 36 4728
6306312438 3565071862123 9346
14531963 352 9415
1315928 3 8018
11220423379745349 7033730184 3518
55265770561030 1593709490903 4700
359015303917077 39678719...

output:

15575
5686
4500
0
12877
4500
7374
7248
0
0
0
0
4626
4500
7248
4500
4500
5686
7248
0
4500
4500
15819
7248
4500
2116
4626
2748
4626
15008
0
8727
4500
4500
7248
7248
4500
6281
20880
26309
4500
15008
0
6281
4626
7374
7248
4500
4500
7374
0
4500
5686
15625
12498
5686
0
5686
4500
5686
4500
9579
15008
26309...

result:

ok 2000 lines

Subtask #2:

score: 5
Accepted

Test #11:

score: 5
Accepted
time: 585ms
memory: 695952kb

input:

200000 200000
859422066098830991 1 4914
642859986446449532 1 376
719948192245038320 1 5246
326732866086294827 1 4979
927556748609838327 1 6477
966962857351020963 1 8843
935451737400114761 1 4518
455550602517312533 1 76
542921280411063861 1 5774
838451513131566371 1 7145
981836072584124918 1 5220
346...

output:

5205
4936
1403
5167
7383
4859
7776
9177
5939
3299
8317
677
3523
8993
4241
573
6384
1702
1468
783
1121
5132
3615
4793
4193
6153
5942
8494
1719
7636
937
7039
5003
3525
1913
9495
1140
1807
797
1077
3307
5210
4898
9472
8034
9364
1670
4986
7425
600
7955
9871
3313
6349
2658
6340
1755
8179
3819
2730
6962
8...

result:

ok 200000 lines

Test #12:

score: 0
Accepted
time: 593ms
memory: 695160kb

input:

200000 200000
956411821175138894 1 5358
341642377596522918 1 2127
715082333858786977 1 2503
994733210681795576 1 8498
629491736026527962 1 3061
302275246921408818 1 6499
592174816840684778 1 2495
475299672941996761 1 7538
435302727068183202 1 5054
909771490031798723 1 9922
356138676220151881 1 8224
...

output:

6844
6202
9398
2023
6059
3934
4558
1828
9426
4996
3924
6627
4916
4523
9946
2082
9823
8465
5976
9999
123
9014
6728
563
4289
3259
8044
9580
9623
254
1083
3459
4693
9091
6721
1478
1234
2512
1226
7251
6495
23
2959
4184
556
2338
5181
4518
896
7211
2757
6055
6219
4609
3964
6738
1240
7175
3435
715
5322
695...

result:

ok 200000 lines

Test #13:

score: 0
Accepted
time: 391ms
memory: 648524kb

input:

200000 200000
1194431153319868 1 2750
116188032 1 5148
32049992419 1 1806
374 1 8441
6570622 1 7066
1235310 1 9310
30 1 6499
399268052852849224 1 4274
93923 1 8230
14040791738223584 1 6040
3 1 2600
160960 1 3522
16187950407 1 420
441 1 1682
993612742070 1 4800
93975081 1 2450
273362016008 1 8070
101...

output:

33545644
33551382
33128609
32802400
33231571
33820229
33753774
33489214
33163631
33472061
33426791
33386558
33680286
33268904
33351506
33578826
33242322
33374940
33772489
33314529
33452217
33452780
33153071
33533325
32779453
32633278
33381142
33350028
33157200
32896978
33502670
33272381
33318496
331...

result:

ok 200000 lines

Test #14:

score: 0
Accepted
time: 360ms
memory: 648848kb

input:

200000 200000
474950 1 3067
15557675711 1 6730
8193059 1 3700
925864226443607322 1 6325
222003 1 8031
14595233 1 3103
293877914 1 5690
72989027089079397 1 2575
48 1 4105
379502 1 6860
11142871072401 1 4136
1909791326750 1 1100
7 1 9522
34519328413533175 1 3977
116165473 1 9054
31151238679035 1 2209
...

output:

33099869
33183075
33062765
33075750
33203524
33167485
33239580
32921624
33195832
33051732
33006135
33056044
33319080
33027350
33200864
33244233
32966392
33098992
33138726
33245518
32925523
33132446
33130328
33091453
33223817
33152671
33083001
33042090
33444413
33050540
33286033
33184427
33231015
333...

result:

ok 200000 lines

Test #15:

score: 0
Accepted
time: 308ms
memory: 652372kb

input:

200000 200000
2712556 1 2061
32765932 1 5640
42310977934 1 7880
4833835581423695 1 9351
55084 1 5386
17 1 6246
158093678851225511 1 3557
24675909 1 2604
3823 1 5401
223648272245477 1 7385
941838317580021883 1 1280
122785012348289447 1 2876
1217318239522057 1 1470
1924238782 1 6274
1 1 7801
123064771...

output:

34086665
33859193
33950839
33865461
33640621
33363836
33461248
33852383
34096351
33704901
33514823
33630146
33272441
34010570
32544025
34141667
34173727
34009845
32913413
33730422
34049999
33457836
33789839
34064863
34016759
33665303
34084200
33748405
33135187
34039009
33973667
33833533
33893258
337...

result:

ok 200000 lines

Test #16:

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

input:

200000 200000
3178755513 1 2215
4927 1 6394
13930074095409626 1 392
45131 1 8260
6 1 3727
384543297153808 1 9095
17824102655858463 1 3075
5493663090030 1 5179
121787 1 9353
15673967519747 1 1687
34372267279289538 1 9996
71309834 1 3327
20971496201090299 1 200
7314858614 1 7170
298 1 5212
40523 1 339...

output:

33242854
33099614
32399390
28979510
33006246
32795099
32722811
33487828
32971133
33516302
33501216
33116821
37675159
33032481
33723025
32388311
33269921
33586856
33124341
31306757
33103511
32257499
33445025
32779194
33272556
32519865
32797156
33229312
33265961
32603320
24878009
32919945
32930418
324...

result:

ok 200000 lines

Test #17:

score: 0
Accepted
time: 303ms
memory: 650212kb

input:

200000 200000
2101 1 2088
36643136080 1 239
7588 1 2175
555331521919 1 6827
134217165 1 5590
47 1 1936
318984407921 1 8230
46689805418 1 7374
900094645945710257 1 458
253021369 1 152
569693414191909410 1 7492
4048315897519205 1 2733
15780089943340 1 2570
125167 1 7243
199817129 1 3301
2119372 1 9974...

output:

33091363
33126707
32055316
33170472
33518458
33252157
33122807
33147404
33068334
33285961
33516173
33017698
33328698
33336361
33094465
33248427
33623369
33173174
33555230
33253201
16572023
32990034
32949741
33272050
33140909
33229905
32934805
33609524
33221133
33025040
33537186
33051980
33127291
330...

result:

ok 200000 lines

Test #18:

score: 0
Accepted
time: 337ms
memory: 652380kb

input:

200000 200000
3962799484931408 1 2115
182712831275931 1 2107
23 1 8110
8392713976 1 8541
185865241942236 1 3627
233359626153 1 8996
2398 1 297
875967 1 3511
202 1 8629
19275153 1 1922
16038 1 1259
238824859732 1 7618
3826013 1 3401
1613050361 1 9572
26053821135933 1 1093
70 1 8410
188556278855779887...

output:

32322088
32658584
33303387
32405006
32793760
32887215
32833560
33312066
33337102
32618409
33369949
32867793
32349905
33134813
24981019
16447491
32886790
33310030
33522127
33591231
32773142
32771663
33640998
33602438
16447491
33508435
33221095
32806981
32858132
33403845
33057391
32787990
33192308
323...

result:

ok 200000 lines

Test #19:

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

input:

200000 200000
1 1 7534
4275885371532498 1 4062
170978034 1 8167
55952059598 1 4988
4325469396017 1 7167
8580936470 1 5302
1 1 2584
921793120 1 1606
151293375742270799 1 7846
39 1 3854
10508300610266 1 5572
836228 1 77
995897183530175 1 7145
999306 1 8757
15350735290511 1 5420
122697889155815 1 6411
...

output:

32368922
32692959
32404361
32934996
32580288
32736331
32751294
32951846
32571009
16464273
32800468
32830343
32337748
32767873
32917901
33077523
32623080
30466625
32867252
32658270
32404941
32913831
32664437
32632325
33073949
32606896
32378577
32052056
32912444
32787785
32309726
32210148
32526009
324...

result:

ok 200000 lines

Test #20:

score: 0
Accepted
time: 317ms
memory: 651388kb

input:

200000 200000
24828 1 4088
15145733213981 1 2605
32708338252 1 5316
75544499748460268 1 4584
28 1 5430
44690218 1 5890
3 1 774
22563301 1 5062
273352 1 2101
1 1 6745
2101 1 6115
146911856 1 85
31291502335198 1 4461
446496166299489069 1 7130
65152339 1 1003
32637 1 982
29037 1 7801
914392236516 1 150...

output:

32927657
33310876
33552068
33254526
33082165
32656922
33505558
33598059
33436152
33271556
33554491
33402987
33630322
33092393
32940836
33403934
33282014
32923753
28998144
31454146
33530401
33687994
33720787
32975924
33506833
33424330
32963002
32961215
32928503
33117984
33065405
33076580
32982287
332...

result:

ok 200000 lines

Subtask #3:

score: 5
Accepted

Test #21:

score: 5
Accepted
time: 263ms
memory: 645444kb

input:

100000 100000
504849608 374110485 5954
845294749 269058441 4860
818642530 341615985 5355
779408178 612082365 3722
392690513 971162916 6982
999625668 824426927 1261
966352187 983873183 722
517369231 806105700 3569
905389201 907084792 503
582692052 424611071 9044
373185376 783728614 4518
285689031 604...

output:

1226
1136
1263
9933
1046
5982
3994
4762
1069
4836
3919
5873
3652
2335
8752
35
7194
6444
8424
4933
6260
3327
7190
5510
419
4822
3506
8873
7768
4274
4632
602
3088
3589
4027
1100
4303
4506
9467
7327
6181
9812
7483
219
2051
2723
8049
8846
667
1116
3742
8816
2337
9921
5265
5827
5071
990
6568
6524
310
680...

result:

ok 100000 lines

Test #22:

score: 0
Accepted
time: 244ms
memory: 645920kb

input:

100000 100000
534379735 780548911 380
431960394 779154520 2529
584521049 676574900 8067
508669304 334379533 6321
447880762 685734962 725
657780154 741080343 9682
317099245 988245646 8169
536928394 989620319 8266
466127191 335597357 6592
505329757 654354610 2559
842762730 386933982 531
322162211 9513...

output:

7005
1657
5392
4775
8427
6567
4764
362
7676
7602
9721
931
1361
7537
9338
9401
4403
7451
5580
9305
4117
1819
835
549
9977
332
4505
8535
41
4039
4348
3515
5496
1422
9222
2830
6851
4630
6242
1407
7510
7144
4740
453
2887
6297
3367
5293
8995
6548
1359
9093
8010
4574
5566
1008
3199
4546
2992
3025
131
2667...

result:

ok 100000 lines

Test #23:

score: 0
Accepted
time: 181ms
memory: 624064kb

input:

100000 100000
103 13726404 5235
1 3 416
200749 245 6729
25 223 2479
6 1543 8387
156362328 250034857 9201
4381295 509704 7076
976167077 6183 6405
19 24172 6171
8244790 53133568 6117
145224726 3 6598
2014527 34 6010
87250 43 3697
867 1239364 4892
29451 211788473 1334
566956124 1 5446
18 29979 5814
337...

output:

2309437
2454452
2426628
2290482
2223384
2446790
2428685
2256789
2463783
2290359
2440133
2424452
2485737
2299203
2204788
2309210
2197585
2317724
2444547
2291101
2453706
2428702
2328679
2388096
2379216
2192881
2343031
2293948
2303924
2241459
2429122
2320486
2481256
2193778
2307954
2479334
2235476
2431...

result:

ok 100000 lines

Test #24:

score: 0
Accepted
time: 181ms
memory: 623520kb

input:

100000 100000
2239 126 6524
875843036 16031 1927
28 114824 9616
220018 38 3298
3562037 2727 7014
93516 11481700 2100
33097 187181 6885
18 18 7188
1 1 733
7 17098112 1833
2781 261357021 8093
139 1962944 5993
434496414 64 8349
713 604013 9898
3 12126508 2646
943918 634 2734
911877 4 1430
35534604 1670...

output:

2143648
2196870
2158620
2112939
2195911
2078584
2092929
2115071
2112941
2124824
2129272
2237322
2099065
2106570
2150551
2238218
2076364
2082617
2096750
2198817
2128425
2148912
2189569
2199924
2075772
2104890
2156805
2122884
2156627
2076359
2154691
2119123
2212134
2050779
2207710
2034043
2146784
2135...

result:

ok 100000 lines

Test #25:

score: 0
Accepted
time: 175ms
memory: 621908kb

input:

100000 100000
255870721 5390 5681
815806504 7658054 2735
96 55828 380
166 54 2890
2632431 1532 5608
13935 168377352 3590
2461603 485488300 7720
62940 509 287
358 219649 1236
5262206 1 9891
46085868 416934 1849
110286 2527221 2667
916804 72350500 4287
165 388370 666
78818796 315 8234
2926 111822 2933...

output:

1835239
2164793
2112620
2124344
2270196
1125417
2000096
2287328
2308439
2061326
2247827
2087501
1646271
1584137
1887804
2177930
1006424
2123368
2128024
1551646
2117375
2011076
2025553
2148496
1051321
2140776
1926557
1122544
2165535
2192411
2124381
2157303
2091328
1565725
2061849
2114617
1030674
2072...

result:

ok 100000 lines

Test #26:

score: 0
Accepted
time: 172ms
memory: 623336kb

input:

100000 100000
15800 107873 7984
2139540 4014 573
6023 22765 5677
135561 94 1561
4893 59302 4233
127930 3 6813
51 1847 6458
2125988 2225142 3145
433661112 59008 7837
8369724 4731783 9695
426082 2159 5121
40063008 6631637 6653
411270 3348 4339
2 2032724 6473
127781 14098671 5340
24208 446506 3676
2321...

output:

2161170
2278105
1801025
2049582
2252751
2225443
2400492
2254043
2220746
2073044
1136927
1576171
2188676
2146423
1099874
2283307
2298246
2271619
2331726
2196609
2188652
1641814
2255780
2431482
1943289
2023417
2395515
1906402
2128293
2401384
2225815
2205821
2112707
2260055
2017553
2441234
1108299
2118...

result:

ok 100000 lines

Test #27:

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

input:

100000 100000
2 892534 8507
251494320 66699 2874
45822400 46688380 5711
86000 46574 202
5 1508923 3054
27805 8123 8394
3 146298143 2820
110552 134253535 9389
55 1296 4881
3 1266207 2266
3323 7999 8489
41414214 2 9601
30 648833853 8476
3676 33 9838
168 7736914 5319
507886 326 9261
516994341 76 491
24...

output:

1904118
2342049
2299153
2402067
2271857
1162915
2179037
2325727
2307662
2303003
2361794
2119809
2216961
2350705
2278138
2249146
1602712
2414895
2418309
2197055
2118592
2267113
2189086
2422560
2243233
2250368
2241853
2318480
2146354
1192242
2163772
1751273
2174632
2048862
2154029
2097213
2361304
2355...

result:

ok 100000 lines

Test #28:

score: 0
Accepted
time: 158ms
memory: 624024kb

input:

100000 100000
1495490 2958 6434
124 140588572 3028
2 514 49
12443 7366 8397
29588235 575737 2008
600 2 8077
33 934 8295
57 3339257 9883
1765 311539 6770
122 27 3603
536453109 36948 8322
172103297 3685726 9575
233360268 268513 3609
1 32438299 1769
1 208035 7226
287944 6498 3369
72449 2 3513
2555 6988...

output:

2299113
1823259
1589558
2333792
2145076
2073363
1933409
2097337
2129309
2261227
2181843
2231163
2256007
2233258
2225668
2178197
2401522
2003084
2147316
2321528
2126198
2231395
2309634
2077688
1914339
2027986
1093916
1631430
2283512
2228746
2249592
2057787
1931640
2228441
1076461
1987679
1078438
2221...

result:

ok 100000 lines

Test #29:

score: 0
Accepted
time: 188ms
memory: 623984kb

input:

100000 100000
148 18408 1606
187965177 278438305 4093
1194 54973 6563
75 102182 2803
29681996 98 1477
44 52192 5846
108896960 140 2338
103075974 9603 596
29999681 22500712 7423
57 92 7577
225533074 112 4762
144 71 5760
977 127 1435
20 7969 6955
43917 163 4070
5513822 1471 3854
283 174386 5492
3 3482...

output:

2149301
2177924
1826522
1984477
1868929
1922954
2097484
2217410
1973282
1088921
2094092
2191800
2071612
1023082
2080808
1815550
2111525
1790540
1866261
2291773
2208619
2219113
1946750
1918818
1107163
1988681
2152812
2254801
2141172
1740715
1975871
1436434
2151390
2360504
2277799
2214522
1032795
2182...

result:

ok 100000 lines

Test #30:

score: 0
Accepted
time: 155ms
memory: 625560kb

input:

100000 100000
68 7876 8245
7427750 5796955 9140
986 12608495 7365
66686398 511566 3146
83 1 1447
1367 29 1398
694172601 124328847 7269
3199 121277 9318
257216716 263593391 3064
25 513 7119
3 338 7651
564 25807688 1403
10383084 23 2304
2108 210436243 9778
2415 50166032 2153
36337 243688348 9534
32435...

output:

2321953
2359991
2159166
1582189
2413720
1187418
1092303
2340607
2223092
2272648
2089771
2273343
2210416
2198546
2241462
2340005
1691918
2329324
2402441
1967817
2205981
2368384
2283140
2276213
2185729
1985069
2140406
2268787
2175229
2359316
2314892
2147013
2225378
2093984
1127314
2149143
2224232
2282...

result:

ok 100000 lines

Subtask #4:

score: 10
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #31:

score: 10
Accepted
time: 820ms
memory: 797488kb

input:

200000 200000
304551451493979362 978252592185660690 3986
736180404426382117 699465552887116355 4249
829848014815153139 840393099324660235 4701
340967479544801503 684030297401736637 4815
799021574895164578 789438266711693655 7892
700066576029503659 922595963922825727 7174
422675637086311650 627942636...

output:

4433
7227
9189
6056
7811
7552
1781
8389
9736
1122
9649
9379
6915
1715
7842
7842
2664
9579
1122
4115
4293
8100
5765
1982
7035
8056
1630
2346
6131
9710
2658
4810
8599
1855
5119
5123
2034
1539
6969
7506
8696
8576
2310
5650
6351
2384
1318
3464
488
6654
6801
213
7082
1217
2072
905
8205
5931
7811
9562
725...

result:

ok 200000 lines

Test #32:

score: 0
Accepted
time: 843ms
memory: 797412kb

input:

200000 200000
595686247582366824 960057099811214805 4839
337303931192668730 367545485427897697 6818
550058514850987167 346407225463300838 1453
546639016510043777 436174141155311268 6421
934787841519659348 566251712050498310 3503
494005654284275108 516902409673071091 627
924038169504193306 9463524795...

output:

2281
6598
9513
3254
1176
6216
2439
4971
6730
7987
6667
720
4415
6417
1700
3301
2373
2070
4878
3128
7741
4429
3690
8669
762
3588
8204
7796
7338
7540
8562
957
6108
7983
870
5600
9685
6333
7571
5911
2725
7988
3836
7904
3506
2865
4335
7001
4033
1144
622
5650
6838
8543
4179
8288
5218
5059
9609
550
5014
4...

result:

ok 200000 lines

Test #33:

score: 0
Accepted
time: 517ms
memory: 681328kb

input:

200000 200000
19 501419250732667 8757
8996470088282 4 7009
3046404729 17987925 6270
61381336486638968 4202543808 7787
18988994109327322 3618426982702524 7451
12 414572988557970139 6415
1615190 1407 9615
4784739650724006 58095928495 9511
4127589778 635371080079586 3359
2110771285 2364335109949557 126...

output:

1153040
1113703
1173866
1052445
1071535
1126946
1162488
1107905
1175322
1151316
1148056
1103776
1136216
1105340
1073017
1065698
1053307
1095539
1134909
1056684
1051926
1069406
1152334
1039325
1041332
1154860
1164258
1085013
1098098
1140975
1169875
1136843
1136759
1041375
1067138
1058640
1068024
1180...

result:

ok 200000 lines

Test #34:

score: 0
Accepted
time: 533ms
memory: 681300kb

input:

200000 200000
13995 33874 3547
53964813 11667058 5255
1 277129949362373 9642
88096167078747498 23836821 3162
17 153429818413 7987
95495945121597364 19989909717 1830
2086 3899205438898512 4925
3062446597282 5511852 1177
12755283080665882 4119951586513 5577
210652 16 2678
16905369292901037 1855335966 ...

output:

1159443
1085837
1132131
1044403
1164064
1193207
1141676
1000059
1087695
1093537
1028741
1034851
1043829
1085552
1127110
1168737
1161565
1035933
1037575
1113279
1149505
1018377
1115958
1127616
1053897
1092341
1097812
1083204
1081715
1038105
1133229
1162129
1214899
985988
1135342
1149786
1113789
10594...

result:

ok 200000 lines

Test #35:

score: 0
Accepted
time: 466ms
memory: 691248kb

input:

200000 200000
138354742247 269168058 8209
307 732600454559 7374
21192123283 1 5612
4249438958546 15417 8024
2167851252672 147178830417980 9098
645591314697819509 1 1117
1228560 651717 1756
32494459904309 17 4443
1197124201688 6326 6590
9076658931608849 4488 4901
27147493798077459 549 8899
6 12 1411
...

output:

1060542
1226866
1116539
1140901
999034
522907
1213903
1093057
1029490
740100
1033658
964392
1130066
1131612
1073722
1164943
1040061
1040183
1095504
1104149
1142204
1047444
1161730
1002409
1221656
1246336
1148989
1109145
1075136
1111166
887079
1062414
1001626
1139576
1214292
529633
1076259
1012089
10...

result:

ok 200000 lines

Test #36:

score: 0
Accepted
time: 472ms
memory: 691144kb

input:

200000 200000
242456124022 1867974048 9570
914812756737 2 1274
11 5196454003 4933
145 463272500490595402 3956
22 38 1383
9111292210511 994985091 4642
211062869383 813 9272
7652795214026 432455548869906004 3249
9431738919699664 5433741497422563 7870
260 183474674846427633 5135
82916639668281 19454 15...

output:

1240948
1159442
1159867
1102584
1219026
1217731
1188713
1220296
1212492
1209616
523700
1238653
1173120
1164295
1098444
1105890
1209346
1254722
904734
1135131
1242112
1238310
597301
1193689
1255710
1278005
1107409
1115017
1059900
1235819
1139294
1216217
1239702
1145782
1222427
1129250
1064936
1338463...

result:

ok 200000 lines

Test #37:

score: 0
Accepted
time: 474ms
memory: 691100kb

input:

200000 200000
223 285584 7055
865373 1343524210502213 1336
813329405701 438703 5134
1899099831346 24877128 2990
37679433987062985 1384593331683167 5657
575834225018 73 5386
8502622 1 4259
1283787972652 9638735215536243 7084
1363316239565731 34106117 3576
33425909903857627 906263 895
3220 60 8127
660...

output:

1247625
1073218
1196690
1089036
1206564
1130671
1231064
1128492
1162879
1233734
1117664
233182
1044051
1127416
1061533
806560
1189192
1101540
1090430
1163158
762217
1106945
1156143
1246050
1267581
1138462
1026714
1115664
1160311
1064787
1151756
1178445
1119105
1192532
979403
1215405
1121483
1157866
...

result:

ok 200000 lines

Test #38:

score: 0
Accepted
time: 492ms
memory: 691084kb

input:

200000 200000
1022512503758098 16543456 3828
9187063629 264556170613 6105
10 288557843546 8029
123548 1924 6991
538464202315263 16612244 5587
396287046 880858893531927310 921
12687361492485548 7147 844
267636009985774301 3989685790704402 8215
456948475180435 1417503830921 4087
8027 14133594 8080
36 ...

output:

1287580
1135624
1070472
1024567
840372
542782
1041374
1151616
1140548
954394
1075671
1199244
1090024
1212526
1140649
1164050
1114889
1043921
1047497
1091106
1081179
924898
1191528
1002408
1030737
1107535
1032512
1075271
1156787
1162928
1157052
1044863
1090711
1098011
844568
1013269
1206222
976265
10...

result:

ok 200000 lines

Test #39:

score: 0
Accepted
time: 497ms
memory: 689168kb

input:

200000 200000
4 949592897159450944 7335
183767755530106 3020 571
575 15243 5515
85744018186628 931613238447696498 6786
22248 868497082193299 1755
2131627379016420 558864018 2655
11824069512 5809 9428
59449 1521571444 6401
3801408 60 4402
2536505 18836499347868 3264
21972005755510424 20145 2599
11005...

output:

1059647
1022126
1020178
1025522
1036566
1107928
801457
944031
1028583
1068264
973779
524206
1052163
1033737
977531
1069054
1096064
1038894
1069248
1011297
1095519
985322
1103779
1053740
1014580
1035226
1017317
1077413
855010
924870
1017769
985474
1085107
954542
988260
996792
1060276
1057275
455173
1...

result:

ok 200000 lines

Test #40:

score: 0
Accepted
time: 501ms
memory: 691032kb

input:

200000 200000
2 505762 787
129666969 34420609494 6840
177 3235131 9017
43349259496911762 5012042171921 87
1070674151122 2 9552
536681286 2 3478
1993 1768649 1803
3476622 3294 865
113196157756055488 66 9522
2417330807181178 12647651599 3465
5655045456467561 26 2946
22617600589446 7135258336572 1875
2...

output:

1119413
1065876
1192288
1095103
1171771
1193873
1041774
1072762
842285
1120608
1069774
856648
1232483
1086893
1136018
1212268
1065458
1175684
1206414
1056283
948088
1156739
1091461
1066857
1142100
1090351
818697
1218684
1191425
1096252
1198153
1050712
1152355
964275
1031192
1103287
1201510
1178226
1...

result:

ok 200000 lines

Extra Test:

score: 0
Extra Test Passed