QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#8991#1217. 归程Qingyu100 ✓966ms46728kbC++173.7kb2021-04-06 21:04:432021-12-19 11:21:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2021-12-19 11:21:17]
  • 评测
  • 测评结果:100
  • 用时:966ms
  • 内存:46728kb
  • [2021-04-06 21:04:43]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <vector>
#define N 200002
#define M 400002
using namespace std;
const int inf = 1 << 30;
struct Edge
{
    int u, v, l, h;
} e[M];
vector<pair<int, int>> fa[N], minx[N];
int head[N], ver[M * 2], nxt[M * 2], edge[M * 2], l;
int t, n, m, q, k, s, ans, i, dis[N], f[N], minn[N], dep[N];
int read()
{
    char c = getchar();
    int w = 0;

    while (c < '0' || c > '9')
        c = getchar();

    while (c <= '9' && c >= '0')
    {
        w = w * 10 + c - '0';
        c = getchar();
    }

    return w;
}
void insert(int x, int y, int z)
{
    l++;
    ver[l] = y;
    edge[l] = z;
    nxt[l] = head[x];
    head[x] = l;
}
void Dijkstra()
{
    priority_queue<pair<int, int>> q;
    memset(dis, 0x3f, sizeof(dis));
    q.push(make_pair(0, 1));
    dis[1] = 0;

    while (!q.empty())
    {
        int x = q.top().second, d = -q.top().first;
        q.pop();

        if (d != dis[x])
            continue;

        for (int i = head[x]; i; i = nxt[i])
        {
            int y = ver[i];

            if (dis[y] > dis[x] + edge[i])
            {
                dis[y] = dis[x] + edge[i];
                q.push(make_pair(-dis[y], y));
            }
        }
    }
}
int my_comp(const Edge &x, const Edge &y)
{
    return x.h > y.h;
}
int find(int x)
{
    if (x != f[x])
        f[x] = find(f[x]);

    return f[x];
}
int main()
{
    t = read();

    while (t--)
    {
        l = ans = 0;
        memset(head, 0, sizeof(head));

        for (i = 1; i <= n; i++)
            fa[i].clear(), minx[i].clear();

        n = read();
        m = read();

        for (i = 1; i <= m; i++)
        {
            e[i].u = read();
            e[i].v = read();
            e[i].l = read();
            e[i].h = read();
            insert(e[i].u, e[i].v, e[i].l);
            insert(e[i].v, e[i].u, e[i].l);
        }

        q = read();
        k = read();
        s = read();
        Dijkstra();
        sort(e + 1, e + m + 1, my_comp);

        for (i = 1; i <= n; i++)
        {
            f[i] = i;
            minn[i] = dis[i];
            dep[i] = 1;
            fa[i].push_back(make_pair(inf, i));
            minx[i].push_back(make_pair(inf, dis[i]));
        }

        for (i = 1; i <= m; i++)
        {
            int u = e[i].u, v = e[i].v, h = e[i].h;
            int f1 = find(u), f2 = find(v);

            if (f1 == f2)
                continue;

            if (dep[f1] > dep[f2])
                swap(f1, f2);

            f[f1] = f2;
            dep[f2] = max(dep[f1] + 1, dep[f2]);
            fa[f1].push_back(make_pair(h, f2));

            if (minn[f2] > minn[f1])
                minx[f2].push_back(make_pair(h, minn[f1])), minn[f2] = minn[f1];
        }

        for (i = 1; i <= n; i++)
        {
            sort(fa[i].begin(), fa[i].end());
            sort(minx[i].begin(), minx[i].end());
        }

        for (i = 1; i <= q; i++)
        {
            int v = read(), p = read(), f;
            v = (v + k * ans - 1) % n + 1;
            p = (p + k * ans) % (s + 1) + 1;

            while (1)
            {
                int pos = lower_bound(fa[v].begin(), fa[v].end(), make_pair(p, 0)) - fa[v].begin();
                f = fa[v][pos].second;

                if (f == v)
                    break;

                v = f;
            }

            int pos = lower_bound(minx[v].begin(), minx[v].end(), make_pair(p, 0)) - minx[v].begin();
            ans = minx[v][pos].second;
            printf("%d\n", ans);
        }
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 5ms
memory: 19940kb

input:

3
1 0
0 0 1
1 0
0 0 1
1 0
0 0 1

output:


result:

ok 0 lines

Test #2:

score: 5
Accepted
time: 1ms
memory: 22044kb

input:

3
6 9
1 6 395 1
6 3 13 1
6 4 798 1
6 5 403 1
4 5 2 1
3 1 97 1
5 2 8 1
3 5 187 1
3 2 640 1
10 0 1
4 1
3 1
5 1
3 1
6 0
5 1
3 1
5 1
5 0
3 0
6 7
4 3 4 1
2 5 26 1
6 4 30 1
2 4 1000 1
3 1 445 1
5 6 92 1
1 2 29 1
10 0 1
4 1
5 0
1 0
5 0
3 1
4 1
2 1
4 1
3 1
4 1
6 7
4 2 87 1
2 5 23 1
1 2 16 1
4 3 24 1
6 4 4 1
5 6 247 1
1 3 223 1
10 0 1
4 0
4 1
4 1
4 0
3 1
3 1
4 0
5 0
4 1
3 1

output:

286
97
284
97
0
284
97
284
0
0
177
0
0
0
181
177
29
177
181
177
0
103
103
0
127
127
0
0
103
127

result:

ok 30 lines

Test #3:

score: 5
Accepted
time: 1ms
memory: 22104kb

input:

3
50 121
37 15 454 1
23 5 386 1
28 38 894 1
17 31 8 1
38 43 387 1
5 43 308 1
18 39 15 1
34 9 506 1
34 49 15 1
50 3 119 1
13 27 483 1
45 17 835 1
25 2 966 1
24 30 71 1
37 19 28 1
43 7 905 1
10 4 107 1
37 35 416 1
20 13 18 1
47 20 16 1
6 24 116 1
12 47 974 1
48 41 809 1
10 47 17 1
9 42 13 1
16 36 892 1
44 35 11 1
16 34 11 1
9 21 961 1
11 14 874 1
17 26 889 1
40 49 613 1
13 21 464 1
24 10 679 1
33 30 927 1
46 20 472 1
28 40 3 1
9 35 24 1
16 9 170 1
15 25 17 1
4 6 813 1
48 11 31 1
36 28 28 1
37 32 3...

output:

1526
1503
1503
1466
1369
1665
1650
1650
0
0
497
0
1402
1671
1401
1379
1451
1646
1650
1671
1646
1365
1646
1215
0
1413
1330
1483
1665
0
1646
0
1402
0
1650
1215
0
1650
1357
1246
1650
1215
1264
1330
1425
1646
1526
1665
1526
1665
0
1482
1646
0
1466
808
1646
0
1375
1646
1521
1291
1665
500
1526
1665
1671
1650
1665
1313
1343
1500
1646
1246
1646
1545
1386
1650
1264
0
1671
1215
500
1650
0
1650
1650
1521
1665
1665
1521
1413
1665
1503
1671
1646
1650
1375
1526
1650
518
643
609
643
821
591
821
821
66
821
0
35...

result:

ok 300 lines

Test #4:

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

input:

3
100 259
62 44 8 1
26 69 30 1
37 34 280 1
36 8 80 1
12 47 2 1
78 98 17 1
35 16 914 1
91 75 7 1
80 76 943 1
93 45 3 1
51 100 518 1
26 59 146 1
76 73 231 1
23 73 11 1
64 10 858 1
51 54 7 1
51 86 696 1
59 40 150 1
17 20 64 1
60 43 16 1
78 7 926 1
46 2 440 1
26 82 922 1
32 12 46 1
31 72 756 1
64 70 876 1
68 8 478 1
33 67 20 1
82 69 641 1
96 17 166 1
62 87 912 1
61 18 58 1
60 70 921 1
72 2 12 1
98 42 900 1
77 64 481 1
24 21 1 1
39 43 519 1
88 67 353 1
43 17 1 1
45 12 67 1
37 56 1 1
47 45 701 1
3 14 ...

output:

1007
944
739
905
1286
1018
1001
1260
1262
1035
1262
905
993
1015
1266
1281
779
992
460
1281
739
759
1252
795
0
992
1004
1281
1260
1286
1286
1247
1266
1252
739
1262
0
0
1260
1262
0
836
1001
1053
1012
455
1028
1286
1281
0
1004
1262
1286
992
992
1036
1016
895
930
1007
1286
1281
1286
1063
1252
1004
985
1260
0
1001
1281
1286
1028
1286
1070
1266
0
1286
993
930
1247
0
384
1281
1260
760
0
1262
1012
1281
1260
1015
992
1035
0
972
0
717
1286
1262
1286
993
1252
821
993
887
0
1001
985
585
1266
1286
1266
1286...

result:

ok 600 lines

Test #5:

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

input:

3
1403 4000
659 1257 556 1
428 883 77 1
398 429 623 1
934 998 916 1
408 1318 15 1
595 299 249 1
1243 483 668 1
335 1229 560 1
1357 697 607 1
91 555 4 1
131 508 847 1
591 254 219 1
1004 1319 11 1
209 78 299 1
328 532 21 1
1001 1215 12 1
768 981 762 1
1316 254 126 1
584 1338 583 1
125 869 29 1
745 330 614 1
1023 657 221 1
287 677 6 1
1278 213 28 1
1107 844 105 1
150 721 166 1
728 915 345 1
633 1208 20 1
1168 635 76 1
1322 685 864 1
517 571 10 1
505 1349 480 1
1010 1357 281 1
789 1135 211 1
1379 13...

output:

4637
4318
4318
3466
3860
4318
4171
3728
1452
2474
4098
3412
4033
0
4552
3755
4637
4222
4222
4098
3702
3567
0
3961
0
4249
3738
0
2807
4108
3542
3399
3793
3942
0
3876
2806
0
3779
4108
3414
4108
3627
3648
2792
0
3961
2948
0
4015
4222
4108
1655
0
4108
3953
3658
3890
0
3690
3942
3660
3736
4015
4108
3937
4108
3279
3922
0
3775
0
3764
4700
3606
0
3621
3953
3260
4108
3706
3543
2963
3580
0
3697
4318
3714
3720
4134
3876
4637
3569
4156
1357
3247
0
4376
4171
3890
4015
3889
4222
4015
4318
4108
3913
3284
3992
...

result:

ok 6000 lines

Test #6:

score: 5
Accepted
time: 569ms
memory: 46728kb

input:

3
134023 400000
106936 27428 617 1
31553 30342 971 1
19790 1355 127 1
49584 42179 26 1
28910 65772 18 1
48591 55180 17 1
4998 88813 195 1
82176 121958 759 1
21077 25885 341 1
120910 35270 883 1
27537 33116 20 1
78351 18357 6 1
101608 66216 426 1
30213 43293 998 1
37468 49783 586 1
103877 17557 19 1
34588 15648 165 1
10993 110356 4 1
47325 129693 211 1
60552 121107 19 1
44137 82698 92 1
129771 84343 1 1
55365 107619 41 1
13723 53358 43 1
16507 127230 564 1
106910 86592 11 1
4489 24325 124 1
18629...

output:

31014
31770
29737
32596
31117
0
31268
32495
30147
32871
30756
31980
0
31998
32693
26033
32417
9337
31438
32177
32641
31414
31804
33026
32575
27777
0
26698
32652
31867
32450
32271
32652
25847
32652
32302
28402
32177
32302
32197
31661
31799
31713
31814
32107
27295
32565
32250
31712
31125
0
32624
30224
32218
32652
30917
31446
32222
32238
32652
32652
32134
32238
22817
31152
29652
32252
32899
32520
31713
32609
32207
32117
31540
31278
32261
31221
32166
32109
0
31574
32016
0
31500
31169
32591
32707
0
3...

result:

ok 300000 lines

Test #7:

score: 5
Accepted
time: 4ms
memory: 24220kb

input:

3
1500 1499
1263 1264 197 832549205
1407 1408 695 932716365
1146 1147 40 750669441
1386 1387 484 927439941
1178 1179 83 778216556
241 242 317 128333415
1189 1190 759 779845130
1447 1448 288 967694365
1041 1042 783 693510784
913 914 798 601420727
1359 1360 840 901837603
1225 1226 191 800290452
998 999 346 666460632
151 152 673 86239994
188 189 607 99508497
776 777 508 509906730
1183 1184 703 777101314
1194 1195 858 782489948
533 534 717 339215768
573 574 228 359309109
53 54 177 25851851
587 588 7...

output:

149260
464744
481512
389212
287741
237840
59609
156654
208739
107460
565246
334656
43465
456781
367213
544844
636763
109052
55085
595734
355225
256368
328550
69613
315734
255641
36508
628714
690980
222717
55085
675231
499689
124300
234411
642017
179131
115720
326655
500542
138109
288098
524140
556204
204318
411843
295102
544844
179370
94149
79890
440520
39933
376944
436863
673439
218926
459360
590163
493799
391956
474560
39022
630144
301540
696515
396708
446177
524938
489291
369322
141742
227178...

result:

ok 6000 lines

Test #8:

score: 5
Accepted
time: 4ms
memory: 22276kb

input:

3
1500 1499
214 215 746 103777342
1305 1306 809 863481069
780 781 193 489096281
1380 1381 333 918631020
1299 1300 53 866441833
981 982 823 625528911
606 607 551 354810974
345 346 910 191333196
1475 1476 254 977255759
227 228 736 118721990
1378 1379 137 916242486
55 56 168 28186639
1338 1339 981 893765296
976 977 166 624928700
51 52 135 28040711
1294 1295 466 856589397
1436 1437 954 952462499
1114 1115 561 733343387
1425 1426 268 943910965
1285 1286 66 854014427
900 901 426 568828927
117 118 87 5...

output:

159954
339343
458570
458570
203878
580405
621372
93231
58933
175182
110766
662839
79318
248759
391633
98798
29686
79318
430391
119721
490097
329847
642364
1382
203878
462322
704124
276766
453424
556535
557525
557525
672166
454002
747531
342380
616501
438728
250858
632594
222786
545457
240393
347834
54452
33642
218408
625056
615985
398654
85310
557517
512427
206314
359697
198142
742955
202889
159954
374141
173759
370350
82844
117252
1564
393755
720193
363213
54452
706555
82844
591652
66085
310101...

result:

ok 6000 lines

Test #9:

score: 5
Accepted
time: 3ms
memory: 24192kb

input:

3
1500 1499
186 187 314 94742289
75 76 261 39423111
1034 1035 125 648876320
1428 1429 832 941472266
1181 1182 504 752620972
342 343 486 178026302
440 441 192 240994251
1431 1432 552 945810062
1229 1230 159 790119569
1194 1195 565 761837664
113 114 256 55257526
636 637 238 352763203
1213 1214 756 781259147
389 390 910 209330228
127 128 943 58044293
231 232 100 112863638
949 950 718 580586051
1348 1349 89 872280572
163 164 391 82456947
911 912 718 558685938
657 658 115 375442508
696 697 660 402372...

output:

569689
312985
696132
60974
688719
393018
501235
488432
614064
271703
137383
250965
154888
211437
738940
518300
108142
57565
443490
192843
526972
85447
404013
345230
485990
665361
401934
391877
702266
638461
87637
493465
152001
6298
716651
102922
171244
398821
332876
377487
139973
349964
583015
580747
455812
624945
336871
111426
482225
726320
537396
156411
498276
443490
176121
642295
116315
264410
511491
319470
139973
490034
82865
87637
377487
658924
381082
95889
324207
0
132415
181207
735444
440...

result:

ok 6000 lines

Test #10:

score: 5
Accepted
time: 491ms
memory: 46600kb

input:

3
200000 199999
168039 12763 765 279320236
183939 16430 198 6881839
122193 47956 163 21807713
67770 169599 261 994936289
74818 123071 837 825259015
150448 32275 987 90179474
155426 115119 567 807410643
143919 114116 968 915726797
92951 9762 998 671084406
150297 117878 862 107998837
91701 134269 653 404819131
82555 190330 823 297893845
39841 188856 510 934009036
191841 92733 196 913156032
122647 134739 983 922842709
21084 43010 857 587778158
105052 135029 834 402783372
87239 19628 388 886426963
1...

output:

65779635
80678744
63515461
86227552
74769861
52122522
450819
89491882
86315837
5026098
38465492
54922440
81958976
80460791
93084090
4505293
11390406
62027241
43923829
80153947
1425999
41017046
89392328
34047372
39431143
14680982
43791379
60145739
13719811
77415622
85100892
91377866
87387701
24532016
78168544
98549288
81792790
85600797
24305318
21401985
77729113
65083250
87381568
90122272
10140657
99541977
60806601
37869423
59265991
37044860
55077535
56958690
18707008
60138160
36322603
31885876
9...

result:

ok 300000 lines

Test #11:

score: 5
Accepted
time: 509ms
memory: 46392kb

input:

3
200000 199999
176394 15779 785 127180026
118840 52233 628 69674288
1971 33381 302 757977279
72869 125444 355 183017412
104923 147605 520 839789866
124478 39387 865 582607027
155179 30904 563 287043678
62654 32772 741 221773407
175009 23990 438 117663422
177376 176873 136 848504696
57250 16505 54 848194556
119446 44404 356 404914843
197105 169891 19 26159814
141480 145703 205 907229963
117008 17929 383 637585429
172025 98335 403 466342380
42181 13391 117 452502150
167903 155669 169 50156734
157...

output:

27739808
89958497
74839886
41091196
40434595
81500937
37903685
94813799
88772134
64079457
7227617
82050147
53862990
27122905
3702939
66860503
19384105
63627827
85272577
78259960
51490641
87930052
70169237
64794654
4108403
3063959
66258350
22170687
53361620
56815550
92326958
76943918
5643824
61492738
77345846
1036377
96761015
76237558
68610473
39161277
7459657
93156755
51175154
41633142
34454570
69675299
31623262
11114351
31531528
24525166
35357143
34925810
69636040
16549343
35194121
56975761
333...

result:

ok 300000 lines

Test #12:

score: 5
Accepted
time: 711ms
memory: 45696kb

input:

3
134023 400000
67041 63272 992 180592857
41473 75825 108 301222188
114213 118633 12 580124132
20125 31290 30 519396153
90723 84443 189 316168642
84070 23184 683 111413871
112204 69103 389 388055662
115520 39583 310 273512441
105629 49771 973 81918254
112276 117987 26 749496507
121962 108299 838 256651321
9191 46621 9 703764113
51990 25154 725 149888501
276 9096 614 43477384
4576 4639 476 15836274
26575 47700 71 482820625
28566 53995 760 187131349
47450 85467 18 579982415
71215 83744 968 1169342...

output:

0
0
0
0
32038
0
0
28793
33179
32743
0
0
32249
0
0
0
0
11485
23537
29633
0
0
23977
33163
32754
0
32542
32596
33179
9635
0
21084
0
33521
0
0
0
15299
0
16912
33110
33179
0
15557
33214
32824
32779
31244
0
0
32507
33110
0
33110
0
0
32919
33110
0
32830
0
0
0
0
0
0
33179
32463
0
0
0
0
0
0
0
0
33110
0
25266
32054
32421
32626
32522
0
14045
0
33110
0
28360
0
0
0
0
0
0
32626
33485
0
33889
32649
0
0
0
33110
32519
21851
0
0
0
25727
32542
0
9838
32366
32830
32857
0
0
0
21484
0
0
0
23281
0
32885
0
32626
27248
...

result:

ok 300000 lines

Test #13:

score: 5
Accepted
time: 688ms
memory: 45632kb

input:

3
134023 400000
58760 3502 768 215875099
107385 86405 15 527479997
132742 112734 946 444077360
17162 37315 564 392834909
112439 74725 25 747453202
132349 88516 327 84395270
73108 131771 99 18974938
109915 50777 727 263001501
62336 37521 630 149446391
41770 2858 621 21949981
130072 108091 323 422930213
77728 125249 240 397132970
105223 1115 30 545916939
89433 87684 736 150380028
92980 23362 34 64559933
34447 31583 60 53821405
99084 71004 411 490695302
21761 91292 239 252590996
42268 77365 604 366...

output:

0
23801
32156
21200
16692
32317
16404
32031
16386
10568
31863
24877
3114
0
0
32444
0
12954
32551
32436
32317
0
32098
0
0
0
0
32272
0
0
0
0
32018
19115
0
32001
0
31863
0
0
10177
0
0
32551
7618
0
32566
0
0
32101
32264
21200
32264
0
31812
0
31824
19647
32436
32318
0
0
31965
0
0
0
0
27708
27186
0
32219
32408
16224
0
0
0
0
22632
31592
0
21710
9872
32207
0
32444
0
24024
0
0
0
0
0
0
0
0
0
0
0
0
0
0
16224
32249
22690
18795
32253
24324
14702
32551
24045
31863
25527
0
0
19768
0
5857
0
0
32117
0
0
0
32077
...

result:

ok 300000 lines

Test #14:

score: 5
Accepted
time: 684ms
memory: 45796kb

input:

3
134023 400000
15491 25039 962 444781241
43770 90154 968 416678205
19896 66733 917 208667421
15023 2102 692 444508565
74033 113231 3 504471242
94078 25801 8 624427171
102961 120670 491 241484370
78528 3616 27 586135212
107319 5083 876 40723199
28998 77345 384 304581393
116304 47118 591 153577459
81938 82237 24 584099134
63207 9895 844 214142975
34836 23494 13 524429058
56809 49562 30 496295149
73773 83563 27 658830198
47441 12771 22 618219271
31014 105503 218 402901217
128338 114946 784 4609297...

output:

11811
0
0
0
0
0
0
0
31726
32654
0
0
32091
0
25154
0
0
32174
32253
27468
32506
0
0
0
23388
0
28400
0
0
32072
0
0
0
31788
20395
0
32174
6679
0
32099
8633
0
32253
29108
0
26922
0
0
31977
32304
15748
0
0
0
17651
0
21759
6341
0
0
30439
0
32282
9284
31696
3882
31834
31919
0
31722
32286
32654
26619
32174
32223
0
0
0
25506
32174
21410
0
0
31893
0
0
0
0
0
16990
31917
31966
18628
0
0
0
31757
31917
31442
11943
28091
0
32002
0
0
32247
0
0
32654
32253
0
617
0
0
32174
0
0
32223
32174
0
31896
0
0
26707
32174
0...

result:

ok 300000 lines

Test #15:

score: 5
Accepted
time: 4ms
memory: 24108kb

input:

3
1403 4000
63 230 9 792459870
250 10 521 435710193
186 75 483 41567023
185 1006 566 219013432
1148 740 142 41210356
486 1050 48 488430239
1218 60 5 939467812
369 1002 373 377523109
877 1206 29 656561482
980 659 81 342719745
544 17 958 234525425
880 1010 85 63567532
579 238 394 313448548
631 102 8 668804498
561 880 385 150470611
1266 630 945 210718019
324 383 24 756894321
641 745 593 30063015
122 408 12 843993209
152 398 8 606161684
1201 611 49 29305336
85 1248 586 250152778
983 510 116 49837597...

output:

4658
3980
3580
0
0
3866
4596
0
0
0
4692
0
4765
0
0
3523
0
0
5002
0
0
0
0
0
0
0
0
0
0
0
4213
0
3146
0
0
5330
0
0
3029
0
4667
0
0
0
3779
5002
4911
0
0
0
4915
5330
3184
3924
4665
0
4911
0
1069
0
4692
5222
3712
4596
0
0
0
5269
4834
0
5002
0
4692
0
5079
0
0
4915
4054
0
4803
0
4213
4911
0
4332
4739
0
4596
0
4568
4803
0
4946
0
0
4632
0
0
0
4596
5002
4669
0
4803
4900
4615
4832
4834
0
0
3376
0
0
3383
4738
0
3052
0
0
2931
5079
0
0
0
0
0
5002
0
4658
0
4915
4803
4737
0
5330
0
0
0
0
0
3580
0
0
0
0
4665
4803
...

result:

ok 6000 lines

Test #16:

score: 5
Accepted
time: 4ms
memory: 22144kb

input:

3
1403 4000
65 36 108 94567299
497 73 930 399127210
814 128 811 105804086
300 479 8 925063872
644 583 749 61035098
769 1221 9 756940473
129 1005 650 421450316
434 116 793 38919578
420 253 20 693812030
313 170 12 810090183
1296 689 837 148940335
32 491 5 909075814
720 1358 30 797814306
661 572 954 359826595
806 1213 87 62828210
690 746 26 790233211
226 1329 19 664498987
491 1033 347 282010328
385 1304 782 271616856
305 1117 466 423712832
316 304 24 936634212
1043 1016 395 166215119
1167 292 504 3...

output:

5416
0
0
0
2894
0
0
0
5135
0
0
4917
0
4849
0
5229
0
4703
0
4849
5448
0
4703
0
0
0
2884
0
0
0
0
0
0
0
4931
5416
0
0
0
5442
0
4982
5503
5029
0
0
0
0
0
0
0
1967
5510
0
0
0
0
0
4856
5134
5135
3546
4703
0
0
4227
0
3667
5083
0
5154
0
5416
0
5154
0
4931
0
3715
5135
0
2932
0
0
5315
0
0
0
4672
5229
0
0
4014
4982
4849
2512
0
0
4128
0
0
5229
0
5229
0
0
0
0
0
5135
4982
0
0
4982
0
5175
0
4271
0
5005
5229
5229
0
5013
0
4277
0
3073
0
0
0
0
0
5229
4982
4014
5425
5503
0
0
3427
0
1920
0
0
4303
0
0
4703
4775
5442
...

result:

ok 6000 lines

Test #17:

score: 5
Accepted
time: 716ms
memory: 45620kb

input:

3
134023 400000
124828 37415 961 94076145
12469 128238 20 641194816
130567 15737 167 118907136
131297 6336 25 524919668
116982 130433 24 756819767
33316 74251 964 98831248
67280 6664 493 47288237
119344 53718 25 275115234
123245 128903 701 193512252
67851 82761 537 434699228
105776 133640 27 740920781
122112 71030 53 74222422
69568 68687 97 130690742
36717 59022 4 533056757
13090 34595 382 400589434
64160 77122 9 668982363
69401 19631 131 111131893
58915 66713 15 638932926
78242 123313 165 52356...

output:

0
30691
29617
2222
32343
0
0
28179
0
0
0
0
6198
32314
32444
29779
0
0
0
0
25794
0
11709
0
32159
32200
32347
0
0
0
10133
23825
32589
27915
0
32200
28733
0
0
0
32776
32589
0
32432
14246
0
0
0
0
32325
29700
0
0
0
0
32347
0
0
32334
32421
0
0
0
27370
0
0
0
0
16208
0
32999
31749
32578
31196
0
32347
11718
6935
0
0
0
31505
32159
0
32502
32252
32552
32298
31901
24691
0
0
32843
0
32325
26954
0
31563
0
0
10986
0
32095
32640
32325
32089
31518
31606
32870
23188
0
32089
31621
0
32159
0
8633
0
0
11064
32229
0
...

result:

ok 300000 lines

Test #18:

score: 5
Accepted
time: 693ms
memory: 45620kb

input:

3
134023 400000
93897 30157 297 268792428
132559 55246 25 703055243
78340 95366 168 238768162
14465 13469 535 64125745
18273 112312 807 440189389
47009 122943 109 38388604
132558 29279 424 51116970
7442 50269 90 474483522
77415 104844 996 533591796
65098 57707 23 806817064
20920 120036 439 419244143
53733 23292 16 592139055
89083 50810 105 10276521
63079 58064 12 746540993
98823 38459 405 8840699
19677 74773 918 234297529
5963 11787 891 431860287
35214 131556 793 273110906
51476 103214 413 15631...

output:

0
27460
0
0
0
22533
23617
0
0
32985
0
33117
0
11343
0
33092
7266
0
26670
29528
0
8425
32658
19908
32658
0
0
0
12939
10085
0
19388
32807
0
0
0
0
0
0
0
33232
0
0
33098
0
0
0
0
30860
32892
23536
0
33415
32985
0
31706
26670
32101
0
31715
0
28821
33775
32686
32829
22024
0
10741
0
0
0
33869
32658
33287
0
0
0
33548
32829
0
0
10071
32693
0
33445
33123
0
0
33365
0
33869
21116
32693
32944
0
33659
0
0
19999
32935
0
0
3362
32892
9204
0
0
32941
15253
0
32829
0
32982
0
0
0
33012
0
32693
32925
32658
32658
0
32...

result:

ok 300000 lines

Test #19:

score: 5
Accepted
time: 930ms
memory: 45628kb

input:

3
134023 400000
8769 5728 809 19387679
57063 91233 797 253655114
130290 72440 967 32496257
91843 24946 657 501122161
49847 43516 108 85279737
9697 18896 695 273697557
46300 88649 364 14955048
20408 46673 788 79075025
105581 10860 9 806715014
35442 17634 946 64078166
74381 121008 17 680814138
33256 62273 811 298811205
114706 100760 24 630364240
9808 118316 11 174026107
116510 100556 21 634902931
40403 54556 6 625100960
48659 81341 60 121879268
7618 115934 21 789421818
9032 101519 958 32172187
977...

output:

0
32798
32668
32591
0
0
28226
0
0
0
33669
0
0
0
0
0
0
0
20127
33126
14909
33577
33552
0
32990
0
0
0
0
12484
0
12868
28263
0
0
15117
32595
32732
0
0
23781
0
32963
0
32742
7251
0
29789
21158
0
33165
32958
32302
0
17344
0
0
0
8231
0
33816
0
33323
32705
0
0
32731
0
25503
0
32490
20268
0
30236
32731
32427
33264
14201
21336
0
0
8502
0
14777
0
0
0
18861
33816
0
0
26797
0
0
22690
0
32882
0
0
0
0
0
0
0
32948
32881
0
31144
0
33075
0
32668
0
0
32595
17811
32584
0
0
32968
0
16478
20648
0
0
32674
33196
33080...

result:

ok 1200000 lines

Test #20:

score: 5
Accepted
time: 966ms
memory: 45612kb

input:

3
134023 400000
102887 57011 25 621065092
104930 92183 31 572560306
118658 64299 848 501142203
131931 87158 65 200398712
132887 33804 15 654384648
46738 88508 15 616094154
113013 63932 174 188235708
51888 86629 17 551871892
12748 98037 218 210399397
85016 84392 818 377250424
126145 20672 857 133646762
59313 115655 910 329104390
11755 104299 799 56635379
67349 19877 211 84897752
61994 106638 603 68758554
11883 132582 22 517110064
65465 121735 957 52044840
45157 88661 464 246491243
19520 13042 13 ...

output:

0
0
0
0
5175
11407
0
33296
33025
32977
26332
0
33433
0
0
0
32906
0
32894
33433
0
33128
0
32346
0
0
12845
33180
33576
0
32852
0
21913
0
33251
22015
33233
33233
0
32906
32716
8498
0
0
33109
0
0
0
0
15322
32427
32986
9676
0
32592
0
25916
32959
33587
32741
0
25637
0
0
12540
26719
0
33080
31887
0
14952
32628
33169
33040
0
33251
33069
32906
0
33251
32832
32906
0
0
21023
0
0
0
0
0
6949
32906
0
0
33378
0
31367
22205
32981
0
11597
0
0
0
0
0
32982
0
32906
32906
0
33446
0
33251
22361
32299
0
0
0
0
32865
33...

result:

ok 1200000 lines

Extra Test:

score: 0
Extra Test Passed