QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#308462#7181. Graph Cutskevinshan#TL 954ms170376kbC++172.4kb2024-01-20 06:05:572024-01-20 06:05:57

Judging History

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

  • [2024-01-20 06:05:57]
  • 评测
  • 测评结果:TL
  • 用时:954ms
  • 内存:170376kb
  • [2024-01-20 06:05:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
vector<int> adj[maxn], seg[4*maxn], res;
array<int, 2> e[maxn];
int n, m, q, ban[maxn], in[maxn], qu[maxn], ans[maxn], pref[maxn], no[maxn];
map<int,int> ex;

void add(int val, int l, int r, int id = 1, int lx = 1, int rx = q)
{
    if (lx > r || rx < l) return;
    if (lx >= l && rx <= r) return void(seg[id].emplace_back(val));
    int m = (lx + rx) >> 1;
    add(val, l, r, id<<1, lx, m);
    add(val, l, r, id<<1|1, m+1, rx);
}

inline void upd(int i)
{
    for (int id: adj[i]) if (!ban[id])
    {
        int j = e[id][0] ^ e[id][1] ^ i;
        if (in[j]) no[id] = 1;
        else res.emplace_back(id), no[id] = 0;
    }
    in[i] = 1;
}

inline void rupd(int i)
{
    for (int id: adj[i]) if (!ban[id])
    {
        int j = e[id][0] ^ e[id][1] ^ i;
        if (in[j]) res.emplace_back(id), no[id] = 0;
        else no[id] = 1;
    }
    in[i] = 0;
}

void solve(int id = 1, int l = 1, int r = q)
{
    if (!(pref[r] - pref[l-1])) return;
    for (int i: seg[id]) upd(i);
    while (res.size() && (no[res.back()] || ban[res.back()])) res.pop_back();
    if (l == r)
    {
        if (qu[l]) 
        {
            // while (res.size() && (no[res.back()] || ban[res.back()])) res.pop_back();
            ans[l] = res.size() ? res.back() : 0;
            if (res.size()) res.pop_back();
            ban[ans[l]] = 1;
        }
        for (int i: seg[id]) rupd(i);
        return;
    }
    int m = (l + r) >> 1;
    solve(id<<1, l, m);
    solve(id<<1|1, m+1, r);
    for (int i: seg[id]) rupd(i);
    while (res.size() && (no[res.back()] || ban[res.back()])) res.pop_back();
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    cin>>n>>m;
    for (int i=1; i<=m; i++) cin>>e[i][0]>>e[i][1], adj[e[i][0]].emplace_back(i), adj[e[i][1]].emplace_back(i);
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        char c; int x;
        cin>>c;
        if (c == '?') qu[i] = 1, pref[i] = 1;
        else 
        {
            cin>>x;
            if (!ex.count(x)) ex[x] = i;
            else add(x, ex[x], i-1), ex.erase(x);
        }
        pref[i] += pref[i-1];
    }
    for (auto [u, v]: ex) add(u, v, q);
    if (q > 0) solve();
    for (int i=1; i<=q; i++) if (qu[i] == 1) cout<<ans[i]<<"\n";
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 17ms
memory: 127428kb

input:

4 5
1 2
1 3
1 4
2 3
2 4
10
+ 1
+ 2
?
?
?
?
?
- 2
?
?

output:

5
4
3
2
0
1
0

result:

ok q=10

Test #2:

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

input:

0 0
0

output:


result:

ok q=0

Test #3:

score: 0
Accepted
time: 15ms
memory: 130740kb

input:

0 0
1
?

output:

0

result:

ok q=1

Test #4:

score: 0
Accepted
time: 47ms
memory: 132544kb

input:

1000 2000
1 50
1 88
331 1
1 352
1 497
2 32
2 282
550 2
989 2
334 3
3 665
4 38
4 69
4 343
4 451
589 4
917 4
89 5
5 162
675 5
681 6
7 22
127 7
7 592
7 672
787 7
8 310
107 9
9 137
184 9
9 244
378 9
446 9
9 658
883 9
65 10
75 10
414 10
10 468
686 10
245 11
269 11
11 386
403 11
493 11
394 12
493 12
565 1...

output:

208
207
1990
1958
1475
1474
879
1861
1737
1493
1147
1237
967
1768
657
854
853
1304
426
1225
852
851
89
951
949
1421
1480
1479
1478
243
1201
896
895
1880
1725
846
1529
278
1562
1561
1560
1042
1667
973
972
687
1557
1556
614
1789
1788
1648
1687
1851
1956
1696
1797
1796
1267
1869
941
1076
49
968
1860
25...

result:

ok q=100000

Test #5:

score: 0
Accepted
time: 63ms
memory: 134812kb

input:

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

output:

77103

result:

ok q=100000

Test #6:

score: 0
Accepted
time: 903ms
memory: 153132kb

input:

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

output:

29181
99603
62280
62279
99120
81726
98646
81725
87435
87434
18678
18677
53625
84105
46379
32519
76027
64169
93794
55427
66784
66010
52402
93010
93009
93464
58064
1334
49277
23435
23434
16244
42389
99544
96979
23825
23824
23822
47999
16243
16241
88802
62824
99215
22259
52709
99404
79780
96598
98353
6...

result:

ok q=100000

Test #7:

score: 0
Accepted
time: 789ms
memory: 152104kb

input:

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

output:

64436
66011
66010
52095
64435
90090
66009
65751
23045
99678
91553
37553
69546
69545
74256
93353
54531
41028
74928
74927
97335
97334
97333
97331
891
890
889
98456
88803
92778
887
40685
40684
58353
46053
46052
82661
82660
82659
58640
58639
92300
92299
62280
37552
95025
26145
26144
9581
96678
63096
467...

result:

ok q=100000

Test #8:

score: 0
Accepted
time: 597ms
memory: 170308kb

input:

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

output:

0
48960
37553
99671
99670
97196
66785
77526
9156
9155
9154
56610
56609
56608
88205
88204
56607
56606
56604
56603
97470
97469
97468
97467
96755
87591
87590
87589
87588
39650
14190
14189
14188
14187
14186
70035
70034
70033
70032
91806
91805
91804
91803
91802
89385
97403
97402
97401
70278
94325
94324
7...

result:

ok q=100000

Test #9:

score: 0
Accepted
time: 432ms
memory: 150940kb

input:

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

output:

0
0
0
0
0
0
0
0
33251
33250
33249
33248
33247
96360
97403
97402
97401
97400
97399
65490
65489
65488
65487
65486
87278
87277
87276
98303
98302
98301
86151
86150
86149
86148
99246
98300
98299
98298
98297
98296
98295
98294
96906
77945
77944
77943
77942
77941
77940
98820
90228
72186
72185
94010
72184
43...

result:

ok q=100000

Test #10:

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

input:

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

output:

0
0
0
0
62553
62552
62551
62550
62549
62548
62547
62546
62545
62544
62543
62542
62541
62540
20678
20677
66785
20676
20675
20674
20673
20672
24215
24214
24213
24212
24211
24210
24209
24207
24206
24205
24204
24203
24202
84975
84974
84973
84972
99660
99659
99658
99657
99656
99655
99654
99646
99638
9962...

result:

ok q=100000

Test #11:

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

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok q=100000

Test #12:

score: 0
Accepted
time: 61ms
memory: 136208kb

input:

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

output:

63093

result:

ok q=100000

Test #13:

score: 0
Accepted
time: 884ms
memory: 153364kb

input:

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

output:

80375
80374
88950
91425
91424
86961
98860
94630
88802
82660
39995
96277
18274
18273
65227
79979
88801
65750
99245
99244
88949
93352
48959
96754
71477
60059
12109
3539
50852
99427
32885
98195
45724
45723
2660
33250
99380
91165
77944
81344
95585
48958
95494
86960
86958
68555
90902
24989
39302
53320
53...

result:

ok q=100000

Test #14:

score: 0
Accepted
time: 770ms
memory: 170376kb

input:

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

output:

64965
88506
88205
88204
75591
75587
41028
12528
5286
60060
60056
70520
70516
70515
98406
99120
99116
61731
97196
99115
99113
93353
10005
10004
98978
73803
73799
73798
30303
74256
96980
38256
96831
74705
98303
29930
63634
63633
93349
35061
35057
11271
61727
93352
93351
69791
94010
87900
87896
69053
6...

result:

ok q=100000

Test #15:

score: 0
Accepted
time: 601ms
memory: 169584kb

input:

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

output:

69053
86151
86148
79380
79377
79376
79375
98196
98195
98194
85653
98190
98193
91806
67803
33615
33614
33613
94530
94529
94527
94526
94525
67802
67801
67797
67795
67794
96026
99666
89528
89527
91680
91679
67550
67549
67548
38256
38255
38254
38248
38247
62553
62552
74030
85316
96755
96754
96753
48960
...

result:

ok q=100000

Test #16:

score: 0
Accepted
time: 437ms
memory: 152816kb

input:

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

output:

99215
91552
50852
50849
50848
58064
58061
58060
58065
18274
18271
18270
18267
32152
32149
36490
36487
36486
36483
97600
97597
97596
99670
99667
13775
13772
13768
13766
13764
13762
13761
95309
94115
94112
98084
98081
98077
98085
98083
94108
12944
92777
92774
15835
15832
81725
81722
81718
81716
81714
...

result:

ok q=100000

Test #17:

score: 0
Accepted
time: 250ms
memory: 150244kb

input:

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

output:

96600
77315
77313
77310
97728
97726
97723
78153
78151
78152
78150
78149
79178
79176
79173
79172
79171
40341
40339
40336
40335
40334
40340
40338
40337
40333
40331
40329
40327
40324
40323
40322
40321
40319
40318
40316
40315
40314
40312
80571
80569
80566
76676
76674
76671
76670
76669
76667
76665
76663
...

result:

ok q=100000

Test #18:

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

input:

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

output:

81915
81913
81912
81910
81909
81904
81903
81901
81899
81896
81893
81890
81889
81888
81887
81884
81883
81882
81881
81878
81875
81872
98978
98976
98975
98973
98972
98967
98966
98964
98962
98959
98956
98953
98952
98951
98950
98947
98946
98945
98944
98941
98863
98740
98467
98418
98265
98047
97990
97932
...

result:

ok q=100000

Test #19:

score: 0
Accepted
time: 78ms
memory: 136000kb

input:

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

output:

98405

result:

ok q=100000

Test #20:

score: 0
Accepted
time: 894ms
memory: 155844kb

input:

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

output:

90340
90325
98710
98735
62800
33953
33943
24190
92280
98546
97529
97516
87584
26903
83203
4844
4839
95396
73796
97722
47026
98815
71946
26140
26145
36486
36491
36490
85651
84628
33249
99624
76459
72418
36489
97726
97721
92893
92889
24989
97052
97051
97046
69790
81152
57194
57193
57188
57184
57183
26...

result:

ok q=100000

Test #21:

score: 0
Accepted
time: 768ms
memory: 167280kb

input:

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

output:

25741
69526
64945
64965
28802
99676
99680
71476
71475
71460
71478
48958
99246
40683
88801
83389
89809
88504
88503
18676
18678
68554
95674
97534
22258
77313
70999
71001
58351
98938
99354
99353
81724
81726
91806
26143
66009
98083
98976
98978
94114
94116
89668
4849
91678
46051
93238
81343
81342
45394
5...

result:

ok q=100000

Test #22:

score: 0
Accepted
time: 601ms
memory: 167872kb

input:

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

output:

0
0
78750
78701
78700
78603
74276
54025
78771
12089
78339
89790
83189
83182
83165
83210
27665
27671
90222
90228
90227
90226
90225
53010
52995
52988
52971
52946
91290
91275
91268
91251
91258
91226
97464
97470
99045
99040
99030
99023
99022
99051
36129
36135
36134
29924
29930
90630
90636
69294
96105
96...

result:

ok q=100000

Test #23:

score: 0
Accepted
time: 438ms
memory: 153020kb

input:

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

output:

65914
66011
66010
88409
81195
65861
50129
50076
50034
55033
47258
47355
81056
81003
19384
19331
19289
19288
19481
16556
16653
16652
16651
16650
6585
6584
6583
6582
6581
89714
89811
89810
89809
89808
89807
18178
18134
88259
72788
72766
72744
72885
38509
38487
38465
38456
38606
94999
92634
99356
99355...

result:

ok q=100000

Test #24:

score: 0
Accepted
time: 263ms
memory: 150660kb

input:

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

output:

0
0
0
0
94325
59391
69931
93582
52299
94266
59251
59495
59494
59493
70035
56506
56366
56326
91449
69907
59367
94302
70012
59472
61627
61487
59219
61603
61708
91530
56587
56482
56610
56609
56608
97888
97911
97910
97909
40662
40625
92518
92541
90205
90228
56316
56315
28782
98456
98455
98454
65988
6596...

result:

ok q=100000

Test #25:

score: 0
Accepted
time: 34ms
memory: 131124kb

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok q=100000

Test #26:

score: 0
Accepted
time: 63ms
memory: 135988kb

input:

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

output:

53093

result:

ok q=100000

Test #27:

score: 0
Accepted
time: 938ms
memory: 153612kb

input:

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

output:

79124
32194
32193
2221
61277
68672
99895
15446
80133
89285
55216
55215
50929
96353
99909
5293
5292
75948
47750
99747
7885
76602
11706
56110
69418
97154
99565
42453
25017
92989
92985
25013
25011
25010
1778
1774
98778
99955
75728
87616
22285
76167
76163
86159
86155
96438
90145
96521
64806
84626
99997
...

result:

ok q=100000

Test #28:

score: 0
Accepted
time: 859ms
memory: 169972kb

input:

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

output:

4422
49662
49661
16678
16677
16676
72304
72303
72302
72301
90281
90280
80324
85484
98050
54908
80719
62922
74605
71356
94858
1337
83554
6163
51857
85653
55804
97588
7888
3106
3105
92628
90141
90140
99972
91100
98407
43459
43458
43457
43456
43455
40737
53701
18707
99999
99998
97587
97585
97584
86648
...

result:

ok q=100000

Test #29:

score: 0
Accepted
time: 644ms
memory: 169740kb

input:

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

output:

98110
98109
99504
99503
99502
87765
87764
99994
69896
69895
69894
99993
99864
99922
99921
99920
58429
58428
97227
97226
99989
99988
47742
93220
93219
93214
96263
96262
96257
68404
68403
68398
68397
88380
88379
33651
33650
33645
33644
33643
98515
98514
98509
98508
98507
98506
98505
28078
28077
28072
...

result:

ok q=100000

Test #30:

score: 0
Accepted
time: 439ms
memory: 151928kb

input:

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

output:

0
79924
79923
79922
79921
79920
79919
79918
79917
92989
92988
51230
51229
72772
51228
51227
51226
51225
99260
92987
92986
95157
95156
95155
59293
59292
59291
59290
59289
71355
71354
71353
67399
67398
67397
59288
59287
59286
98873
98872
46438
33291
33290
96603
46437
99595
99594
99747
99746
99745
9974...

result:

ok q=100000

Test #31:

score: 0
Accepted
time: 262ms
memory: 154912kb

input:

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

output:

0
0
0
0
0
0
93449
93448
93447
93446
93445
93444
93443
93442
91493
91492
91491
91490
21492
21491
93441
77235
77234
77233
77232
77231
78081
78080
78079
78078
78077
78076
78075
78074
78073
78072
78071
78070
78069
78068
78067
91489
5727
99829
99828
99827
99826
99825
99824
99823
99822
99821
99820
99819
9...

result:

ok q=100000

Test #32:

score: 0
Accepted
time: 23ms
memory: 133396kb

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok q=100000

Test #33:

score: 0
Accepted
time: 63ms
memory: 135860kb

input:

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

output:

4855

result:

ok q=100000

Test #34:

score: 0
Accepted
time: 930ms
memory: 152976kb

input:

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

output:

29205
99785
99783
99782
99791
98960
68156
76367
66099
94747
56385
29580
99980
99561
94224
55495
55494
11275
90959
96841
96840
67390
95441
99645
84783
99990
1778
99955
85815
85814
86480
86315
92007
92002
36886
97155
97152
98516
99536
891
888
95820
6588
71113
95056
78702
97001
97000
59577
99811
62091
...

result:

ok q=100000

Test #35:

score: 0
Accepted
time: 831ms
memory: 154040kb

input:

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

output:

63187
63184
43455
45453
94646
39004
76150
64529
94951
97443
97440
97439
99845
91876
91490
91487
28838
28835
28834
28831
28830
28826
68654
96172
29214
29216
29215
29213
22285
97436
43452
82439
31453
32925
95905
95902
73229
99502
74598
74595
74591
99992
17889
17887
97721
44790
44788
78698
96839
96837
...

result:

ok q=100000

Test #36:

score: 0
Accepted
time: 651ms
memory: 168708kb

input:

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

output:

95543
95541
92753
82449
51242
51244
51243
51241
51238
55511
89435
89433
92264
44137
44135
66117
93570
93572
93571
93569
71120
61551
61549
15445
42115
42113
97374
97372
97371
97369
20705
72544
86656
86654
86653
82636
95448
95450
95449
92992
92990
92989
92987
92986
92985
98110
85319
71118
71117
71115
...

result:

ok q=100000

Test #37:

score: 0
Accepted
time: 451ms
memory: 151624kb

input:

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

output:

96432
96431
98873
98870
89858
44132
80909
80908
80907
93335
47424
47423
18698
18697
18696
18693
18692
18689
88385
88384
99892
99891
19503
19500
90965
90964
62099
62098
62097
26180
26177
26176
26173
14204
14203
14202
14199
14198
14195
99406
99405
99404
99401
98872
98871
98868
21100
21099
21098
21095
...

result:

ok q=100000

Test #38:

score: 0
Accepted
time: 257ms
memory: 148612kb

input:

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

output:

81300
81299
81298
81293
81292
81291
64792
64791
81289
81288
81287
73693
73692
80320
70627
70626
97151
97150
97149
97144
97143
97142
97140
13370
13367
94755
92260
92259
92258
92253
92257
92256
92255
82066
82065
82064
33287
33286
33285
33280
33284
33283
33282
33281
33277
61260
61259
61258
61253
61252
...

result:

ok q=100000

Test #39:

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

input:

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

output:

99863
99861
99860
99859
99858
99856
99854
99852
99851
99849
99831
99813
99774
99731
99708
99659
99549
99519
99488
99355
99319
99998
99995
99992
99988
99983
99970
99953
99932
99920
99893
99845
99828
99789
99746
99723
99674
99564
99534
99503
99370
99334
99297
99259
99220
99139
99097
99054
99010
98872
...

result:

ok q=100000

Test #40:

score: 0
Accepted
time: 57ms
memory: 134124kb

input:

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

output:

96092

result:

ok q=100000

Test #41:

score: 0
Accepted
time: 954ms
memory: 155420kb

input:

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

output:

4925
41717
79273
87567
16664
97443
97445
23848
23841
99259
15438
15431
61546
84962
97721
97714
90827
47742
47735
80908
93674
99998
62374
89568
89567
45786
5287
99593
99592
66115
64534
65065
82062
49345
99534
65064
66631
62919
5722
5721
92380
62373
98515
99809
35458
92256
92005
96760
10435
87608
8760...

result:

ok q=100000

Test #42:

score: 0
Accepted
time: 786ms
memory: 151368kb

input:

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

output:

0
14200
91757
80327
80324
25010
71595
71592
82261
82258
89290
45453
93455
93452
99999
99990
53394
53392
46112
95351
95349
50294
50292
98172
12118
12116
29211
29209
29206
99972
99970
32922
75280
72071
72069
72066
56099
56097
89866
89865
96088
93109
68162
71359
72307
72306
90969
90966
48704
16664
5727...

result:

ok q=100000

Test #43:

score: 0
Accepted
time: 632ms
memory: 151576kb

input:

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

output:

0
0
0
0
0
0
0
65322
65321
65320
91155
65189
91228
85062
85039
82177
6520
6593
52394
52371
92911
92888
91109
85016
85002
82131
78378
98710
98726
40713
40678
90399
90365
97571
97587
94631
94596
99252
93554
93562
99244
99239
55489
55481
55476
55497
68900
68892
68908
68907
68906
99782
99774
98817
98825
...

result:

ok q=100000

Test #44:

score: 0
Accepted
time: 437ms
memory: 151624kb

input:

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

output:

8401
43032
42907
42908
45593
78503
78502
78501
78500
78499
78498
78497
44602
44583
44461
58251
65400
65589
58232
58177
92613
82241
78483
65569
61252
45762
63876
94836
92532
36515
36535
97837
47395
47415
74609
95445
95909
95889
95843
95354
95908
48061
48041
96434
9164
9144
94548
94547
893
892
80126
8...

result:

ok q=100000

Test #45:

score: 0
Accepted
time: 277ms
memory: 151428kb

input:

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

output:

0
75271
75270
75269
75197
97299
97298
97297
97296
97295
97294
97293
97292
97291
97290
53014
53088
38579
62838
62912
97273
75245
99656
97280
75252
68890
62893
53069
38634
99675
99674
99673
99672
86295
86288
86240
75105
68743
62746
52922
86314
86313
86312
86311
86310
86309
86308
86307
86306
86305
8630...

result:

ok q=100000

Test #46:

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

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok q=100000

Test #47:

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

input:

100000 100000
5722 1
35633 1
76503 1
2 8454
2 93428
3 91414
4 55025
21132 5
6 22400
6 80941
7 22043
7 29361
7 73158
78568 7
8 24159
8 26175
27612 9
39375 9
5454 10
24262 10
40601 10
11 8620
59525 11
11 79781
11 92891
64034 12
33728 14
14 59378
14 79826
560 16
16 31445
35262 16
17911 17
28509 17
9364...

output:

9415

result:

ok q=100000

Test #48:

score: 0
Accepted
time: 137ms
memory: 145804kb

input:

100000 100000
32763 1
1 41318
52251 1
66464 2
83572 2
67186 5
7 64990
34545 8
8 96178
8628 9
10 8181
94794 15
16 33467
16 34451
85594 16
17 20413
31799 17
17 41753
18 61787
71853 18
19 5788
19 49136
97968 19
34661 20
20 61751
95244 20
20211 21
31082 21
22 96882
53538 23
53831 24
81268 24
25 52202
61...

output:

48490
48489
75581
30538
94777
1066
53585
12375
93652
42757
31024
26264
76827
21768
98186
73435
44592
64447
33295
23825
19557
81787
78571
18985
61572
33914
88009
1845
66520
66519
1844
5177
76920
81311
73831
26010
98826
18794
13628
97482
59494
90351
89065
54028
91763
541
97610
82244
82243
96778
95965
...

result:

ok q=100000

Test #49:

score: 0
Accepted
time: 131ms
memory: 141612kb

input:

100000 100000
98 1
1 39536
2 7197
2 36925
64304 2
3 90981
4 55694
4 58594
6 14112
6 61223
49657 7
49961 8
9 63064
84290 9
9616 10
10 26834
10 81424
11 28592
66665 11
11 67518
12 65671
12 77007
13 83518
88724 13
14 22525
28934 14
38904 15
18454 16
16 34371
33103 17
63576 17
46939 18
67514 18
18 72374...

output:

84279
87343
27768
27767
82259
91254
96086
72114
41137
72113
4317
92752
85271
62782
8020
90151
91342
99011
92871
96321
54198
51863
10169
96533
49436
83147
83146
83145
69445
28220
63739
54550
54549
51916
43326
95801
94649
89676
84144
96987
41930
99923
93480
65469
92883
69868
60315
88459
12160
15719
15...

result:

ok q=100000

Test #50:

score: 0
Accepted
time: 101ms
memory: 140736kb

input:

100000 100000
1 30554
51310 1
1 71883
94585 1
2 40250
59351 2
2 60517
72989 3
4 3248
14035 4
4 90751
5 786
6 10125
87221 6
22862 7
7 57323
67940 7
40455 8
8 66854
9 34854
9 87440
43694 10
10 57462
82982 10
94968 10
47934 11
11 71829
24007 12
44565 12
48286 12
70260 12
12 70368
98761 12
20547 14
7549...

output:

71478
71477
50261
40431
49551
49550
26532
58649
52035
76839
35164
76838
3271
92807
41475
99176
87811
85164
50164
56894
10949
9191
82770
76203
63000
16879
36518
41209
98697
18538
76160
78771
66650
3678
97329
74818
60494
33368
95234
71439
50660
63519
25349
63518
57130
29370
72751
81621
35233
12467
683...

result:

ok q=100000

Test #51:

score: 0
Accepted
time: 78ms
memory: 137096kb

input:

100000 100000
26140 1
46196 2
2 54845
78912 3
3 90871
4 12358
5 33609
5 43410
5 78393
47818 6
7 48862
13216 8
8 36636
8 40979
52931 8
8 80000
94821 8
52306 10
14072 12
36807 12
66342 12
344 13
13 4469
13 14570
13 52573
15 29037
15 38532
86576 15
16 9718
43023 16
16 86523
19 16448
20 15703
20 62471
8...

output:

0
0
0
0
33676
0
0
0
81127
70591
25083
25082
25081
64094
56000
43568
28482
96503
69480
68074
67311
12956
12955
12954
12953
9128
9127
9126
6360
9074
76367
61668
1281
81918
22544
90105
13771
81470
90104
90103
90102
23814
81469
81468
845
62238
88273
62237
48282
34967
28457
14145
8056
88272
67816
59096
4...

result:

ok q=100000

Test #52:

score: 0
Accepted
time: 52ms
memory: 140348kb

input:

100000 100000
2005 1
1 15170
57799 2
4 38977
4 57240
42542 5
5 53318
5 75678
6 88650
65147 7
8 53626
8 70633
22352 10
11 49862
12 14548
12 50661
12 69416
13 22675
13 57792
3230 14
61629 16
16 94304
19 4752
11292 19
19 23963
47970 19
3280 20
20 13431
37640 20
20 43437
22 59910
69629 22
94875 22
23 52...

output:

0
0
63812
63811
0
0
0
0
0
0
0
0
0
0
0
0
0
64070
0
0
0
0
0
0
0
0
0
0
0
0
0
17931
17930
0
0
0
0
0
0
0
0
0
0
25349
25298
22976
0
63870
46890
79011
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
74503
57471
54550
49655
23473
0
0
0
0
79932
79931
55883
0
0
0
0
0
0
0
0
95579
95578
94320
0
0
93452
72970
0
0
0
0
0
0
...

result:

ok q=100000

Test #53:

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

input:

100000 100000
40394 1
75982 2
3 18844
73366 3
88698 3
4020 6
6 73638
7 22013
65853 7
8 75952
8 91846
8 92431
35947 9
25852 10
60988 10
84698 10
49696 11
60792 11
94447 12
29797 13
14 32289
14 45866
85823 14
15 5953
19579 15
9976 16
16 26641
17 70399
80811 17
18 57277
19 24826
19 72978
15405 20
64474...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok q=100000

Test #54:

score: 0
Accepted
time: 103ms
memory: 143516kb

input:

100000 100000
1 46719
1 85926
2 31507
3 10325
25701 3
4 20660
4 24390
5 28826
5 32895
5 65707
5 85849
26769 6
35848 6
8 31592
9 6175
10 10273
10 49762
8543 11
12 1257
12 49533
67310 12
12 85402
4042 13
13 91901
14 36759
95374 14
40235 16
16 95131
17 47185
49412 17
86267 17
30733 18
19 36525
99630 20...

output:

45927

result:

ok q=100000

Test #55:

score: 0
Accepted
time: 122ms
memory: 148596kb

input:

100000 100000
1 14816
1 36843
1 67254
69974 1
3 22460
4 94861
51245 5
5 53683
54692 6
6 91387
6 91712
8 56288
8 88631
9 4475
23107 9
9 37340
18545 10
10 32507
10 37510
86500 10
57406 11
11 96238
486 12
12 44026
51175 13
14 92685
14 94886
14 99844
66818 15
58293 16
16 92531
17 32186
36963 18
18 53409...

output:

35268
38278
38280
26801
12361
29784
61456
40056
31178
77744
93174
95767
72285
33621
61457
10381
10380
12780
27140
71415
94667
53373
50463
16284
42262
83306
42330
42329
83984
16331
45676
6004
85765
99535
29141
37195
59858
88446
2847
98966
72061
13674
13427
46688
16304
74149
74148
90472
98446
40295
88...

result:

ok q=100000

Test #56:

score: 0
Accepted
time: 123ms
memory: 143784kb

input:

100000 100000
1 92961
32241 2
2 81221
4608 3
16927 3
18769 3
3 43374
22317 4
55044 4
18810 5
6 72739
61007 7
9 25577
9 27864
34366 9
10 16913
30734 10
40980 10
60805 10
74697 10
82279 10
10021 11
23696 12
36468 12
51197 12
86124 12
12 89628
14 6535
14 21742
14 36158
57841 14
15 81216
15 84873
16 457...

output:

76313
76312
84146
4615
40253
27078
23949
99712
98352
66103
78453
78452
58524
74472
25165
84115
69277
94283
58909
20392
98409
77516
93699
77515
87174
15163
1854
7830
7832
53485
41388
49207
14319
24739
93580
77739
75206
39228
48953
23956
50189
63563
57599
86770
71804
57598
50286
63896
79787
57208
6871...

result:

ok q=100000

Test #57:

score: 0
Accepted
time: 109ms
memory: 142660kb

input:

100000 100000
1 27333
1 84324
96084 1
9114 2
85952 2
3 5372
4 6733
9091 4
58622 4
4 86657
14441 5
55881 5
77265 5
5 80838
6 348
8 52617
8 61683
11583 9
9 73540
93581 9
94661 9
9 98721
46654 10
10 52226
12 55380
12 79729
13 40841
13 58505
80468 13
57058 14
14 59095
23508 15
68757 15
6286 17
17 39373
...

output:

15522
15521
15523
36320
95383
5032
25341
91379
36319
15196
5030
23234
65411
25342
63894
65919
6141
9412
14161
34206
14159
25025
69922
14160
51848
50227
44860
81774
44862
44861
11446
90274
81422
80725
57934
33682
4801
66918
39835
88142
71780
18486
18488
61263
74644
71781
10108
58337
58336
18369
15762...

result:

ok q=100000

Test #58:

score: 0
Accepted
time: 91ms
memory: 143724kb

input:

100000 100000
60818 1
1 61357
77477 1
3 45025
59533 3
46950 4
78991 4
97104 4
36194 5
6 64485
1740 7
5623 8
23553 8
16292 9
62566 9
9 98158
10 23566
10 47129
84382 10
10 89508
11 12522
54918 11
82691 14
89591 14
15 22620
22939 16
56415 16
16 83923
18 29619
18 83502
19 24669
79130 19
43646 20
21 6966...

output:

10065
9947
10064
10067
10066
56242
66813
29589
88124
71957
88991
4741
95750
56241
31081
72931
50128
32048
4136
4134
30306
76882
4135
21481
17501
23291
67470
24008
23290
93063
55374
77120
64655
3393
59927
82335
40733
40073
94650
98071
80814
80420
77595
5829
94649
43980
61265
76643
22996
61262
57472
1...

result:

ok q=100000

Test #59:

score: 0
Accepted
time: 85ms
memory: 139484kb

input:

100000 100000
34616 1
58002 1
1 70045
10303 2
2 39631
40632 2
10056 3
41853 3
70173 3
4 92959
5 47483
16468 6
50684 6
67732 6
84535 7
47014 8
59046 9
10 65208
10 78362
11266 11
24545 11
12 21449
66415 12
92002 12
13 19643
13 23316
96267 14
91298 15
17801 16
49544 16
69757 16
4694 17
17 24548
221 18
...

output:

66894
66893
46224
73531
72637
10557
6100
42522
59259
38876
12147
27640
98772
27638
80256
43939
4178
91973
56740
83488
63479
99465
96478
70306
39179
57203
76296
49541
3850
97633
74942
67022
44163
34378
62495
73165
69202
19275
88353
67084
40921
59299
59260
51199
60849
38277
33907
42523
60042
37547
904...

result:

ok q=100000

Test #60:

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

input:

100000 100000
1 14279
25034 1
1 25644
1 33907
55554 1
32635 2
48898 2
67742 2
30821 3
62159 3
62878 4
4 99567
5427 5
81073 5
40389 6
68943 6
86783 6
7 7357
8 43901
8 49165
66447 8
15193 10
10 27651
52896 10
11 21927
31071 11
65058 11
1885 12
12 86604
13 34951
13 57211
73415 13
76672 13
31146 14
4934...

output:

12370
72435
11987
88913
99109
87883
25748
84241
99225
2496
98241
86421
22432
99067
42593
74294
18920
99089
61548
48027
93485
20838
95430
82633
97083
20364
30646
77154
98251
84739
50267
45946
97545
58883
26708
58108
76375
26599
9661
98198
40119
68293
91944
88190
69860
8422
87380
71847
98695
82549
636...

result:

ok q=100000

Test #61:

score: 0
Accepted
time: 112ms
memory: 136920kb

input:

100000 100000
36686 1
2 28317
3 43331
58975 3
9005 5
5 38587
85424 5
87253 5
91242 6
7 12636
7 28747
43112 7
56525 7
95056 7
8 67866
8 96414
15486 9
9 17569
9 27913
9 45216
57385 9
12037 10
10 26847
68194 10
10 69558
91082 10
1181 11
29864 11
11 51315
74564 11
11 99360
50347 12
12 70424
80616 12
810...

output:


result:

ok q=100000

Test #62:

score: 0
Accepted
time: 109ms
memory: 140144kb

input:

100000 100000
19575 1
26203 1
72508 1
1 97963
14667 2
16976 2
3 6175
3 67390
3 85817
3 95274
61098 4
5 63076
48837 6
6 85456
8 11139
8053 9
9 14304
9 42080
78302 9
87001 9
95714 9
10 11640
10 38250
11 68261
33284 12
34067 13
37576 13
13 83578
15 23823
35578 16
57809 16
17 35284
43161 17
17 47477
516...

output:


result:

ok q=100000

Test #63:

score: 0
Accepted
time: 106ms
memory: 137048kb

input:

100000 100000
36059 1
46485 1
23653 2
73424 2
2 74494
51828 3
4 33328
53661 4
34793 5
6 51871
55444 6
6 65656
8 16246
8 34477
10425 9
62445 9
21534 10
10 30313
60761 10
96061 10
7597 11
11 15469
63367 12
40382 13
14 75126
15 56288
15 84929
53927 16
64468 16
17 53139
18 5845
76176 18
19 24677
19 5891...

output:


result:

ok q=100000

Test #64:

score: 0
Accepted
time: 95ms
memory: 140468kb

input:

100000 100000
20177 2
2 98955
3 46743
3 46866
62628 3
12631 4
75181 4
5 54593
27546 6
6 31901
6 83336
6 90688
7 32220
7 63366
8 61776
37721 9
9 48206
9 70008
96585 9
10 62990
98079 10
11 11607
21944 11
11 80964
13 9208
13 49235
13 69968
13 85800
38176 14
57272 14
15 3765
16 67576
17 40546
17 44435
1...

output:


result:

ok q=100000

Test #65:

score: 0
Accepted
time: 101ms
memory: 137328kb

input:

100000 100000
1 33218
2 26924
4 22063
4 72727
83189 4
5 26165
50928 5
6 12110
17480 7
39161 7
7 76692
20436 8
36025 8
9 52297
9 58874
67940 9
10 17168
10 40179
10665 11
11 26766
11 26798
28558 11
41443 11
91932 11
11 96520
12 38384
89050 13
14 44040
14 60933
63286 14
14 91796
38298 15
83369 15
20977...

output:


result:

ok q=100000

Test #66:

score: 0
Accepted
time: 109ms
memory: 140036kb

input:

100000 100000
97038 1
2 12394
73478 2
27345 3
3 52828
3 94198
17649 4
34700 4
4 48092
90308 4
4 92571
5 73178
5 96066
1197 6
79796 6
6 95080
7 6897
7 96564
8 57604
8 70048
29738 10
10 42975
10 99064
11 20156
11 25952
51206 11
11 97949
38714 12
92965 12
10950 13
15 6617
8272 15
17383 15
37580 15
5035...

output:


result:

ok q=100000

Test #67:

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

input:

100000 100000
1 43054
1 66061
45045 4
81759 5
15827 6
6 40801
78430 6
6 83704
3488 9
32237 9
10 8261
10 37635
98555 10
82566 11
30294 12
68894 12
13 32989
92708 14
94972 14
15 41948
16 28327
20490 17
52712 17
18 23230
18 77251
9533 19
66382 19
20 10583
23214 22
32369 22
24 32167
75443 24
26 9052
278...

output:


result:

ok q=100000

Test #68:

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

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok q=100000

Test #69:

score: 0
Accepted
time: 23ms
memory: 135928kb

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok q=100000

Test #70:

score: -100
Time Limit Exceeded

input:

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

output:


result: