QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#20485#2561. Diameter Pair SumQingyuAC ✓2396ms104792kbC++207.4kb2022-02-16 11:42:032022-05-03 10:12:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-03 10:12:43]
  • 评测
  • 测评结果:AC
  • 用时:2396ms
  • 内存:104792kb
  • [2022-02-16 11:42:03]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int mod = 1e9 + 7, N = 1e5 + 5;
const int half = (mod + 1) / 2;

int iadd(int x, int y) {
    return x + y >= mod ? x + y - mod : x + y;
}

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

int mul(int x, int y) {
    return 1ll * x * y % mod;
}

pii operator+(pii p, int x) {
    p.first += x;
    return p;
}

struct Count {
    int dis, cnt;
    Count() : dis(-N), cnt(0) {}
    Count(int dis, int cnt) : dis(dis), cnt(cnt) {}
    Count operator+(Count x) const {
        if (dis == x.dis) return Count(dis, iadd(cnt, x.cnt));
        if (dis < x.dis) return x;
        return *this;
    }
    void operator+=(Count x) {
        *this = *this + x;
    }
    Count operator+(int x) const {
        return Count(dis + x, cnt);
    }
    Count operator*(Count x) const {
        if (dis == x.dis) return Count(dis, mul(cnt, x.cnt));
        return Count(-1, 0);
    }
    Count operator*(int x) const {
        return Count(dis, mul(x, cnt));
    }
    Count sq() const {
        return Count(dis, mul(cnt, cnt));
    }
};

struct Dist  {
    int cnt, ver;
    Count sum, one, ans;
    pii far;
    Dist() : cnt(0), ver(-1), sum(), one(), ans(), far(-N, -1) {}
    Dist(int x) : cnt(1), ver(x), sum(0, 1), one(0, 1), ans(0, 1), far(0, x) {}
    void merge(Dist L, Dist R, pii Cfar, Count Csum, Count Cans) {
        Count rcsum = Count(L.cnt, 1) + (R.sum + Csum + (L.cnt + 1));
        cnt = L.cnt + 1 + R.cnt;
        sum = L.sum + rcsum;
        one = L.one + (R.one + (L.cnt + 1)) + rcsum * (L.cnt + 1);
        ans = L.ans + (R.ans + Cans + (L.cnt + 1)) + L.one * rcsum * 2 + rcsum.sq() * (L.cnt + 1);
        far = max(max(L.far, max(R.far, Cfar) + (L.cnt + 1)), pii(L.cnt, ver));
    }
};

struct node {
    int l, r, p, rev;
    Dist ldis, rdis;
    map<int, int> psum, pans, r1, r2, s2;
    set<pii> pfar;
    node() {}
    node(int x) : l(0), r(0), p(0), rev(0), ldis(x), rdis(x) {}
} ns[N];

void lazy(int x) {
    if (!ns[x].rev) return;
    ns[x].rev = 0;
    if (ns[x].l) {
        ns[ns[x].l].rev ^= 1;
        swap(ns[ns[x].l].ldis, ns[ns[x].l].rdis);
        swap(ns[ns[x].l].l, ns[ns[x].l].r);
    }
    if (ns[x].r) {
        ns[ns[x].r].rev ^= 1;
        swap(ns[ns[x].r].ldis, ns[ns[x].r].rdis);
        swap(ns[ns[x].r].l, ns[ns[x].r].r);
    }
}

void update(int x) {
    int l = ns[x].l, r = ns[x].r;
    pii Cfar = pii(-N, -1);
    Count Csum = Count(-1, 0), Cans = Count(-1, 0);
    if (!ns[x].pfar.empty()) {
        Cfar = *ns[x].pfar.rbegin();
        int dis = Cfar.first;
        Csum = Count(dis, ns[x].psum[dis]);
        Cans = Count(dis, ns[x].pans[dis]);
    }
    ns[x].ldis.merge(ns[l].ldis, ns[r].ldis, Cfar, Csum, Cans);
    ns[x].rdis.merge(ns[r].rdis, ns[l].rdis, Cfar, Csum, Cans);
}

void erase_map(int x) {
    if (!x) return;
    int p = ns[x].p;
    if (!p) return;
    int dis = ns[x].ldis.far.first;
    ns[p].pfar.erase(ns[x].ldis.far);
    add(ns[p].psum[dis], mod - ns[x].ldis.sum.cnt);
    add(ns[p].pans[dis], mod - ns[x].ldis.ans.cnt);
    add(ns[p].r1[dis], mod - mul(ns[x].ldis.ans.cnt, ns[x].ldis.sum.cnt));
    add(ns[p].r2[dis], mod - mul(ns[x].ldis.ans.cnt, mul(ns[x].ldis.sum.cnt, ns[x].ldis.sum.cnt)));
    add(ns[p].s2[dis], mod - mul(ns[x].ldis.sum.cnt, ns[x].ldis.sum.cnt));
}

void insert_map(int x) {
    if (!x) return;
    int p = ns[x].p;
    if (!p) return;
    int dis = ns[x].ldis.far.first;
    ns[p].pfar.insert(ns[x].ldis.far);
    add(ns[p].psum[dis], ns[x].ldis.sum.cnt);
    add(ns[p].pans[dis], ns[x].ldis.ans.cnt);
    add(ns[p].r1[dis], mul(ns[x].ldis.ans.cnt, ns[x].ldis.sum.cnt));
    add(ns[p].r2[dis], mul(ns[x].ldis.ans.cnt, mul(ns[x].ldis.sum.cnt, ns[x].ldis.sum.cnt)));
    add(ns[p].s2[dis], mul(ns[x].ldis.sum.cnt, ns[x].ldis.sum.cnt));
}

