QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#166843#7074. The Answer!ucup-team004#AC ✓245ms4012kbC++204.5kb2023-09-06 19:17:172023-09-06 19:17:18

Judging History

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

  • [2023-09-06 19:17:18]
  • 评测
  • 测评结果:AC
  • 用时:245ms
  • 内存:4012kb
  • [2023-09-06 19:17:17]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

constexpr int N = 1E5;

bool isprime[N];
std::vector<int> primes;

i64 mod(i64 a, i64 p) {
    if (a < 2 * p) {
        return a;
    }
    i64 v = (a - p) / p;
    a -= v * p;
    return a;
}

i64 mulmod(i64 a, i64 b, i64 p) {
    if (b == 0 || a <= 2 * p / b) {
        return mod(a * b, p);
    }
    i64 res = a * b - i64(1.0L * a * b / p) * p;
    res %= p;
    if (res < 0) {
        res += p;
    }
    res += p;
    return res;
}

i64 power(i64 a, i64 b, i64 p) {
    i64 res = 1 % p;
    for (; b; b /= 2, a = mulmod(a, a, p)) {
        if (b % 2) {
            res = mulmod(res, a, p);
        }
    }
    return res;
}

using Matrix = std::array<std::array<i64, 2>, 2>;

Matrix mul(const Matrix &a, const Matrix &b, i64 p) {
    Matrix c{};
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                c[i][j] = mod(c[i][j] + mulmod(a[i][k], b[k][j], p), p);
            }
        }
    }
    return c;
}

i64 fib(i64 n, i64 p, i64 f0 = 0, i64 f1 = 1, i64 x = 1, i64 y = 1) {
    Matrix m{x, 1, y, 0};
    Matrix a{f1, f0, 0, 0};
    for (; n; n /= 2, m = mul(m, m, p)) {
        if (n % 2) {
            a = mul(a, m, p);
        }
    }
    return a[0][1];
}

i64 exgcd(i64 a, i64 b, i64 &x, i64 &y) {
    if (!b) {
        x = 1, y = 0;
        return a;
    }
    i64 g = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
}

i64 inverse(i64 a, i64 m) {
    i64 x, y;
    exgcd(a, m, x, y);
    x %= m;
    if (x < 0) {
        x += m;
    }
    return x;
}

int get(int x, int y, int g, int a, int p, int e) {
    i64 m = 1;
    for (int i = 0; i < e; i++) {
        m *= p;
    }
    i64 phim = m / p * (p - 1);
    a %= m;
    
    i64 Fx = fib(x, phim);
    i64 Fy = fib(y, phim);
    i64 Fg = fib(g, phim);
    
    i64 ax = (power(a, Fx, m) - 1 + m) % m;
    i64 ay = (power(a, Fy, m) - 1 + m) % m;
    i64 ag = (power(a, Fg, m) - 1 + m) % m;
    // std::cerr << "x : " << x << ", y : " << y << ", a : " << a << ", p : " << p << ", e : " << e << "\n";
    // std::cerr << Fx << " " << Fy << " " << Fg << "\n";
    // std::cerr << ax << " " << ay << " " << ag << "\n";
    // std::cerr << "t : " << t << "\n";
    if (ag != 0) {
        i64 m1 = 1;
        while (ag % p == 0) {
            ag /= p;
            m1 *= p;
        }
        Fx = fib(x, phim * m1);
        Fy = fib(y, phim * m1);
        Fg = fib(g, phim * m1);
        ax = (power(a, Fx, m * m1) - 1 + m * m1) % (m * m1) / m1;
        ay = (power(a, Fy, m * m1) - 1 + m * m1) % (m * m1) / m1;
        ag = (power(a, Fg, m * m1) - 1 + m * m1) % (m * m1) / m1;
        i64 inv = inverse(ag, m);
        return ax * ay % m * inv % m * inv % m;
    }
    i64 t = fib(g, m, 2, 1);
    i64 v = g % 2 ? 1 : m - 1;
    return fib(x / g, m, 0, 1, t, v) * fib(y / g, m, 0, 1, t, v) % m;
}

