QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#830720#869. Game on a TreeCalculateloveAC ✓340ms21868kbC++144.4kb2024-12-24 22:04:362024-12-24 22:04:42

Judging History

This is the latest submission verdict.

  • [2024-12-24 22:04:42]
  • Judged
  • Verdict: AC
  • Time: 340ms
  • Memory: 21868kb
  • [2024-12-24 22:04:36]
  • Submitted

answer

#include <bits/stdc++.h>

const int N = 100100;
const int mod = 1e9 + 7;

void add(int &x, const int &y) {
    x += y;
    if (x >= mod) x -= mod;
}

void dec(int &x, const int &y) {
    x -= y;
    if (x < 0) x += mod;
}

int qpow(int a, int b, int p) {
    int ans = 1;
    for (; b; b >>= 1) {
        if (b & 1) ans = 1ll * ans * a % p;
        a = 1ll * a * a % p;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int n, m, c;
int a[1 << 20], b[1 << 20];

void FWT_xor(int *a, const int &n, const int &opt) {
    for (int k = 1; k < n; k <<= 1)
        for (int i = 0; i < n; i += (k << 1))
            for (int j = 0; j < k; j ++) {
                int u = a[i + j], v = a[i + j + k];
                add(a[i + j] = u, v), dec(a[i + j + k] = u, v);
            }

    if (opt == -1) {
        int inv = qpow(n, mod - 2, mod);
        for (int i = 0; i < n; i ++) a[i] = 1ll * a[i] * inv % mod;
    }
}

int col[N];

int tot, head[N], ver[N * 2], Next[N * 2];
void add_edge(int u, int v) {
    ver[++ tot] = v;    Next[tot] = head[u];    head[u] = tot;
}

int Fa[N];
int dep[N];
int sze[N];
int son[N];

void dfs1(int u) {
    dep[u] = dep[Fa[u]] + 1;
    sze[u] = 1;

    for (int i = head[u]; i; i = Next[i]) {
        int v = ver[i];
        if (v == Fa[u]) continue;

        Fa[v] = u;
        dfs1(v);

        sze[u] += sze[v];
        if (sze[v] > sze[son[u]]) son[u] = v;
    }
}

int dfsClock, dfn[N], idx[N];
int chain_top[N];

void dfs2(int u, int P) {
    dfsClock ++;
    dfn[u] = dfsClock, idx[dfsClock] = u;

    chain_top[u] = P;

    if (son[u]) dfs2(son[u], P);
    for (int i = head[u]; i; i = Next[i]) {
        int v = ver[i];
        if (v == Fa[u] || v == son[u]) continue;

        dfs2(v, v);
    }
}

namespace SGT {
    struct node {
        int l, r;
        int sum;
    } t[N * 4];

    void upd(int p) {
        t[p].sum = t[p * 2].sum ^ t[p * 2 + 1].sum;
    }

    void build(int p, int l, int r) {
        t[p].l = l, t[p].r = r;
        if (l == r) {
            t[p].sum = (1 << col[idx[l]]);
            return;
        }
        int mid = (t[p].l + t[p].r) >> 1;
        build(p * 2, l, mid), build(p * 2 + 1, mid + 1, r);
        upd(p);
    }

    void change(int p, int x) {
        if (t[p].l == t[p].r) {
            t[p].sum = (1 << col[idx[x]]);
            return;
        }
        int mid = (t[p].l + t[p].r) >> 1;
        if (x <= mid)
            change(p * 2, x);
        else
            change(p * 2 + 1, x);
        upd(p);
    }

    int ask(int p, int l, int r) {
        if (l <= t[p].l && t[p].r <= r)
            return t[p].sum;
        int mid = (t[p].l + t[p].r) >> 1;
        if (l <= mid && mid < r)
            return ask(p * 2, l, r) ^ ask(p * 2 + 1, l, r);
        if (l <= mid)
            return ask(p * 2, l, r);
        else
            return ask(p * 2 + 1, l, r);
    }
}

int path_ask(int x, int y) {
    int ans = 0;
    while (chain_top[x] ^ chain_top[y]) {
        if (dep[chain_top[x]] > dep[chain_top[y]]) std::swap(x, y);
        ans ^= SGT::ask(1, dfn[chain_top[y]], dfn[y]);
        y = Fa[chain_top[y]];
    }
    if (dep[x] > dep[y]) std::swap(x, y);
    ans ^= SGT::ask(1, dfn[x], dfn[y]);
    return ans;
}

int main() {
    scanf("%d%d%d", &m, &c, &n);

    for (int i = 0; i < c; i ++) scanf("%d", &b[1 << i]);

    b[0] = 0;
    for (int S = 1; S < (1 << c); S ++) b[S] = gcd(b[S ^ (S & -S)], b[S & -S]);

    for (int i = 1; i <= m; i ++) {
        int S = 0, cnt = 0;

        scanf("%d", &cnt);
        for (int j = 1, x; j <= cnt; j ++) {
            scanf("%d", &x);
            S |= (1 << x);
        }

        a[S] ++;
    }

    FWT_xor(a, 1 << c, +1), FWT_xor(b, 1 << c, +1);
    for (int i = 0; i < (1 << c); i ++) a[i] = 1ll * a[i] * b[i] % mod;
    FWT_xor(a, 1 << c, -1);

    for (int i = 1; i <= n; i ++) scanf("%d", &col[i]);

    for (int i = 1, u, v; i < n; i ++) {
        scanf("%d%d", &u, &v), u ++, v ++;
        add_edge(u, v), add_edge(v, u);
    }

    dfs1(1);
    dfs2(1, 1);

    SGT::build(1, 1, n);

    int cur = 0;
    for (int i = 1, u, v, w, y; i <= m; i ++) {
        scanf("%d%d%d%d", &u, &v, &w, &y), u ++, v ++, w ++;

        cur ^= path_ask(u, v);
        printf("%d\n", a[cur]);

        col[w] = y, SGT::change(1, dfn[w]);
    }

    puts("");

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

6
4
9


result:

ok 3 number(s): "6 4 9"

Test #2:

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

input:

7 4 8
28 49 88 49
1 1
3 2 0 3
0
1 3
0
0
1 0
2 2 2 2 3 0 1 2
0 2
0 3
2 6
0 4
3 7
7 1
2 5
1 4 4 1
3 6 4 2
7 6 4 2
6 2 2 2
4 2 7 0
2 3 5 3
5 1 4 1

output:

207
13
121
253
13
253
106


result:

ok 7 numbers

Test #3:

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

input:

2 1 3
4
0
1 0
0 0 0
0 1
1 2
2 1 1 0
2 0 1 0

output:

4
4


result:

ok 2 number(s): "4 4"

Test #4:

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

input:

3 5 3
9 5 3 6 2
4 1 2 0 4
2 4 2
5 2 4 0 1 3
2 4 0
0 1
0 2
0 1 0 4
1 2 2 3
2 0 0 4

output:

2
15
3


result:

ok 3 number(s): "2 15 3"

Test #5:

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

input:

3 3 4
5 7 3
0
1 2
0
0 0 2 1
0 2
2 3
3 1
0 2 2 2
0 1 0 1
1 0 1 0

output:

7
3
9


result:

ok 3 number(s): "7 3 9"

Test #6:

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

input:

4 3 4
1 1 5
0
2 1 0
2 2 0
1 2
2 0 1 0
0 1
0 3
3 2
1 3 0 2
3 2 1 1
0 1 0 0
0 1 0 1

output:

7
8
8
4


result:

ok 4 number(s): "7 8 8 4"

Test #7:

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

input:

2 3 5
856865964 5739011 960906896
3 2 1 0
1 1
1 0 1 1 1
0 3
3 4
0 2
2 1
3 0 1 1
0 2 1 2

output:

5739012
5739012


result:

ok 2 number(s): "5739012 5739012"

Test #8:

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

input:

2 4 5
324416021 989585814 165885636 719714558
3 0 2 1
1 0
0 0 3 1 0
0 1
0 3
1 2
1 4
4 0 0 2
0 4 3 2

output:

42
155471443


result:

ok 2 number(s): "42 155471443"

Test #9:

score: 0
Accepted
time: 2ms
memory: 14192kb

input:

3 5 5
791966078 825948970 370864377 64820190 422159065
2 2 3
0
3 0 3 2
0 4 0 2 0
0 2
2 4
2 1
0 3
4 3 0 3
4 0 1 3
2 0 3 4

output:

64820193
791966079
435684569


result:

ok 3 number(s): "64820193 791966079 435684569"

Test #10:

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

input:

3 1 5
112032488
1 0
1 0
0
0 0 0 0 0
0 1
1 3
1 2
2 4
1 3 3 0
4 3 0 0
4 3 3 0

output:

224064976
224064976
224064976


result:

ok 3 number(s): "224064976 224064976 224064976"

Test #11:

score: 0
Accepted
time: 36ms
memory: 18876kb

input:

2 20 2
878166488 554062362 928434187 525114719 52760343 69272867 846344516 552145963 200763127 150418845 682365002 751325815 572492089 386549317 61673291 480959228 48927050 418192013 117178700 341590479
2 15 1
20 19 18 16 15 13 7 0 1 12 4 17 6 5 3 8 11 9 2 10 14
5 5
0 1
1 0 0 19
0 1 0 13

output:

3
2


result:

ok 2 number(s): "3 2"

Test #12:

score: 0
Accepted
time: 220ms
memory: 17524kb

input:

100000 1 100000
106525970
1 0
1 0
0
1 0
0
0
0
0
0
1 0
0
1 0
0
0
0
0
1 0
1 0
0
0
1 0
0
0
0
0
0
0
0
0
0
1 0
1 0
0
0
1 0
0
0
1 0
1 0
1 0
0
0
1 0
1 0
1 0
0
0
1 0
0
0
1 0
0
1 0
0
0
1 0
1 0
0
0
0
0
1 0
1 0
1 0
0
0
1 0
0
1 0
0
1 0
0
1 0
0
0
0
1 0
0
1 0
0
0
0
1 0
1 0
1 0
0
1 0
0
0
1 0
0
1 0
0
1 0
0
1 0
1 0
...

output:

308072077
288853359
288853359
308072077
288853359
288853359
288853359
288853359
308072077
308072077
288853359
308072077
308072077
308072077
288853359
288853359
308072077
308072077
308072077
288853359
308072077
308072077
288853359
288853359
308072077
308072077
308072077
308072077
308072077
288853359
...

result:

ok 100000 numbers

Test #13:

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

input:

41561 1 85904
463641356
1 0
0
1 0
0
1 0
1 0
0
1 0
1 0
0
0
0
0
0
1 0
0
0
0
0
1 0
0
0
0
1 0
1 0
0
1 0
1 0
0
1 0
0
0
0
0
0
0
0
0
1 0
0
1 0
1 0
0
0
0
1 0
1 0
1 0
1 0
1 0
1 0
0
0
1 0
1 0
0
1 0
1 0
1 0
0
1 0
0
0
0
0
1 0
0
0
1 0
0
0
1 0
1 0
0
0
1 0
1 0
1 0
0
1 0
1 0
0
0
0
0
0
1 0
0
0
1 0
1 0
1 0
1 0
0
0
1 ...

output:

840192180
840192180
840192180
840192180
558069660
840192180
558069660
558069660
558069660
840192180
840192180
558069660
840192180
840192180
558069660
840192180
840192180
840192180
840192180
840192180
840192180
840192180
558069660
840192180
558069660
840192180
558069660
840192180
840192180
558069660
...

result:

ok 41561 numbers

Test #14:

score: 0
Accepted
time: 119ms
memory: 15692kb

input:

47888 7 75572
236420882 262653787 604759466 670651358 213595625 495350280 810067234
7 0 2 4 6 3 1 5
7 0 3 2 1 6 5 4
6 0 4 5 6 3 1
5 2 1 0 6 3
0
2 5 1
6 3 1 4 5 0 2
6 5 1 6 3 4 0
5 1 6 3 2 5
7 3 4 2 1 0 6 5
7 0 5 1 6 3 2 4
6 4 1 3 6 2 5
6 2 1 4 0 5 3
4 2 3 0 1
1 0
2 5 6
6 3 2 4 0 1 5
2 4 0
4 1 0 5 3
...

output:

885493247
689716354
265828623
956601378
550229
839881723
560342477
668975705
244833746
668975705
648650191
679756956
668975705
797303519
795787216
245038493
587189751
244833746
667440826
967399079
218815537
662745530
669945875
502164375
449100926
275456490
113012579
550229
617842892
149997981
117833...

result:

ok 47888 numbers

Test #15:

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

input:

31442 19 29769
40833374 868252351 740183762 423469919 920855697 305761471 344941421 621120222 317290885 505026088 94273936 883793211 961953721 678105577 415006094 570966390 735951168 963093356 325057297
16 5 4 7 16 8 15 3 12 17 13 18 9 6 11 10 14
14 6 8 0 16 2 4 14 7 18 5 15 3 17 10
16 0 16 10 18 14...

output:

678137170
317322372
961985354
31558
678137035
31799
31462
718970434
101607014
31517
31533
31512
174045529
305792934
31489
505057591
621151705
619775848
31530
31456
505057568
31490
927209004
31458
94305444
325088785
868283815
31456
31503
31586
31499
31874
31489
31514
570997848
31476
31520
31493
31466...

result:

ok 31442 numbers

Test #16:

score: 0
Accepted
time: 43ms
memory: 17688kb

input:

17522 10 41270
431579348 559621011 338350466 626496383 843418274 633353435 862522175 247348860 756966884 264422664
4 0 5 6 7
3 1 4 9
2 0 6
9 0 4 1 7 2 9 3 5 6
1 2
0
0
2 5 8
0
9 3 8 6 2 9 4 0 1 7
3 3 9 6
9 4 0 6 7 3 8 2 1 5
7 1 9 2 5 7 4 0
7 3 6 5 0 4 7 1
5 4 5 6 9 8
8 6 3 9 0 7 5 8 1
10 2 3 7 0 5 8 ...

output:

797817819
204759650
287449819
627360566
404971458
572720141
143177720
892546794
915710336
186460155
281479869
844050207
593477614
248200739
424608505
201745918
349479301
716766328
76837471
205083206
320108802
70517979
517021417
207469434
387298594
196104007
186764506
59387676
936182304
157852572
510...

result:

ok 17522 numbers

Test #17:

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

input:

22213 10 91424
831748069 628464845 359994378 557944206 919377628 768250350 348576527 585912626 421061931 285981186
8 8 7 2 4 6 1 9 0
9 3 5 4 1 8 0 9 6 2
6 8 5 4 0 7 9
9 6 4 7 0 5 8 1 9 3
9 4 0 1 3 9 7 6 2 8
7 9 8 1 2 3 6 7
10 2 1 6 9 4 7 3 0 5 8
4 3 9 5 7
5 9 2 0 6 8
4 3 7 8 2
7 3 0 1 5 4 7 6
10 3 2...

output:

628619655
77488229
316904665
235885571
77488229
149089508
384070928
867878696
449495667
115909889
835528748
477276809
23581906
247757998
386498738
536511823
373135547
922314013
145324567
877315810
352208161
234925076
308686425
609621464
377292256
765228875
956481859
912186675
700315639
308182147
644...

result:

ok 22213 numbers

Test #18:

score: 0
Accepted
time: 114ms
memory: 16320kb

input:

73068 17 6221
506768995 78114242 449509999 5084749 461363413 269269265 313788422 435875751 760646208 673589377 516902845 756303378 684414339 44116322 903216445 612529203 788550723
16 15 2 10 0 16 5 8 14 12 13 9 11 7 1 3 4
15 2 16 1 6 9 8 3 11 14 13 0 15 12 10 5
13 0 3 13 7 10 12 8 6 5 9 14 2 11
4 10...

output:

358076827
782593938
949387862
756376508
399355775
155077811
565970151
801174279
414457499
981403798
123172558
984345838
417279532
471244856
633874207
972159565
678747265
806965987
211917701
9237361
505552923
637266038
700834963
461521538
152079949
191256475
99087970
454667900
133997458
922302281
959...

result:

ok 73068 numbers

Test #19:

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

input:

2251 16 7997
995636616 328206274 885343792 41487840 191988664 22459173 275735432 745939192 526703525 858247375 596055406 663264208 244165213 326056004 806343390 77177313
4 10 7 12 3
12 4 3 6 11 14 1 12 13 8 5 10 9
5 7 2 1 15 0
13 8 5 4 15 9 13 0 7 11 12 1 6 2
14 3 11 15 6 7 10 4 2 0 9 13 1 8 12
12 1...

output:

2345
2287
2404
2295
2371
2305
2295
596057699
2297
991275640
22461461
2368
2299
328208632
2311
2305
41490142
2295
2331
367546539
326058351
2372
2304
2301
2307
2313
77179691
2389
2339
858249735
244167565
2311
2291
745941535
2300
2303
2304
2292
2727
596057688
336389201
2317
2295
2376
2306
2355
80634567...

result:

ok 2251 numbers

Test #20:

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

input:

97212 20 33129
804918642 900055203 816217515 888753071 206387823 390462115 370374041 32270037 382825134 815333596 184634440 112495964 35840655 164180579 544399314 810054948 884709786 699213671 636140462 446131705
12 7 1 5 0 10 12 15 11 18 19 4 8
18 16 18 17 4 12 3 0 9 19 2 13 10 6 1 15 14 5 11
18 14...

output:

900152577
97294
753296553
97280
777603467
357158025
699311010
97348
97530
734451905
97324
859647017
402741464
318942588
520947627
97316
900152566
97296
97309
900152524
178706328
815431226
97346
117057298
97369
97388
206485322
206486857
206485236
720927541
97354
206485143
97614
97303
97801
816314834
...

result:

ok 97212 numbers

Test #21:

score: 0
Accepted
time: 211ms
memory: 16972kb

input:

88014 5 99561
975918415 716229668 620732057 422399559 962723136
1 2
5 2 4 1 0 3
0
1 2
0
4 3 2 1 4
3 3 2 0
1 2
4 4 3 1 0
1 2
2 4 0
5 2 4 1 3 0
5 3 2 0 1 4
0
0
0
3 4 2 0
0
4 1 3 0 2
2 4 2
5 0 3 1 4 2
2 2 3
0
2 2 4
3 0 2 4
2 0 1
2 4 0
0
4 0 1 2 4
4 4 3 0 2
2 3 0
5 4 3 0 1 2
5 3 4 2 1 0
5 4 1 3 2 0
4 3 ...

output:

351370707
225813262
602777116
440501935
45998396
924395530
26727974
712618034
602777116
351370707
225813262
111091097
181403944
150090324
181403944
602777116
27315785
26727974
181403944
542458536
882262179
805546740
542458536
164107154
150090324
351370707
225813262
189331784
189331784
45998396
80720...

result:

ok 88014 numbers

Test #22:

score: 0
Accepted
time: 138ms
memory: 16640kb

input:

51225 12 88158
419504919 840140480 723235534 239847579 299104424 954616130 92750219 789342427 418520025 292249098 20724195 18419670
3 9 2 7
4 1 10 4 9
2 1 10
0
0
11 7 3 6 8 10 1 2 5 0 4 9
5 9 2 6 3 10
6 1 6 3 11 10 7
0
6 5 1 10 7 8 9
1 4
6 11 9 5 3 2 0
2 10 3
7 6 9 8 1 10 7 5
10 10 1 2 11 9 0 4 5 8 ...

output:

5211666
107298668
805099994
544115834
552054926
550957207
439438050
674525424
561828919
449461615
672797825
978977224
626094663
401173319
702094250
261349699
868455948
701384345
980914262
264880430
619110569
935227859
33230422
937713207
519982386
695654365
414114988
900361130
571105385
96080258
5591...

result:

ok 51225 numbers

Test #23:

score: 0
Accepted
time: 31ms
memory: 16668kb

input:

9567 4 63117
311908074 435819416 275004352 773905389
1 0
0
4 2 1 3 0
3 2 1 0
1 0
2 0 2
4 1 2 3 0
1 2
1 2
3 3 0 2
1 3
4 2 3 0 1
4 2 3 0 1
2 0 3
1 2
0
4 2 1 0 3
4 0 3 2 1
4 3 1 2 0
0
0
2 2 0
0
0
3 2 1 3
3 3 0 1
1 2
0
3 2 0 3
4 2 3 1 0
1 3
2 0 2
3 0 2 1
1 0
0
1 2
2 2 0
4 0 1 2 3
4 1 0 2 3
2 3 0
4 3 2 0...

output:

473472292
612271013
863978573
863978573
158404217
206600818
197672743
473472292
983781985
27824478
197672743
735590723
473472292
612271013
197672743
888540316
888540316
612271013
158404217
735590723
197672743
408966041
863978573
831662371
566773321
197672743
888540316
983781985
197672743
408966041
1...

result:

ok 9567 numbers

Test #24:

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

input:

53718 1 16670
668651003
1 0
0
1 0
1 0
0
1 0
0
1 0
0
0
1 0
1 0
0
1 0
1 0
1 0
0
1 0
1 0
0
0
1 0
1 0
0
0
1 0
1 0
0
0
0
0
0
0
1 0
1 0
0
1 0
0
0
1 0
1 0
0
1 0
0
0
0
0
0
1 0
1 0
1 0
0
1 0
1 0
0
0
1 0
0
1 0
0
0
0
1 0
0
0
1 0
1 0
1 0
1 0
1 0
0
0
0
0
1 0
0
0
1 0
1 0
1 0
0
0
0
0
0
1 0
0
0
1 0
1 0
0
0
0
0
0
0
...

output:

64997059
529330669
64997059
529330669
529330669
64997059
64997059
64997059
64997059
64997059
529330669
529330669
529330669
64997059
529330669
64997059
64997059
529330669
529330669
64997059
64997059
529330669
529330669
529330669
64997059
529330669
529330669
529330669
529330669
529330669
529330669
649...

result:

ok 53718 numbers

Test #25:

score: 0
Accepted
time: 149ms
memory: 13548kb

input:

59422 14 57094
258567011 575643131 67568430 346970960 23985938 762263576 547593957 280210843 670361929 83770991 962265751 201095819 526843987 206358720
0
5 9 10 13 7 1
4 9 7 0 13
0
6 0 7 6 10 9 5
0
3 13 3 1
3 11 8 10
10 9 3 1 10 5 0 12 7 4 8
8 7 11 2 10 5 9 8 6
8 5 3 6 11 12 4 2 0
6 11 8 12 1 6 10
1...

output:

268735812
550173847
960424665
631220232
276955464
248544473
286702861
437554732
581562175
99639485
708896781
195845110
878212404
631236785
742815867
307765024
762244868
823877067
508051122
810145102
792463169
740580584
495581850
728663057
334908310
380841401
300578124
740635485
956549002
920925182
4...

result:

ok 59422 numbers

Test #26:

score: 0
Accepted
time: 59ms
memory: 11488kb

input:

38226 1 16861
404573639
0
1 0
1 0
0
1 0
1 0
1 0
0
0
0
1 0
0
0
0
0
0
0
0
0
0
0
0
0
1 0
0
1 0
1 0
1 0
0
1 0
0
0
0
1 0
0
0
0
1 0
0
0
0
0
1 0
1 0
0
1 0
0
0
1 0
0
1 0
1 0
1 0
1 0
0
1 0
1 0
0
0
0
1 0
1 0
1 0
0
1 0
1 0
1 0
1 0
0
1 0
0
1 0
0
0
0
1 0
1 0
0
0
0
1 0
0
1 0
0
1 0
1 0
1 0
0
0
1 0
1 0
1 0
1 0
1 0
...

output:

617615407
614200759
617615407
614200759
617615407
614200759
614200759
614200759
617615407
614200759
617615407
617615407
617615407
614200759
614200759
617615407
617615407
614200759
614200759
617615407
614200759
614200759
614200759
617615407
617615407
617615407
617615407
617615407
617615407
617615407
...

result:

ok 38226 numbers

Test #27:

score: 0
Accepted
time: 148ms
memory: 16796kb

input:

63205 9 81393
468800782 716699484 870899039 466221185 963659333 70593510 555471277 530559400 892033425
4 3 1 8 4
9 0 4 6 8 3 1 2 5 7
5 1 5 3 0 8
8 0 8 5 3 1 4 2 6
8 2 4 6 1 5 3 8 0
5 7 0 5 3 1
7 1 6 5 7 8 4 0
4 8 2 5 7
9 8 6 7 4 5 3 1 2 0
6 5 3 8 0 2 1
3 1 2 3
9 6 7 5 0 1 8 2 3 4
9 8 3 1 0 7 2 6 4 5...

output:

48361571
403869208
47978193
54661730
597108734
515302741
81292832
613029722
922318734
279559762
531110955
535483762
844938468
160767395
356331227
226381850
898198548
740974994
480955159
159847924
914416332
881041483
159847924
886569022
411278417
145639011
145639011
529290843
152840527
793420883
3981...

result:

ok 63205 numbers

Test #28:

score: 0
Accepted
time: 51ms
memory: 16396kb

input:

10730 14 99854
917376248 940099373 440313835 407246739 233992750 339438582 45065650 786908932 385046701 786517945 838159232 412230862 180915394 842428473
2 4 3
0
1 10
1 12
0
8 13 3 1 8 9 12 2 6
3 6 3 0
14 9 12 7 11 8 6 5 13 2 10 4 1 3 0
4 9 3 11 7
11 11 10 7 2 3 0 8 9 4 13 6
0
14 2 13 3 12 8 4 10 7 ...

output:

940280114
737852596
781455111
258289315
281671242
483349185
170444420
940110420
535298724
254670209
6595040
84961620
20912554
20037138
555598999
844446106
297052873
431316399
10873
374690972
638222738
414918976
765425471
685001983
290482429
578852781
860887620
858680793
917387088
898065170
198395464...

result:

ok 10730 numbers

Test #29:

score: 0
Accepted
time: 143ms
memory: 16564kb

input:

64305 3 85613
837244130 296634699 990933147
1 1
3 1 2 0
2 1 2
0
1 2
3 1 2 0
2 0 1
0
3 2 1 0
3 1 0 2
2 2 0
3 2 1 0
1 2
0
2 2 1
0
1 0
0
2 0 1
3 1 2 0
2 2 1
0
0
3 1 0 2
0
1 1
1 2
0
0
2 1 2
3 2 0 1
0
3 0 2 1
3 0 2 1
3 1 2 0
2 2 0
3 2 0 1
3 0 1 2
1 2
2 1 2
3 1 2 0
3 2 0 1
3 2 1 0
2 2 1
1 0
3 2 1 0
0
1 2
...

output:

590242531
76447112
886485512
241748725
241748725
886485512
473511339
54362501
188330639
54362501
522803550
473511339
54362501
76447112
590242531
241748725
522803550
590242531
241748725
76447112
76447112
188330639
522803550
473511339
54362501
886485512
473511339
522803550
54362501
54362501
522803550
...

result:

ok 64305 numbers

Test #30:

score: 0
Accepted
time: 39ms
memory: 16732kb

input:

13703 2 58088
109640503 666867111
2 1 0
0
0
2 1 0
0
2 1 0
1 0
0
1 0
0
2 0 1
1 0
2 1 0
2 0 1
0
1 0
0
0
2 1 0
0
2 0 1
2 0 1
2 1 0
1 0
1 1
1 1
1 0
2 0 1
2 0 1
0
1 1
0
0
0
0
1 0
1 0
0
1 0
0
0
0
2 0 1
1 1
1 1
0
0
2 1 0
1 1
0
2 1 0
2 1 0
2 1 0
1 1
1 1
0
0
0
2 0 1
1 1
1 1
2 0 1
2 1 0
0
1 1
0
1 1
2 0 1
0
1 ...

output:

972918226
129025155
972918226
972918226
866724999
866724999
866724999
515105499
515105499
129025155
972918226
515105499
972918226
972918226
515105499
866724999
866724999
866724999
515105499
972918226
129025155
515105499
515105499
515105499
972918226
129025155
515105499
129025155
972918226
515105499
...

result:

ok 13703 numbers

Test #31:

score: 0
Accepted
time: 141ms
memory: 15064kb

input:

56592 13 66043
307248746 681322249 227005915 157287097 353103327 394068620 620598128 915567774 985806323 513524013 446184055 370242443 454188032
11 6 2 0 8 3 4 10 12 7 11 1
5 6 3 9 11 5
4 0 6 11 8
5 5 4 10 0 9
1 2
1 12
11 12 10 6 9 7 1 8 11 4 5 0
11 1 5 3 10 12 8 9 0 2 7 6
11 2 4 6 11 7 12 3 8 5 1 0...

output:

475735221
443591046
281404712
954853914
55502869
732810732
37633760
149906946
289739435
250780881
710079951
250780881
564386590
820615463
94818430
344517470
946140050
255444009
607782023
221816420
51594464
188395750
790515679
735026086
209493837
224491993
897548923
701896541
728057590
580753477
9274...

result:

ok 56592 numbers

Test #32:

score: 0
Accepted
time: 199ms
memory: 17552kb

input:

97460 12 43803
27167124 537909690 997747430 258004228 744891014 284410965 543766238 656941733 792619210 944826289 955379900 264477641
8 6 5 1 2 10 4 9 3
0
8 5 3 8 1 7 6 2 10
0
1 8
10 0 9 4 3 6 8 7 11 5 2
10 7 8 9 3 0 10 11 5 6 4
9 1 6 4 8 10 0 2 3 9
0
5 9 7 1 6 8
1 3
1 1
6 2 7 9 5 0 4
1 10
3 3 0 5
8...

output:

472467393
503158150
427030155
279797524
58040759
926580672
428736699
468748418
802864177
70551237
862662466
22631904
766785554
649450006
56228886
310736698
876586627
333200746
626790496
684118955
496883900
165825839
838358193
923931774
7491956
671842486
893254582
936148689
384884502
598824824
623439...

result:

ok 97460 numbers

Test #33:

score: 0
Accepted
time: 329ms
memory: 21860kb

input:

100000 20 100000
988688020 331330879 776413204 578640706 970328991 684334742 700619675 54268490 310801569 174765756 344415011 180043832 535964457 227990632 399581295 714968756 16369791 809928945 444857002 107802870
20 8 5 13 14 11 12 18 9 15 0 3 16 10 4 6 17 1 19 2 7
11 4 19 6 1 16 17 2 11 14 5 9
18...

output:

347800928
54368652
100215
988788199
100225
413576969
100135
100190
100172
444957898
310901808
978322147
100247
100151
798838995
100185
407392986
78232015
365170218
617240086
54368669
100279
555881736
917831987
100144
100179
45135145
100242
100106
100307
100171
54368664
933550431
174867137
108637144
...

result:

ok 100000 numbers

Test #34:

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

input:

100000 20 100000
988880394 753588592 412319385 782097203 408711492 4401153 684466477 206451177 206299597 13246077 389599961 249545815 6353185 632549990 1234595 253525786 955769018 25318436 141824076 182390769
6 19 18 9 15 6 11
12 14 19 1 11 18 7 4 3 16 15 9 12
8 10 19 15 5 9 3 16 2
19 1 15 14 12 9 6...

output:

206399638
206399614
100029
206399664
684566542
100025
100104
100035
50736918
782197256
802019464
685801108
100025
100030
911638060
206551212
206399640
182490871
389700058
253625836
100035
253625817
408811575
100043
795443322
100052
100045
100058
418772610
195280013
133495498
100039
100035
100068
282...

result:

ok 100000 numbers

Test #35:

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

input:

100000 20 100000
989072768 175846304 48225567 285449327 704876463 994577641 471951210 520829633 411429918 358330703 715690585 604434165 7192972 980146184 729135524 921962205 107470278 49085632 34267080 473719208
7 17 11 1 2 14 6 4
1 6
10 3 16 18 13 15 11 7 6 4 0
13 16 6 10 0 5 17 15 11 1 14 4 7 13
1...

output:

100397
704976565
472051315
100142
100249
104148
175946440
100185
48325663
74121392
489683476
100177
922062419
632220198
994677980
100142
715790686
100470
100136
987440440
100133
100160
100201
100165
49185750
100156
100107
100216
100160
100473
987297410
49186029
100114
100136
920481847
100235
2075118...

result:

ok 100000 numbers

Test #36:

score: 0
Accepted
time: 323ms
memory: 21052kb

input:

100000 20 100000
989265143 745587663 831615395 712595461 480172077 580443789 939501267 504676435 763892305 510361810 270651447 819268369 912323776 953939183 825721057 842689814 961414771 289885894 43215725 953097986
7 0 13 8 14 17 11 4
15 8 2 15 4 13 14 0 18 6 9 16 7 11 17 12
17 15 6 12 17 16 7 4 2 ...

output:

925151749
100027
353151624
100009
953197999
129696183
270751482
745687688
100043
912423784
100014
100007
831715400
825821064
842789828
100010
745687704
476587804
100015
815086299
866362975
480272235
100011
666634664
842789867
407645880
564956065
100026
100007
782291136
100143
763992336
100017
289985...

result:

ok 100000 numbers

Test #37:

score: 0
Accepted
time: 321ms
memory: 21860kb

input:

100000 20 100000
989457517 167845375 467521577 139741595 402951337 18826291 407051323 341039591 968871046 662392917 973095955 34102573 817454580 780248536 922306590 615933777 815359263 530686156 52164370 284993117
6 11 9 15 18 1 0
15 8 0 15 9 13 5 2 3 6 18 12 17 10 14 4
18 17 9 4 18 13 16 12 10 1 19...

output:

100017
100022
100042
52264388
100014
139841647
100023
100033
759813239
83555362
407151353
815779294
100003
101329
815459273
973196244
100016
285093129
100001
616033808
530786168
35244172
52264395
100060
989557533
100016
100301
100040
467590925
989557533
100019
202047959
584799555
100010
100004
40715...

result:

ok 100000 numbers