bool is_root(int x) {
    return ns[x].p == 0 || ns[ns[x].p].l != x && ns[ns[x].p].r != x;
}

void rotate(int x) {
    int p = ns[x].p;
    if (ns[p].l == x) {
        ns[p].l = ns[x].r;
        if (ns[p].l) ns[ns[p].l].p = p;
        ns[x].r = p;
    }
    else {
        ns[p].r = ns[x].l;
        if (ns[p].r) ns[ns[p].r].p = p;
        ns[x].l = p;
    }
    ns[x].p = ns[p].p;
    ns[p].p = x;
    if (ns[x].p) {
        if (ns[ns[x].p].l == p) ns[ns[x].p].l = x;
        else if (ns[ns[x].p].r == p) ns[ns[x].p].r = x;
    }
    update(p);
    update(x);
}

void splay(int x) {
    while (!is_root(x)) {
        int p = ns[x].p;
        int g = ns[p].p;
        if (!is_root(p)) {
            if ((ns[g].l == p) == (ns[p].l == x)) rotate(p);
            else rotate(x);
        }
        rotate(x);
    }
}

int access(int x) {
    vector<int> vt;
    for (int i = x; ns[i].p; i = ns[i].p) vt.push_back(i);
    reverse(vt.begin(), vt.end());
    for (int i : vt) {
        lazy(ns[i].p);
        if (is_root(i)) erase_map(i);
    }
    lazy(x);
    splay(x);
    insert_map(ns[x].r);
    ns[x].r = 0;
    update(x);

    int ret = x;
    while (ns[x].p) {
        ret = ns[x].p;
        splay(ret);
        insert_map(ns[ret].r);
        ns[ret].r = x;
        update(ret);
        splay(x);
    }
    return ret;
}

void make_root(int x) {
    access(x);
    ns[x].rev = 1;
    swap(ns[x].l, ns[x].r);
    swap(ns[x].ldis, ns[x].rdis);
    lazy(x);
}

void link(int p, int x) {
    make_root(x);
    access(p);
    ns[x].l = p;
    ns[p].p = x;
    update(x);
}

void cut(int x, int y) {
    make_root(y);
    access(x);
    ns[ns[x].l].p = 0;
    ns[x].l = 0;
    update(x);
}

int kth(int r, int k) {
    while (1) {
        int lcnt = ns[r].l ? ns[ns[r].l].ldis.cnt : 0;
        if (k == lcnt) return r;
        if (k < lcnt) r = ns[r].l;
        else k -= lcnt + 1, r = ns[r].r;
        lazy(r);
    }
}