void solve() {
    int x, y, a, m;
    std::cin >> x >> y >> a >> m;
    
    std::vector<std::pair<int, int>> fac;
    int tmp = m;
    for (auto p : primes) {
        if (p * p > m) {
            break;
        }
        if (tmp % p == 0) {
            int e = 0;
            while (tmp % p == 0) {
                tmp /= p;
                e++;
            }
            fac.emplace_back(p, e);
        }
    }
    if (tmp > 1) {
        fac.emplace_back(tmp, 1);
    }
    
    int n = fac.size();
    
    std::vector<int> v(n);
    int g = std::gcd(x, y);
    for (int i = 0; i < n; i++) {
        auto [p, e] = fac[i];
        v[i] = get(x, y, g, a, p, e);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        auto [p, e] = fac[i];
        int pe = 1;
        for (int j = 0; j < e; j++) {
            pe *= p;
        }
        // std::cerr << v[i] << " ";
        ans = (ans + 1LL * (m / pe) * inverse(m / pe, pe) % m * v[i]) % m;
    }
    std::cout << ans << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    std::fill(isprime + 2, isprime + N, true);
    for (int i = 2; i < N; i++) {
        if (isprime[i]) {
            primes.push_back(i);
        }
        for (auto p : primes) {
            if (i * p >= N) {
                break;
            }
            isprime[i * p] = false;
            if (i % p == 0) {
                break;
            }
        }
    }
    
    int t;
    std::cin >> t;
    
    while (t--) {
        solve();
    }
    
    return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3700kb

input:

3
3 3 3 97
7 3 2 1901
6 12 3 100

output:

1
1761
98

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 104ms
memory: 4012kb

input:

10000
144272510 611178003 910025047 90419633
273878288 126614243 532069374 713180443
507069465 699642631 407708741 319897477
100780964 523832097 30537866 613853399
464680098 652231582 818592001 3497861
747144855 478230860 286070256 350323037
634746161 109765576 968000366 494476781
32845752 23968185 ...

output:

12358461
458245486
281357365
132976954
272470
312228465
167259963
630118388
229999939
590321282
447573918
39328575
693482753
416155988
85470325
410367926
656530932
35939208
395242216
429467226
306031639
101555997
525413089
126060782
809060867
556259277
67227456
5341844
572000084
46237958
7476350
262...

result:

ok 10000 lines

Test #3:

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

input:

10000
926756583 911666163 60821575 133776389
91130616 387682510 897210089 254849393
790241759 868616384 719217539 479273947
270135511 650627596 227968215 977893339
38369566 624063061 731582525 237849289
462428005 685553380 422651570 812994467
399496699 584305649 477758548 801102793
288021300 9676645...

output:

132953208
92334672
388622582
858596109
61553872
357010026
164428755
35007079
451309954
776150197
192224138
347153906
612802975
732989611
447066112
451179472
515939544
417490522
520532402
174530211
335655687
426943690
212829965
153596514
129191243
155923744
89893378
753666836
683444968
82570169
13191...

result:

ok 10000 lines

Test #4:

score: 0
Accepted
time: 104ms
memory: 3980kb

input:

10000
255512576 636343333 584461682 193903799
397236330 983488254 648554207 754233121
671862058 623685184 70461078 976033013
14139018 975836328 899325578 746048189
278479250 591400508 251710956 290790971
770031842 504941598 580966285 881253449
511480365 426420001 686294186 225524833
249024354 681676...

output:

153680004
194575190
259097627
422447791
172071594
195804616
145687130
488222302
83293641
26481088
86598392
140548982
511801353
743621109
489617513
258285975
673239741
311713677
536916920
115724141
234294050
25073073
159805092
758787854
33252372
364075669
77700212
474267711
83585778
22246388
54212945...

result:

ok 10000 lines

Test #5:

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

input:

10000
253454710 325664384 110873681 624184877
514191761 166400215 96844404 95554957
21278533 431205070 590015737 448544143
859479168 821587095 63286545 339319553
558710038 576255772 386910028 427851887
837245413 185397123 887946706 156137981
281019257 230210707 995969378 35577769
890046124 687934189...

output:

123948689
16733075
84724740
308500635
111279000
76580794
20631637
334231626
53490590
511061786
357944163
343563370
146623051
582535453
149957280
162495154
69015331
68387355
98516337
27474980
311193573
94813605
43018907
214366540
246323668
771851545
271406564
83638009
836771333
154994537
719006500
41...

result:

ok 10000 lines

Test #6:

score: 0
Accepted
time: 104ms
memory: 3716kb

input:

10000
668835602 274281999 796587718 562170509
853832590 741361656 903665516 848321917
31144124 902316928 500058518 383051881
696831126 55677007 967434542 235344899
121553982 399210080 503759048 378906049
408835700 583858779 109594177 922277977
267716823 14081255 785202536 330878447
438248860 3000919...

output:

333987363
23148141
42809809
120520088
377695140
552410372
71469455
580367006
54213217
248135945
753141
2562656
319538386
69770320
529358735
635060710
87355023
784514953
300446382
109546037
124567733
123041650
161599393
116954657
408521965
478952546
272898737
536262741
594650011
84678998
225414232
23...

result:

ok 10000 lines

Test #7:

score: 0
Accepted
time: 105ms
memory: 3980kb

input:

10000
851842432 616134651 882666437 116991947
520801968 818424093 281013934 51576911
485027 156313202 711796013 943566643
504931657 815754556 789124432 586176103
342937749 826931359 23603992 421300631
524889318 861050198 212815683 653987573
977719989 578000830 579115744 137707901
207215936 604965555...

output:

51958273
25108497
224967586
56060115
269090090
432542840
9332613
261964628
23310860
45287147
130502071
299517965
144137454
141062631
310999514
14391229
296954472
189161231
8742336
82463535
404709258
290066559
142375945
341882154
672823519
156631436
730578903
701326929
621830611
194538173
7781740
116...

result:

ok 10000 lines

Test #8:

score: 0
Accepted
time: 105ms
memory: 4012kb

input:

10000
347712783 161973070 424038499 68409739
77777869 881836554 575498922 137707901
392655487 625763864 62375869 810120361
230530420 40260663 92385142 686712379
449008935 75006692 258509929 132464621
591682484 455824010 63569421 908054761
132931337 239701015 677229422 937567769
66423869 619659572 62...

output:

45404888
8589607
115827444
299541167
32933054
598411606
847091330
466210881
150912918
413269422
335304993
101383137
45020293
86806799
110022476
114378384
573040784
462335371
39791326
777649253
343321265
116921300
113868892
47538456
314125820
202955898
120532278
499833134
273847784
31394333
197190208...

result:

ok 10000 lines

Test #9:

score: 0
Accepted
time: 104ms
memory: 3776kb

input:

10000
243423565 397726714 403149883 187416311
207357418 756791415 47106764 123879683
146934069 265687734 871188132 808480583
224838995 430259339 689300987 42216827
492991123 523343995 486647245 614865271
531483617 615388204 206506288 635126101
96170358 520871605 251552037 27461653
752866761 28643937...

output:

106257109
45815988
305559300
16242900
509603087
198721561
11024924
183467122
462891675
172039398
496673722
109769606
23703475
206945188
1893400
35455374
46206768
88987050
119786111
519161935
789910471
131359426
780247941
478615835
282349194
321869868
253660523
3193675
321357556
448225837
30688318
11...

result:

ok 10000 lines

Test #10:

score: 0
Accepted
time: 105ms
memory: 3724kb

input:

10000
497150364 658434844 400940636 412366219
148755563 199871618 930563701 8960453
363274254 539858146 498017204 974372627
86774070 358655545 595243377 994665871
751724830 43911492 781990459 595860127
181907113 755356314 485453764 668204249
168746218 180848162 255663659 72926759
119129003 142190876...

output:

336352946
8564710
243301058
648359224
87663261
563301058
417332
299753201
520524178
32210702
317020726
105094790
311178425
41809372
5271848
259700945
2176969
95744356
830881795
231121129
32681627
5058337
237200232
133750461
108941981
194471803
815951
614326168
61488372
150263512
205641891
56631619
1...

result:

ok 10000 lines

Test #11:

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

input:

10000
613538869 34987949 460616116 768549833
620720815 15926218 221396288 735020327
873297047 527525519 884421821 429243509
701660786 870395297 172145179 48032629
559064470 526225391 352043376 110122429
268431885 800524666 387891127 63012197
451396978 923590881 149016473 971886623
381266059 40974630...

output:

469581130
148804879
50976681
35332427
3949371
54513736
940317054
333771274
619094011
240573261
47017717
25363371
33717935
127169331
38639330
405817078
506847297
27933399
209595916
116207739
36236694
33516156
551816260
15035695
432577362
493654864
18750292
577222578
37479310
9956454
90865745
27763690...

result:

ok 10000 lines

Test #12:

score: 0
Accepted
time: 104ms
memory: 4004kb

input:

10000
485738844 929583700 601151017 740123609
485151262 545290416 918198260 945011479
203905759 198277535 863281386 817708183
510846882 676331423 659333275 282019211
101064293 479525746 325874624 211694993
97356746 578417752 869449199 59065777
639345075 425373533 486499530 992801857
698008399 169107...

output:

398920261
135668295
28796032
69199245
131249875
52470456
615495706
5612151
60989606
24907512
129672212
21092623
373721965
69191808
54258068
187730471
127318906
399393854
71011246
28310557
470623
62944356
151555372
182334418
164894734
16722173
73930082
41460901
314744782
182553842
25663187
165527339
...

result:

ok 10000 lines

Test #13:

score: 0
Accepted
time: 104ms
memory: 3708kb

input:

10000
509566392 288831131 706055723 846672173
715552799 375579191 153215961 600306589
11661309 402389573 518222104 423681989
690854884 870104599 494255609 968991277
244431277 599352002 1888721 217260451
472505235 394766943 174333214 530991353
972781082 225755998 63262138 926203987
879201418 21435492...

output:

647223891
94530990
276686400
748623956
161236433
512070337
710026349
167755270
383248973
21721719
609302041
85508929
169293826
308136229
49742865
19682744
937559688
193489459
11839448
347010838
143941783
122490805
175054781
296372386
628199973
161233221
528727626
423095
37820312
11802102
443671836
3...

result:

ok 10000 lines

Test #14:

score: 0
Accepted
time: 104ms
memory: 3660kb

input:

10000
278108255 312198691 735890163 281242487
700090116 247560421 715411299 220143317
933329637 241766857 688322514 283771637
139815176 76049769 570594871 326363201
799607132 316385285 32284315 683260301
135610017 899426831 734712082 980796931
15496659 296177567 896010281 219373381
91215160 93553485...

output:

269976176
117727373
23531440
256534550
651738134
290482236
57931020
72193723
298722272
255117137
9837797
562024821
173494633
92285150
107267457
333300435
382671823
63901376
17837858
448389562
51782086
176821659
113119481
33091675
341816396
527814381
7812339
143898790
204388513
53663525
383977973
323...

result:

ok 10000 lines

Test #15:

score: 0
Accepted
time: 105ms
memory: 4008kb

input:

10000
114706270 661294586 754495458 843378827
265144710 291107757 789441797 393937387
312476050 788190244 78081439 713589889
325330861 501027635 734789726 625196629
422849860 834852080 976048861 175061057
282948622 239730166 935129292 491472659
384434657 867423188 279704872 565598717
863590455 67938...

output:

266183320
344375868
74843168
587662035
39498120
26358220
161954647
640800403
8780279
100389671
4139511
134090262
920615307
17823056
53429711
140706468
227989130
563437848
248684284
61465687
5441482
105061120
72746010
121831003
350986157
125248179
274410361
84322615
10238955
173264880
169665988
82471...

result:

ok 10000 lines

Test #16:

score: 0
Accepted
time: 104ms
memory: 3768kb

input:

10000
224390935 12514132 559859752 50689711
169664865 980341147 256670588 23199721
59000193 944346557 864327266 220337251
920564375 746011409 394477355 367858367
125767204 363008230 500817785 557538181
301272295 421202778 282831535 538625443
245467820 921095569 221684688 556529863
856433649 33647933...

output:

40050317
13902832
82790980
303909955
307313412
405865395
430307492
265497225
774960
478215022
799974500
82576041
78346813
53957083
103625592
360936562
4623166
152266841
83167098
479617800
725940334
335741591
636050034
446734223
6728533
256753054
63683046
136192878
404647394
246199302
204848125
31709...

result:

ok 10000 lines

Test #17:

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

input:

4
15 3 1900 1901
15 3 38 19
15 75 7 11
3 3 3 2

output:

305
1
1
1

result:

ok 4 lines

Test #18:

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

input:

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

output:

1
0
0
1
4
0
1
4
5
1
1
1
1
1
1
5
1
5
1
1
1
1
0
5
7
1
6
0
7
3
1
3
5
1
4
4
0
1
1
1
1
0
4
5
0
6
0
1
1
1
0
1
1
2
5
7
0
1
2
0
4
0
1
1
2
1
1
1
1
6
1
1
1
1
0
1
2
0
1
4
1
2
0
0
1
1
1
1
3
1
1
3
5
2
4
1
4
1
1
4
5
3
3
0
1
0
0
1
3
1
0
4
1
5
7
1
1
5
1
7
5
1
6
1
1
1
0
1
1
2
3
0
1
3
1
1
1
3
1
0
1
4
1
1
1
1
1
0
1
4
...

result:

ok 10000 lines

Test #19:

score: 0
Accepted
time: 17ms
memory: 3936kb

input:

10000
10 20 5 9
17 17 25 84
2 14 45 28
5 14 81 17
10 13 49 16
12 17 63 94
13 13 30 75
19 16 66 27
15 18 60 81
16 5 63 22
10 9 61 66
1 17 19 45
9 18 75 29
19 9 40 8
6 9 80 52
14 9 44 74
15 20 7 90
17 5 38 55
5 8 69 74
14 17 43 97
17 1 58 83
17 2 15 60
16 16 36 54
15 4 16 62
20 19 98 70
19 10 97 83
8 ...

output:

4
1
9
1
15
20
1
25
73
15
46
31
0
1
21
23
78
11
49
25
39
1
1
31
1
67
1
85
0
16
1
15
40
41
1
65
1
1
6
47
2
1
0
6
43
17
17
67
49
21
3
1
1
11
1
61
45
15
9
0
8
16
17
1
3
6
1
8
50
9
85
22
1
77
46
10
31
1
47
36
39
28
43
46
60
0
31
15
19
18
1
17
1
65
9
1
32
24
7
17
31
1
41
22
26
6
48
1
23
1
1
1
5
16
49
12
1...

result:

ok 10000 lines

Test #20:

score: 0
Accepted
time: 24ms
memory: 3708kb

input:

10000
20 23 320 431
4 33 336 405
24 34 732 789
20 2 244 378
8 19 123 579
31 13 391 783
25 40 383 143
19 17 935 190
26 36 901 4
27 22 525 788
8 34 331 436
34 14 796 20
11 9 699 144
13 9 670 769
6 14 774 243
27 2 45 228
3 15 435 501
18 20 985 164
39 36 305 282
5 32 661 352
24 27 287 324
11 11 815 486
...

output:

210
214
484
15
328
656
22
181
0
454
21
9
76
139
91
46
136
0
108
137
180
1
451
0
408
447
57
478
661
158
267
65
619
88
0
561
561
295
283
335
45
73
1
1
1
81
242
65
86
9
345
201
731
101
64
651
167
92
29
592
130
705
1
1
215
33
374
81
85
10
220
15
145
53
1
21
1
1
31
625
187
126
194
251
282
39
73
1
227
327...

result:

ok 10000 lines

Test #21:

score: 0
Accepted
time: 32ms
memory: 3936kb

input:

10000
3 79 7798 2751
6 51 6616 6731
37 41 2846 7639
11 2 2108 1446
64 66 3430 9116
73 6 6189 2308
56 53 9568 3414
9 78 9366 747
18 26 3116 5596
13 24 8668 7039
77 68 5350 680
65 43 806 3223
51 55 7802 5860
67 16 8076 1715
10 57 2016 8636
31 48 3723 2647
45 41 4906 2319
70 18 5026 1577
80 25 3350 413...

output:

743
3315
2504
451
2077
1912
3351
712
4197
1352
81
1749
233
1601
3097
2514
785
1210
3901
969
289
2262
1441
3703
2613
588
5225
1268
8227
294
5299
1
189
2661
2760
2737
145
8648
4417
2473
3910
1805
2737
2656
2238
145
1
1105
1213
331
1108
1709
1201
3487
1782
7090
705
4020
1
1547
112
4321
934
3661
533
155...

result:

ok 10000 lines

Test #22:

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

input:

10000
46 35 694509717 807859404
38 84 678466387 879448208
19 58 126875363 402284550
51 16 48424087 721256802
69 13 26538735 686229512
7 38 110346406 763084669
33 56 115156808 89489325
28 3 47797592 147378043
9 86 229995890 837523423
17 23 52505693 64041770
19 23 8129270 797061935
30 8 11205666 54367...

output:

402058735
522322896
364366573
285980874
226987256
174588713
608424
117458946
380993121
9919521
468469106
6572273
83311404
536589
431531483
56855557
5604469
257985393
270690637
146416763
5737585
99331923
715961213
445946624
20302726
256548177
194795468
407321001
706518999
21863320
56314633
406656081
...

result:

ok 10000 lines

Test #23:

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

input:

10000
47 72 783465493 90329871
72 31 161880635 146461032
93 1 455264764 861786592
19 71 587374405 130734539
76 24 772548145 270120120
94 2 222135216 307521143
7 85 789759359 817458158
83 35 417411793 327819442
34 5 700150192 459674673
19 58 933075592 143110734
10 51 113722835 617800351
60 41 8500012...

output:

45739458
20398896
78627757
68965916
250229736
144236495
17342765
86389103
83511647
100839263
18517978
503795411
260223900
23364125
69779025
444107338
11389246
152834549
166340822
261631575
137606626
48874298
9546057
129716065
813111894
277229643
681402100
126178345
636772009
147085873
248518929
3675...

result:

ok 10000 lines

Test #24:

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

input:

10000
95254 82410 198290364 415843935
65969 99574 394518785 230368149
8180 12824 652861604 887312945
80336 73818 698426803 317398171
87897 10412 187546094 340176736
63650 72630 236130106 100004375
92350 80155 840969735 308057957
35189 52539 974964744 287667522
53572 77000 96964318 36912232
21109 388...

output:

56239495
3965074
312799001
108034569
179058713
8872995
236536174
22494043
25635009
141149508
276489451
334276601
17066241
66953284
157816601
157841196
614329865
159396301
94168123
242689511
343597155
303687797
137017901
485535661
429475380
504313229
168800996
590737895
18734859
227095491
731797402
6...

result:

ok 10000 lines

Test #25:

score: 0
Accepted
time: 216ms
memory: 3712kb

input:

10000
808884265 484508056 11254757 261760957
311470278 240781140 857268509 461394566
462153789 60894983 360712082 517486155
380821401 476289288 468240978 373337024
166375993 492081972 488053059 828652872
187671108 70524856 216645534 346705814
689664723 706696754 829697805 117766959
320262068 5429841...

output:

33113093
272668040
68103
1439105
617296552
68163663
42063256
121023101
208318970
88016707
14026878
437213306
195937027
338981059
398180307
442192839
551355341
316046505
195376667
389843161
430063841
913521547
116781414
70115840
205561305
52456307
141073537
3157186
164971877
3922117
357968864
6344555...

result:

ok 10000 lines

Test #26:

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

input:

4
3 4 2 887
123 321 456 881
328 341 109 883
39 182 304 887

output:

21
603
518
773

result:

ok 4 lines

Test #27:

score: 0
Accepted
time: 223ms
memory: 3772kb

input:

10000
942711566 975368038 325534069 940504541
965675726 928778998 616156163 907503188
955189167 904605300 896370258 695645095
973053948 907129645 879188634 631568443
927296513 937717675 801669186 845123901
968669845 966253354 178219731 250925502
954215687 975721412 36001204 328322396
934219159 95076...

output:

482423785
80944525
120540975
22016148
567929476
234432091
24733073
380826691
36584369
461299970
91994076
277513751
60213988
186366106
51420755
179857949
107917055
20707921
375270942
745794647
78785581
748387596
91478897
566399358
16196017
44901328
112500581
249169306
333258883
142348528
38537827
517...

result:

ok 10000 lines

Test #28:

score: 0
Accepted
time: 223ms
memory: 3708kb

input:

10000
999992615 999999799 238062341 675111068
999999632 999997062 712199990 175590308
999992601 999993640 957114393 999425652
999996128 999998910 918412288 938273246
999999033 999997597 706379309 388324395
999993533 999995891 241541935 444337183
999995916 999998691 203443385 224270549
999999906 9999...

output:

131306941
34477677
195277246
369486483
214987725
252998782
141767434
442440469
437654177
672007477
300855128
165462353
42164034
183579097
744145861
162550795
91412205
15451866
21440623
9312641
392494
35050296
275814964
590274442
73560548
64352001
514256154
192850612
86896536
267169170
198126613
6110...

result:

ok 10000 lines

Test #29:

score: 0
Accepted
time: 238ms
memory: 3772kb

input:

10000
982736400 54426488 999997227 999992086
299389055 544228471 999997976 999998576
936403690 779823561 999997803 999995474
57150626 172735267 999997510 999996308
36587200 16074467 999995782 999991780
995618041 645529634 999991340 999995682
290900927 605338320 999999166 999993617
377700333 37072635...

output:

906893722
832669681
198987054
422964213
645404257
733287115
188622168
491213141
234078561
591745799
762741354
539610089
808834069
863063905
565202332
420403344
489194321
388542877
31107913
360856543
599000701
198235600
987825409
749921637
558937153
527076460
648993073
210368069
729996149
337146951
5...

result:

ok 10000 lines

Test #30:

score: 0
Accepted
time: 243ms
memory: 3772kb

input:

10000
929976938 960848221 990936899 905032793
941159526 967719614 962919326 961825341
936587638 928134431 920907804 977846440
986590654 937158700 997974219 921847066
972008616 926111178 939712952 970477643
975710912 931179714 920805005 998140732
928716400 918702557 995396739 943458482
915703691 9094...

output:

691449190
543129174
561530081
757996841
644412777
574966200
359255607
817082124
737507328
198515413
95391857
557024349
140362599
515617729
341887874
729356235
355132727
136983535
66970960
787961327
122602241
371208052
343778125
589124985
236981317
782967961
635075786
527337594
294074551
632036411
58...

result:

ok 10000 lines

Test #31:

score: 0
Accepted
time: 222ms
memory: 4004kb

input:

10000
999999757 999999857 539510442 515298265
999999383 999999508 753752167 220687673
999999305 999999612 171728063 516505403
999999735 999999886 422861866 389443047
999999228 999999604 875451757 836285177
999999828 999999577 209166337 29675756
999999132 999999054 420957162 122895138
999999602 99999...

output:

226084086
160585198
465300206
156471575
517307518
7355416
70926463
375073180
619427201
166263065
238000790
174820101
7067548
24933636
3449070
56977448
177964275
315765763
114744528
326459197
211777134
326865656
530941824
161412156
675081052
104933085
10082953
10587759
19225335
61833031
372023884
256...

result:

ok 10000 lines

Test #32:

score: 0
Accepted
time: 227ms
memory: 3788kb

input:

10000
829457269 143416913 502607372 769980958
599410560 960952482 696209882 505861682
845466550 333627088 702477496 468153472
576353723 464801810 309905296 127000576
718610435 305292094 684512924 87641144
801158758 754343171 455008888 191336320
685816571 743665405 796762410 143355352
607199022 49534...

output:

541828875
24178767
161189553
106029057
26597177
70247473
66466737
423015441
228082435
319548993
622453129
48130375
11528233
121118389
16436941
165511025
106041577
548372539
310796017
250983257
118720529
170670897
12854769
742285809
504019209
19420593
265680697
160868761
111558617
152500233
49208137
...

result:

ok 10000 lines

Test #33:

score: 0
Accepted
time: 240ms
memory: 3656kb

input:

10000
875857732 185149047 585973347 878906115
514370078 642805268 225410325 796774122
259839524 713059364 875403489 127992933
762623430 624251222 370238277 404053788
347413122 313681982 699167787 534263226
389103048 55611751 956225052 344760834
674108756 778611851 438288570 116979702
547439902 68502...

output:

582542356
158692495
2833867
144352048
479407750
50469877
99632191
70126966
10753513
13855690
284418922
128478793
163208890
8866381
18263227
682442389
364416733
332198851
527334361
73703947
174941749
427734505
381106360
535449847
718734001
315150418
287273533
324071953
3213271
659503891
56747329
6694...

result:

ok 10000 lines

Test #34:

score: 0
Accepted
time: 240ms
memory: 4012kb

input:

10000
807814179 269352287 279878606 356292034
653408950 918430928 590250824 338663712
177894914 822346677 899740058 45826368
459081399 451359744 36368478 225118539
256052841 131961683 240259550 843429125
878925997 127612299 53045847 306619404
148369833 880406751 829122965 707463025
92679954 82928201...

output:

203784855
328798225
15169617
53377093
235660726
56891908
139857751
29382400
572074921
290696951
686856961
19188548
158661168
95892337
315130596
122476861
53206504
398324800
557284921
238356451
228999001
41903464
524964637
330314257
29566282
527030091
34933753
19691904
1696833
284212345
210401605
736...

result:

ok 10000 lines

Test #35:

score: 0
Accepted
time: 245ms
memory: 3708kb

input:

10000
794721617 253081260 740406957 216934394
255884439 833565350 585504070 267437825
658480977 88196520 133056574 86736419
594632058 825124273 833743852 755203703
55263102 500368268 914935210 585214722
789723608 493976942 273003302 739318498
616142994 734771182 824400097 104990441
294191148 7377457...

output:

94967400
203286641
72575371
524061582
403543353
147472777
39192757
28201069
942613043
37913401
692114605
15193903
172610746
154393925
639101971
96784030
834502537
51248660
20079673
30134064
436074893
41394343
139419569
56761257
18356960
27003450
97885224
69930313
3614959
324680862
717819889
64581249...

result:

ok 10000 lines

Test #36:

score: 0
Accepted
time: 232ms
memory: 3660kb

input:

10000
651336280 418529645 494122968 408518331
59928709 698155697 361223311 738783545
154621396 138133124 20463718 91544970
154449271 255572846 178734539 552035046
457864606 807662301 831845567 417489151
77293154 69613737 595119844 582724233
943079950 870455330 849265206 844159166
846148492 465458622...

output:

322913695
399598033
41659817
304238767
253751536
405684637
576611231
23151212
299099358
2705997
298070785
2178025
92494556
497900313
119281081
146949644
149905631
216124006
199816241
471424521
351761289
593605228
49797122
159445371
504165649
684580860
227021473
324618400
34968063
4133090
54991290
45...

result:

ok 10000 lines

Test #37:

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

input:

10000
84 98 112109643 744341463
52 50 379539984 492226120
8 63 963373878 561408030
85 2 695868915 46060195
40 56 218573131 895858880
76 99 83508280 913428146
73 41 457750197 135269172
91 81 279308015 189791045
66 69 868997616 77084013
17 85 831496820 31268100
28 25 75554828 119347328
68 38 864862348...

output:

182763235
251277681
233534449
16482426
480706605
704745247
121199905
90718561
4640671
4205101
80729033
639186381
64439191
70978075
35282073
47921311
152097103
89962543
21320227
838840267
429222376
592929221
274434997
510527776
68516069
24680809
174988051
73144405
347742775
57290311
708035734
6933247...

result:

ok 10000 lines