int solve(int r) {
    make_root(r);
    int y = ns[r].ldis.far.second;
    make_root(y);
    auto [d, x] = ns[y].ldis.far;
    access(x);
    int ans = 0;
    if (d % 2) {
        int a = kth(x, d / 2);
        int b = kth(x, d / 2 + 1);
        d /= 2;
        cut(a, b);
        add(ans, mul(ns[a].ldis.ans.cnt, mul(ns[b].ldis.sum.cnt, ns[b].ldis.sum.cnt)));
        add(ans, mul(ns[b].ldis.ans.cnt, mul(ns[a].ldis.sum.cnt, ns[a].ldis.sum.cnt)));
        link(a, b);
    }
    else {
        int c = kth(x, d /= 2);
        make_root(c);
        access(c);
        int pans = ns[c].pans[d - 1], psum = ns[c].psum[d - 1];
        add(ans, mul(pans, mul(psum, psum)));
        add(ans, mod - mul(2, mul(ns[c].r1[d - 1], psum)));
        add(ans, ns[c].r2[d - 1]);
        psum = mul(psum, psum);
        add(psum, mod - ns[c].s2[d - 1]);
        psum = mul(half, psum);
        add(ans, mul(psum, psum));
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);int n, m, q;
    cin >> n >> m >> q;
    for (int i = 1; i <= n; ++i) ns[i] = node(i);
    for (int i = 1; i <= m; ++i) {
        int x, y;
        cin >> x >> y;
        link(x, y);
    }
    while (q--) {
        int t;
        cin >> t;
        if (t == 3) {
            int r;
            cin >> r;
            printf("%d\n", solve(r));
            continue;
        }
        int x, y;
        cin >> x >> y;
        if (t == 1) link(x, y);
        else cut(x, y);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

18
64
21

result:

ok 3 number(s): "18 64 21"

Test #2:

score: 0
Accepted
time: 8ms
memory: 41264kb

input:

2 0 2
1 2 1
3 2

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

2 1 1
2 1
3 1

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

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

output:

9
53
8
44
7

result:

ok 5 number(s): "9 53 8 44 7"

Test #5:

score: 0
Accepted
time: 4ms
memory: 41312kb

input:

100 99 150
2 1
3 1
4 2
5 2
6 3
7 3
8 4
9 4
10 5
11 5
12 6
13 6
14 7
15 7
16 8
17 8
18 9
19 9
20 10
21 10
22 11
23 11
24 12
25 12
26 13
27 13
28 14
29 14
30 15
31 15
32 16
33 16
34 17
35 17
36 18
37 18
38 19
39 19
40 20
41 20
42 21
43 21
44 22
45 22
46 23
48 47
49 47
50 48
51 48
52 49
53 49
54 50
55 ...

output:

46392
242688
209920
40120
174961
130861
684784
226304
242688
43256
40120
569584
193536
49528
226304
152911
1090156
46392
742384
242688
152911
163936
742384
141886
152911
46392
163936
130861
163936
163936
52664
52664
46392
259072
130861
259072
242688
193536
511984
52664
49528
226304
130861
36984
1529...

result:

ok 50 numbers

Test #6:

score: 0
Accepted
time: 16ms
memory: 41716kb

input:

1000 999 150
2 1
3 1
4 2
5 2
6 3
7 3
8 4
9 4
10 5
11 5
12 6
13 6
14 7
15 7
16 8
17 8
18 9
19 9
20 10
21 10
22 11
23 11
24 12
25 12
26 13
27 13
28 14
29 14
30 15
31 15
32 16
33 16
34 17
35 17
36 18
37 18
38 19
39 19
40 20
41 20
42 21
43 21
44 22
45 22
46 23
47 23
48 24
49 24
50 25
51 25
52 26
53 26
5...

output:

190174834
92573049
92573049
27451769
856992640
632950237
856992640
190174834
92573049
191696249
191696249
142134649
198042859
899607424
142134649
632950237
43011449
984836992
364514781
984836992
190174834
166570759
190174834
119362609
43011449
198042859
182306809
174438784
856992640
364514781
166570...

result:

ok 50 numbers

Test #7:

score: 0
Accepted
time: 20ms
memory: 41908kb

input:

1000 999 1500
2 1
3 1
4 2
5 2
6 3
7 3
8 4
9 4
10 5
11 5
12 6
13 6
14 7
15 7
16 8
17 8
18 9
19 9
20 10
21 10
22 11
23 11
24 12
25 12
26 13
27 13
28 14
29 14
30 15
31 15
32 16
33 16
34 17
35 17
36 18
37 18
38 19
39 19
40 20
41 20
42 21
43 21
44 22
45 22
46 23
47 23
48 24
49 24
50 25
51 25
52 26
53 26
...

output:

827643876
330587008
122094698
330587008
827643876
316808064
117108409
559208420
122094698
112122120
344365952
86415218
632950237
86415218
794993017
892133753
117108409
117108409
344365952
127080987
559208420
183555954
127080987
234134400
117108409
330587008
102149542
827643876
122094698
303029120
30...

result:

ok 500 numbers

Test #8:

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

input:

100 99 15000
2 1
3 1
4 2
5 2
6 3
7 3
8 4
9 4
10 5
11 5
12 6
13 6
14 7
15 7
16 8
17 8
18 9
19 9
20 10
21 10
22 11
23 11
24 12
25 12
26 13
27 13
28 14
29 14
30 15
31 15
32 16
33 16
34 17
35 17
36 18
37 18
38 19
39 19
40 20
41 20
42 21
43 21
44 22
45 22
46 23
47 23
48 24
49 24
50 25
51 25
52 26
53 26
5...

output:

259072
124536
345200
116792
226304
109048
196383
109048
226304
242688
469104
369592
369592
226304
101304
226304
225665
226304
259072
242688
181742
407152
93560
469104
109048
259072
93560
438128
407152
259072
124536
177152
101304
116792
101304
124536
124536
181742
211024
116792
116792
193536
438128
2...

result:

ok 5000 numbers

Test #9:

score: 0
Accepted
time: 184ms
memory: 48068kb

input:

10000 9999 15000
2 1
3 1
4 2
5 2
6 3
7 3
8 4
9 4
10 5
11 5
12 6
13 6
14 7
15 7
16 8
17 8
18 9
19 9
20 10
21 10
22 11
23 11
24 12
25 12
26 13
27 13
28 14
29 14
30 15
31 15
32 16
33 16
34 17
35 17
36 18
37 18
38 19
39 19
40 20
41 20
42 21
43 21
44 22
45 22
46 23
47 23
48 24
49 24
50 25
51 25
52 26
53 ...

output:

413992301
154638433
977369012
369417401
33732056
596538039
154638433
470355352
33732056
969428874
643018357
666258516
169423134
177878592
177878592
243182644
769420271
192409073
723862182
769420271
201118751
470355352
666258516
768569433
666258516
769434607
201118751
768569433
154638433
243182644
16...

result:

ok 5000 numbers

Test #10:

score: 0
Accepted
time: 490ms
memory: 93380kb

input:

100000 99999 15000
2 1
3 1
4 2
5 2
6 3
7 3
8 4
9 4
10 5
11 5
12 6
13 6
14 7
15 7
16 8
17 8
18 9
19 9
20 10
21 10
22 11
23 11
24 12
25 12
26 13
27 13
28 14
29 14
30 15
31 15
32 16
33 16
34 17
35 17
36 18
37 18
38 19
39 19
40 20
41 20
42 21
43 21
44 22
45 22
46 23
47 23
48 24
49 24
50 25
51 25
52 26
5...

output:

653432513
883481604
732582025
583194430
732582025
574283001
798118294
732582025
653432513
349956819
461240563
819384666
500100406
461240563
67710171
653432513
812457970
798118294
798118294
732582025
883481604
811731537
500100406
116719208
653432513
732582025
732582025
495133489
812457970
230875368
5...

result:

ok 5000 numbers

Test #11:

score: 0
Accepted
time: 837ms
memory: 50492kb

input:

10000 9999 90000
2 1
3 1
4 2
5 2
6 3
7 3
8 4
9 4
10 5
11 5
12 6
13 6
14 7
15 7
16 8
17 8
18 9
19 9
20 10
21 10
22 11
23 11
24 12
25 12
26 13
27 13
28 14
29 14
30 15
31 15
32 16
33 16
34 17
35 17
36 18
37 18
38 19
39 19
40 20
41 20
42 21
43 21
44 22
45 22
46 23
47 23
48 24
49 24
50 25
51 25
52 26
53 ...

output:

201644986
143221416
143221416
689498675
689498675
852468237
724727788
561715051
720670437
480183159
643018357
55907537
177878592
852468237
480183159
999208610
177878592
724727788
689498675
264209112
689498675
201644986
689498675
980208686
201644986
724727788
852468237
201644986
689498675
201644986
6...

result:

ok 30000 numbers

Test #12:

score: 0
Accepted
time: 554ms
memory: 70800kb

input:

50000 49999 30000
2 1
3 1
4 2
5 2
6 3
7 3
8 4
9 4
10 5
11 5
12 6
13 6
14 7
15 7
16 8
17 8
18 9
19 9
20 10
21 10
22 11
23 11
24 12
25 12
26 13
27 13
28 14
29 14
30 15
31 15
32 16
33 16
34 17
35 17
36 18
37 18
38 19
39 19
40 20
41 20
42 21
43 21
44 22
45 22
46 23
47 23
48 24
49 24
50 25
51 25
52 26
53...

output:

940734101
154229738
293966497
360157973
341403424
341403424
528577110
449904864
323815098
940734101
809337639
341403424
940734101
341403424
854059568
550943540
294652302
264117896
264117896
617350299
264117896
940734101
940734101
617350299
651982216
264117896
449904864
348866188
677047501
617350299
...

result:

ok 10000 numbers

Test #13:

score: 0
Accepted
time: 1994ms
memory: 104792kb

input:

100000 99999 99999
2 1
3 1
4 2
5 2
6 3
7 3
8 4
9 4
10 5
11 5
12 6
13 6
14 7
15 7
16 8
17 8
18 9
19 9
20 10
21 10
22 11
23 11
24 12
25 12
26 13
27 13
28 14
29 14
30 15
31 15
32 16
33 16
34 17
35 17
36 18
37 18
38 19
39 19
40 20
41 20
42 21
43 21
44 22
45 22
46 23
47 23
48 24
49 24
50 25
51 25
52 26
5...

output:

61357681
682348822
284839910
772229140
772229140
789334322
266862795
120135325
862109458
61357681
682348822
727288981
284839910
727288981
966575628
296468257
61357681
355245901
883481604
120135325
61357681
883481604
500100406
966575628
537087116
41581521
772229140
61357681
293828727
178912969
613576...

result:

ok 33333 numbers

Test #14:

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

input:

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

output:

516
516
516
516
370

result:

ok 5 number(s): "516 516 516 516 370"

Test #15:

score: 0
Accepted
time: 4ms
memory: 41168kb

input:

100 99 150
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
4 11
5 12
6 13
7 14
8 15
9 16
10 17
2 18
3 19
4 20
5 21
6 22
7 23
8 24
9 25
10 26
2 27
3 28
4 29
5 30
6 31
7 32
8 33
9 34
10 35
2 36
3 37
4 38
5 39
6 40
7 41
8 42
9 43
10 44
2 45
3 46
4 47
5 48
6 49
7 50
8 51
9 52
10 53
2 54
3 55
4 56
5 57
6 58
7 59
8 ...

output:

19295103
19295103
19294161
19293270
19292381
19289787
19290672
19290672
19288082
19288047
19288884
19283817
19283817
19283832
19283832
19285517
19288002
19289691
19289691
19290560
19288002
19285452
19288002
19288002
19282958
19282958
19287120
19289862
19287393
19287393
19282421
19287393
19284639
192...

result:

ok 50 numbers

Test #16:

score: 0
Accepted
time: 8ms
memory: 41360kb

input:

1000 999 150
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
4 33
5 34
6 35
7 36
8 37
9 38
10 39
11 40
12 41
13 42
14 43
15 44
16 45
17 46
18 47
19 48
20 49
21 50
22 51
23 52
24 53
25 54
26 55
27 56
28...

output:

946718776
947333785
947333785
947937942
948552955
949167970
950387152
951628074
952243099
953462301
954681511
956494084
954681511
954681511
954681511
956494084
958371871
957767680
958371871
958997796
960238774
959645407
959645407
960886389
959041212
959656261
960271312
959656261
959052066
959656261
...

result:

ok 50 numbers

Test #17:

score: 0
Accepted
time: 3ms
memory: 41360kb

input:

1000 999 1500
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
4 33
5 34
6 35
7 36
8 37
9 38
10 39
11 40
12 41
13 42
14 43
15 44
16 45
17 46
18 47
19 48
20 49
21 50
22 51
23 52
24 53
25 54
26 55
27 56
2...

output:

947937942
949178848
948574687
949793865
950408884
950408884
950408884
951023905
951023905
951023905
951023905
951023905
949178824
950398006
951013027
951013027
950398006
950398006
951013027
951628050
952847248
952847248
954659803
955285716
954670681
953429739
954044770
955285716
954088186
953473155
...

result:

ok 500 numbers

Test #18:

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

input:

100 99 15000
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
4 11
5 12
6 13
7 14
8 15
9 16
10 17
2 18
3 19
4 20
5 21
6 22
7 23
8 24
9 25
10 26
2 27
3 28
4 29
5 30
6 31
7 32
8 33
9 34
10 35
2 36
3 37
4 38
5 39
6 40
7 41
8 42
9 43
10 44
2 45
3 46
4 47
5 48
6 49
7 50
8 51
9 52
10 53
2 54
3 55
4 56
5 57
6 58
7 59
...

output:

19295103
19294208
19294208
19294208
19291602
19289004
19289004
19288965
19289763
19291466
19290672
19292381
19292381
19290672
19289787
19287168
19285412
19287168
19285412
19285389
19287983
19288002
19289691
19287105
19289670
19289670
19291359
19291359
19289670
19289670
19292228
19292228
19290504
192...

result:

ok 5000 numbers

Test #19:

score: 0
Accepted
time: 42ms
memory: 41808kb

input:

10000 9999 15000
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1...

output:

566056253
653257258
740458265
827659274
914860285
914860285
914860285
2061291
89262306
176463323
176463323
350981769
263664342
350865363
438066386
525267411
612468438
612468438
612468438
786754116
961272590
961272590
961272590
48473620
222759318
309960361
309960361
397161406
484362453
658880959
7460...

result:

ok 5000 numbers

Test #20:

score: 0
Accepted
time: 162ms
memory: 46044kb

input:

100000 99999 15000
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59...

output:

93822056
93822056
276909197
276909197
276909197
867858465
459996346
459996346
50945611
643083503
643083503
826170668
826170668
826170668
826170668
418308559
601395736
601395736
784482921
557330807
742795272
333744565
516831782
107781081
699919007
292056928
292056928
475144165
66093474
838941451
8389...

result:

ok 5000 numbers

Test #21:

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

input:

10000 9999 90000
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1...

output:

566056253
653257258
740458265
827659274
827659274
914860285
2061291
89262306
176463323
263664342
350865363
438066386
525267411
612468438
874071555
48357238
309611239
309611239
309611239
484129737
484129737
833166805
7452532
94537211
7336150
94537211
94537211
269055745
443341499
443341499
791913079
6...

result:

ok 30000 numbers

Test #22:

score: 0
Accepted
time: 144ms
memory: 43664kb

input:

50000 49999 30000
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
...

output:

197979996
553939143
909898292
265857436
621816589
977775744
977775744
333734894
333734894
45061265
401020428
401020428
112346811
823673209
179632375
890958785
246917957
958244379
314203557
670162744
670162744
26713892
670754710
26713892
382673083
738632276
94591464
94591464
805917918
805917918
16187...

result:

ok 10000 numbers

Test #23:

score: 0
Accepted
time: 381ms
memory: 46048kb

input:

100000 99999 99999
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59...

output:

684771320
684771320
867858465
459996346
459996346
459996346
50945611
50945611
643083503
643083503
643083503
234032772
417119941
8069216
191156397
374243586
374243586
966381496
557330783
148280072
148280072
148280072
148280072
148280072
148280072
556142165
739229370
331367281
923505201
923505201
5156...

result:

ok 33333 numbers

Test #24:

score: 0
Accepted
time: 10ms
memory: 41204kb

input:

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

output:

26
26
34
26
30

result:

ok 5 number(s): "26 26 34 26 30"

Test #25:

score: 0
Accepted
time: 8ms
memory: 41136kb

input:

100 99 150
2 91
62 92
2 93
89 94
89 95
89 96
89 97
89 98
62 99
62 100
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
4...

output:

23814
24138
64548
24462
20250
45168
49200
41136
50928
42288
26406
24786
42864
8868
45744
24462
35952
49200
8868
27702
23166
8868
41136
24786
49200
64548
20574
50928
22194
21222
50352
48624
22194
26082
22194
40560
49776
22842
35952
28026
23166
8868
8868
8868
25110
38832
21546
28026
40560
37680

result:

ok 50 numbers

Test #26:

score: 0
Accepted
time: 16ms
memory: 41280kb

input:

1000 999 150
2 901
2 902
2 903
2 904
629 905
629 906
629 907
899 908
899 909
899 910
899 911
2 912
2 913
899 914
899 915
2 916
629 917
629 918
2 919
2 920
899 921
899 922
899 923
2 924
2 925
629 926
899 927
2 928
2 929
2 930
899 931
2 932
629 933
899 934
899 935
2 936
629 937
899 938
629 939
2 940
6...

output:

730181314
845116840
640695833
653377830
778791114
845116840
185694233
437239833
668932966
735042294
392849433
700043238
856566794
740875470
696154454
348459033
845116840
202340633
590756633
845116840
638846233
845116840
281873433
587057433
836150678
622267558
320715033
785596486
655492633
858511186
...

result:

ok 50 numbers

Test #27:

score: 0
Accepted
time: 11ms
memory: 41660kb

input:

1000 999 1500
899 901
629 902
899 903
629 904
899 905
899 906
2 907
899 908
2 909
629 910
2 911
629 912
2 913
629 914
2 915
2 916
899 917
2 918
2 919
629 920
899 921
899 922
629 923
899 924
899 925
2 926
629 927
629 928
629 929
899 930
629 931
899 932
899 933
629 934
899 935
2 936
2 937
2 938
2 939
...

output:

517674976
440789398
56132810
418822090
636664561
310816159
81579788
114095371
380379301
149438396
64615136
565270810
12307459
167816769
927484206
934552811
418822090
244914235
473740360
115509092
187608863
575212506
575212506
254053750
166403048
160706221
129646302
575212506
406007827
200332352
5471...

result:

ok 500 numbers

Test #28:

score: 0
Accepted
time: 49ms
memory: 41464kb

input:

100 99 15000
2 91
62 92
2 93
62 94
62 95
2 96
89 97
89 98
89 99
2 100
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
4...

output:

24580
34980
34980
16768
17024
16256
18560
24580
17024
26580
24980
24580
24580
30180
17280
20352
30580
20096
19072
34180
77320
27780
27380
28580
24580
18048
18816
19840
16000
19072
24580
29380
33780
28180
25780
33780
32980
21120
19840
21632
18048
31380
20352
28980
24980
33780
17536
28580
27780
19328
...

result:

ok 5000 numbers

Test #29:

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

input:

10000 9999 15000
8999 9001
6299 9002
2 9003
6299 9004
2 9005
6299 9006
6299 9007
6299 9008
6299 9009
8999 9010
2 9011
6299 9012
2 9013
2 9014
8999 9015
2 9016
8999 9017
2 9018
2 9019
2 9020
2 9021
6299 9022
8999 9023
8999 9024
6299 9025
2 9026
6299 9027
2 9028
8999 9029
2 9030
6299 9031
8999 9032
62...

output:

174978432
47983424
588469036
386587136
314123251
744992269
314123251
366037578
481541603
869183772
42582952
850457012
143425551
314123251
476384381
746630860
824021286
314123251
561929355
632570398
314123251
812153541
705518728
153053747
314123251
342947543
231752701
178703615
438702591
447195041
43...

result:

ok 5000 numbers

Test #30:

score: 0
Accepted
time: 180ms
memory: 47500kb

input:

100000 99999 15000
62999 90001
62999 90002
62999 90003
62999 90004
89999 90005
2 90006
62999 90007
89999 90008
62999 90009
89999 90010
62999 90011
89999 90012
89999 90013
89999 90014
89999 90015
89999 90016
89999 90017
2 90018
62999 90019
62999 90020
2 90021
62999 90022
89999 90023
2 90024
62999 900...

output:

830151654
694205076
499684638
710213131
905134800
499684638
613264976
592414036
393447862
344287725
135897432
225268444
440475092
132285526
499684638
499684638
21836677
499684638
981685769
80000579
499684638
718700058
930608515
622891741
342268551
833799533
499684638
722550922
523962127
124513956
49...

result:

ok 5000 numbers

Test #31:

score: 0
Accepted
time: 464ms
memory: 49344kb

input:

10000 9999 90000
8999 9001
8999 9002
8999 9003
8999 9004
6299 9005
8999 9006
8999 9007
8999 9008
8999 9009
2 9010
6299 9011
6299 9012
2 9013
8999 9014
2 9015
2 9016
2 9017
2 9018
8999 9019
6299 9020
8999 9021
6299 9022
2 9023
6299 9024
6299 9025
8999 9026
6299 9027
6299 9028
6299 9029
2 9030
2 9031
...

output:

306123359
797331293
278530380
494587145
715117879
736275302
465087995
563865334
802531002
311538701
140027287
69124804
339555282
849926028
985902348
415515749
635440272
61628346
290121799
902942033
30797245
140027287
713060188
691884
40384089
44098460
147441653
394358326
106846152
984008437
23183077...

result:

ok 30000 numbers

Test #32:

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

input:

50000 49999 30000
31499 45001
44999 45002
44999 45003
2 45004
44999 45005
44999 45006
44999 45007
44999 45008
31499 45009
31499 45010
2 45011
44999 45012
44999 45013
31499 45014
44999 45015
31499 45016
44999 45017
31499 45018
44999 45019
2 45020
31499 45021
2 45022
44999 45023
44999 45024
31499 4502...

output:

771706428
974046787
524504694
786858915
601592081
808800730
266680793
178617315
184507078
16129046
545739800
16129046
480189041
632301803
56289447
846040065
973534542
759786880
130478051
193624769
862180099
16129046
186403418
220571136
774116621
16129046
387737200
592465646
8150183
16129046
16129046...

result:

ok 10000 numbers

Test #33:

score: 0
Accepted
time: 750ms
memory: 69088kb

input:

100000 99999 99999
89999 90001
62999 90002
62999 90003
2 90004
2 90005
89999 90006
62999 90007
89999 90008
2 90009
2 90010
62999 90011
62999 90012
62999 90013
62999 90014
89999 90015
2 90016
2 90017
89999 90018
2 90019
2 90020
2 90021
62999 90022
2 90023
62999 90024
62999 90025
89999 90026
2 90027
6...

output:

808937730
400346271
277122711
362253092
808937730
808937730
326371136
66327474
908070160
410260603
116579756
682446537
859162401
700678344
731829290
24169070
961733933
629566692
677786925
810754524
734267865
682410572
273047862
593690675
239073858
470202966
271576994
501497139
248935639
699486940
46...

result:

ok 33333 numbers

Test #34:

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

input:

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

output:

9
9
9
8
26

result:

ok 5 number(s): "9 9 9 8 26"

Test #35:

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

input:

100 99 150
71 41
11 41
31 71
51 71
21 41
81 41
91 31
1 81
61 81
3 63
23 3
33 3
13 23
93 23
43 33
73 13
53 13
83 33
15 65
95 65
35 65
55 15
75 65
85 65
45 85
25 95
5 65
40 90
10 90
60 90
80 90
30 80
50 30
70 80
20 80
100 10
82 42
52 82
12 82
2 82
72 2
62 42
32 82
22 72
92 42
16 26
56 16
76 16
6 76
86...

output:

496
544
142
142
1202
1202
1274
1202
1166
1166
138
402
402
402
402
402
480
114
114
114
102
102
400
400
400
1074
1074
1880
1880
1880
1560
1560
1560
4736
4736
7550
7550
366
7550
7150
7150
4480
350
240
20
20
20
21
70
66

result:

ok 50 numbers

Test #36:

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

input:

1000 999 150
200 8
584 8
712 8
168 200
360 8
904 200
616 168
968 168
456 8
232 168
72 200
1000 968
488 616
872 488
296 616
392 968
136 392
808 904
776 1000
648 392
104 136
328 872
40 808
424 200
936 136
744 712
264 136
552 136
520 616
680 40
840 200
856 248
24 856
728 24
184 728
280 184
216 280
88 8...

output:

79
79
1138
1138
1202
1202
1186
1186
1186
1186
1186
1186
1186
1186
1186
1186
1186
1186
18080
18080
18080
18080
18080
18080
18080
18080
18080
18080
18080
18080
1138
1138
29288
29288
29288
9362
9362
9362
9362
9362
9362
9362
9362
9362
9362
9362
43514
43514
43514
43514

result:

ok 50 numbers

Test #37:

score: 0
Accepted
time: 20ms
memory: 41952kb

input:

1000 999 1500
181 149
853 181
725 181
85 149
53 725
469 853
341 53
501 469
245 501
309 53
661 53
565 501
117 85
21 469
693 565
597 693
629 309
981 501
213 85
949 341
885 53
821 597
917 21
373 949
533 597
277 629
437 277
757 565
405 597
789 277
716 812
108 716
204 812
556 204
844 812
588 812
780 844
...

output:

78
78
78
83
83
83
83
83
83
90
90
90
312
83
306
306
306
306
2406
2406
2406
2406
2406
2406
330
330
69
69
69
69
68
68
68
68
68
68
1227
1227
1227
1227
68
1227
1227
1199
1199
256
256
256
252
236
236
736
736
736
736
62
62
62
62
72
72
276
276
276
276
74
74
3736
1134
1134
1134
1134
1134
642
642
2604
1104
11...

result:

ok 500 numbers

Test #38:

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

input:

100 99 15000
96 26
56 96
86 56
36 86
66 86
46 66
6 36
16 96
76 86
100 50
20 50
90 20
40 20
70 50
10 100
80 100
30 100
60 90
29 59
69 59
19 29
9 59
99 29
89 19
49 9
79 89
39 69
14 24
54 24
4 14
64 4
84 24
34 64
94 24
74 84
44 84
57 77
87 57
37 57
7 57
47 37
27 37
67 77
17 27
97 77
32 92
2 92
12 2
72 ...

output:

448
392
376
376
842
842
914
368
368
368
368
368
368
368
368
368
368
368
996
978
170
170
24
24
24
24
24
443
224
224
842
102
914
336
336
102
102
102
106
28
269
269
269
269
436
436
404
404
340
5504
388
388
233
716
716
233
1791
716
716
296
305
305
30
30
29
102
98
118
98
98
98
98
98
98
304
304
304
304
30...

result:

ok 5000 numbers

Test #39:

score: 0
Accepted
time: 193ms
memory: 48740kb

input:

10000 9999 15000
6291 391
6391 391
1591 6291
191 391
7891 191
9591 6391
1091 6391
4191 6291
7091 7891
4891 9591
9791 1091
591 6291
9891 7891
9491 9591
91 9791
5991 7091
4391 9591
691 1091
8191 7091
1191 191
3391 9491
8791 591
5191 7091
5891 9491
3691 3391
3791 5991
3191 8791
7791 3691
4791 591
1791 ...

output:

1912
1912
1912
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
2040
498
498
498
498
498
498
498
498
498
498
498
498
498
498
498
498
498
498
498
498
538
538
538
538
538
...

result:

ok 5000 numbers

Test #40:

score: 0
Accepted
time: 562ms
memory: 68140kb

input:

100000 99999 15000
79655 88187
84711 79655
89135 88187
1919 79655
31623 89135
56587 1919
44263 84711
29727 84711
35731 56587
19931 44263
7291 44263
52163 31623
77759 56587
73967 35731
17719 56587
45211 7291
4131 73967
87871 52163
53427 79655
53111 88187
73335 77759
2235 4131
47107 53111
96087 7291
2...

output:

894
894
3280
3280
3280
3280
3280
3280
3280
3280
3280
3280
3280
3280
3280
830
830
830
830
830
830
830
830
830
830
830
830
830
830
830
830
830
830
830
838
838
838
838
838
838
838
838
878
878
878
878
878
878
878
878
878
878
878
878
878
878
878
878
878
878
878
878
878
4581
4581
4581
4581
4581
4581
4581
...

result:

ok 5000 numbers

Test #41:

score: 0
Accepted
time: 1218ms
memory: 65260kb

input:

10000 9999 90000
5856 1356
4156 5856
8956 5856
4356 4156
156 4156
2056 4356
5956 8956
5056 1356
2356 5956
256 4156
4756 4156
6356 1356
56 4156
756 2056
2456 2356
8656 2056
8256 1356
7856 8956
7156 5856
9656 4156
7656 256
8356 8956
6056 2056
356 1356
6556 2056
456 5056
2756 5056
1056 8656
9456 1356
4...

output:

102088
102088
102088
102088
102088
102088
102088
102088
102088
102088
102088
102088
102088
102088
102088
102088
102088
4432
4432
4432
4432
4432
4432
4432
4432
4432
4432
4432
4432
121
121
121
486
486
486
486
486
486
486
486
486
486
486
486
126
126
126
126
126
126
126
506
506
506
506
506
506
506
506
5...

result:

ok 30000 numbers

Test #42:

score: 0
Accepted
time: 648ms
memory: 63044kb

input:

50000 49999 30000
4114 26962
29426 4114
6354 4114
13970 29426
46898 13970
35922 29426
41746 4114
8594 26962
44210 29426
7250 46898
30546 26962
20690 13970
36594 4114
47122 13970
45778 4114
754 7250
26066 35922
2098 35922
32562 8594
46674 8594
39506 6354
5458 7250
36818 26962
22706 754
12850 35922
46...

output:

187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
187
768
768
768
768
768
768
768
768
768
189
189
189
189
4819
4819
4819
4819
4819
4819
4819
4819
4819
4819
4819
4819
4819
4819
4819
4819
4819
4819
48...

result:

ok 10000 numbers

Test #43:

score: 0
Accepted
time: 2372ms
memory: 96968kb

input:

100000 99999 99999
23014 23330
1842 23330
82106 1842
9742 1842
65990 82106
61250 1842
22066 9742
98222 65990
81158 1842
40394 9742
89690 23330
50506 23014
44186 1842
11322 50506
81790 44186
1526 50506
38814 65990
52718 1842
67886 9742
59986 82106
76102 50506
65042 22066
26806 9742
11638 98222
5950 5...

output:

237384
237384
237384
237384
237384
237384
237384
237384
237384
237384
237384
7078
7078
7078
7078
7078
7078
7078
7078
6716
6716
6716
6716
6716
6716
6716
6716
268488
268488
268488
268488
268488
268488
268488
268488
268488
268488
268488
268488
268488
268488
268488
268488
268488
268488
7942
7942
7942
79...

result:

ok 33333 numbers

Test #44:

score: 0
Accepted
time: 1647ms
memory: 75652kb

input:

100000 99999 100000
2 1
3 2
4 3
5 4
6 5
7 6
8 2
9 3
10 5
11 9
12 5
13 9
14 11
15 1
16 14
17 5
18 8
19 14
20 11
21 18
22 2
23 6
24 2
25 17
26 3
27 10
28 22
29 21
30 25
31 13
32 27
33 21
34 20
35 9
36 27
37 29
38 5
39 33
40 29
41 37
42 32
43 22
44 11
45 40
46 8
47 42
48 20
49 23
50 12
51 16
52 32
53 4...

output:

2226
2226
2226
2226
2226
2226
2226
2226
2226
2226
2226
2226
2226
2226
2226
2226
2226
2226
1797
1797
1797
1031
1031
19
1031
1031
1031
1031
1031
1031
1031
1031
1031
642
49
49
24
2580
49
49
460
49
30
49
49
49
24
49
49
32
49
49
8
49
48
48
5735
54
4
3
48
48
48
48
48
24
48
48
48
60
48
323
7
13
46
112
688
...

result:

ok 999 numbers

Test #45:

score: 0
Accepted
time: 1768ms
memory: 75476kb

input:

100000 99999 100000
2 1
3 2
4 2
5 2
6 2
7 4
8 6
9 7
10 5
11 2
12 3
13 1
14 1
15 4
16 11
17 2
18 3
19 12
20 14
21 11
22 3
23 4
24 16
25 24
26 14
27 18
28 9
29 2
30 4
31 19
32 31
33 19
34 27
35 22
36 22
37 5
38 8
39 30
40 14
41 20
42 28
43 9
44 25
45 15
46 26
47 16
48 10
49 27
50 34
51 33
52 30
53 36
...

output:

146
146
146
146
146
146
146
146
146
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
4
47
47
47
47
47
47
47
47
47
47
47
18
47
47
36
47
47
47
47
47
87
47
47
47
47
47
36
47
47
47
112
47
47
11
47
1902
36
324
8
33
316
182
182
3
182
96
182
38
182
62
136
2
182
3536
107
182
182
182
2016
182
426
38
182...

result:

ok 970 numbers

Test #46:

score: 0
Accepted
time: 2285ms
memory: 65868kb

input:

100000 99999 100000
2 1
3 1
4 2
5 1
6 2
7 3
8 2
9 2
10 3
11 8
12 4
13 6
14 11
15 3
16 3
17 8
18 5
19 13
20 13
21 14
22 2
23 19
24 11
25 24
26 12
27 24
28 24
29 8
30 3
31 24
32 2
33 32
34 12
35 17
36 14
37 18
38 36
39 10
40 20
41 4
42 10
43 21
44 41
45 24
46 30
47 6
48 11
49 41
50 28
51 36
52 38
53 3...

output:

4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
4246
...

result:

ok 98997 numbers

Test #47:

score: 0
Accepted
time: 2396ms
memory: 66052kb

input:

100000 99999 100000
2 1
3 2
4 1
5 2
6 4
7 2
8 2
9 6
10 9
11 10
12 9
13 5
14 6
15 11
16 2
17 5
18 8
19 11
20 4
21 7
22 16
23 6
24 22
25 8
26 19
27 10
28 6
29 20
30 28
31 14
32 6
33 30
34 19
35 11
36 17
37 27
38 8
39 25
40 5
41 10
42 38
43 4
44 28
45 43
46 34
47 26
48 32
49 13
50 1
51 3
52 36
53 13
54...

output:

2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
2468
...

result:

ok 99026 numbers

Test #48:

score: 0
Accepted
time: 11ms
memory: 41248kb

input:

14 13 1
1 2
1 3
1 12
2 4
2 5
3 6
3 7
4 8
4 9
5 10
7 11
12 13
13 14
3 1

output:

213

result:

ok 1 number(s): "213"