QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#308473#7181. Graph CutskevinshanTL 1429ms31444kbC++172.5kb2024-01-20 06:39:132024-01-20 06:39:14

Judging History

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

  • [2024-01-20 06:39:14]
  • 评测
  • 测评结果:TL
  • 用时:1429ms
  • 内存:31444kb
  • [2024-01-20 06:39:13]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<int> adj[maxn], seg[4*maxn];
array<int, 2> e[maxn];
int n, m, q, ban[maxn], in[maxn], qu[maxn], ans[maxn], pref[maxn], no[maxn];
int st[maxn], pos[maxn], sz;
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 rem(int val)
{
    if (!pos[val]) return;
    swap(st[pos[val]], st[sz]);
    pos[st[pos[val]]] = pos[val];
    pos[val] = 0;
    sz--;
}

inline void ins(int val)
{
    if (pos[val]) return;
    st[++sz] = val;
    pos[val] = sz;
}

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]) rem(id), no[id] = 1;
        else ins(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]) ins(id), no[id] = 0;
        else rem(id), 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);
    if (l == r)
    {
        if (qu[l]) 
        {
            ans[l] = sz ? st[sz] : 0;
            if (sz) rem(st[sz]);
            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);
}

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: 4ms
memory: 16212kb

input:

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

output:

5
4
2
3
0
1
0

result:

ok q=10

Test #2:

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

input:

0 0
0

output:


result:

ok q=0

Test #3:

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

input:

0 0
1
?

output:

0

result:

ok q=1

Test #4:

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

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
1861
1228
1737
1493
1147
967
1848
1741
1179
1478
243
528
854
853
852
851
1225
951
949
1479
1480
1300
1299
1298
1421
895
1880
1201
1529
846
1968
1723
1561
1667
254
1736
1702
973
972
1295
255
971
1527
1789
1788
1648
1593
1851
1956
1696
1797
1796
1267
941
1026
1076
1075
1962...

result:

ok q=100000

Test #5:

score: 0
Accepted
time: 48ms
memory: 24528kb

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: 1373ms
memory: 24296kb

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
46378
32518
76026
64168
93793
55426
66783
66009
52401
93009
93006
93463
58063
1333
49276
23434
23431
16243
42388
99543
96978
23824
23821
23820
47998
16240
16239
88801
62823
99214
22258
52708
99403
79779
96596
98351
6...

result:

ok q=100000

Test #7:

score: 0
Accepted
time: 1239ms
memory: 23944kb

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
97330
891
890
889
98456
88803
92778
886
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: 1013ms
memory: 23452kb

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
56603
56602
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: 721ms
memory: 22400kb

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: 412ms
memory: 21676kb

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
24206
24205
24204
24203
24202
24201
84975
84974
84973
84972
99660
99659
99658
99657
99656
99655
99654
99646
99638
9962...

result:

ok q=100000

Test #11:

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

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: 52ms
memory: 23940kb

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:

63044

result:

ok q=100000

Test #13:

score: 0
Accepted
time: 1358ms
memory: 24596kb

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
98859
94629
88801
82659
39994
96276
18273
18272
65226
79978
88800
65749
99244
99243
88949
93351
48958
96753
71476
60058
12108
3538
50851
99426
32884
98194
45723
45644
2659
33249
99379
91164
77943
81343
95584
48931
95493
86960
86957
68554
90901
24988
39301
53319
53...

result:

ok q=100000

Test #14:

score: 0
Accepted
time: 1270ms
memory: 23952kb

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
75378
41028
12528
5286
60060
59847
70520
70307
60658
98406
99120
86606
61731
97196
77069
57742
93353
10005
10004
98978
73803
57548
57258
30303
74256
96980
38256
96831
74705
98303
29930
63633
63632
93270
35061
35026
11271
11138
93352
93351
69791
94010
87900
92071
69053
8...

result:

ok q=100000

Test #15:

score: 0
Accepted
time: 1017ms
memory: 22856kb

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
86146
79380
79375
79372
79363
98196
98195
98194
85653
98086
98193
91806
67803
33615
33614
33613
94530
94529
94526
94525
94510
67802
67801
67774
67765
67748
96026
99666
89528
89527
91680
91679
67550
67549
67548
38256
38255
38254
38201
38164
62553
62552
74030
85316
96755
96754
96753
48960
...

result:

ok q=100000

Test #16:

score: 0
Accepted
time: 738ms
memory: 22132kb

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:

99200
91537
50837
50798
50797
58049
58010
58009
58065
18259
18220
18219
17980
32137
32098
36475
36436
36435
36196
97585
97546
97545
98191
98136
13720
13457
13456
13752
13749
13746
13694
95254
94060
52297
98029
48584
83153
98085
98082
94059
12889
92722
92721
15780
15779
81670
81669
52311
48868
48549
...

result:

ok q=100000

Test #17:

score: 0
Accepted
time: 416ms
memory: 21412kb

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
77308
77299
97728
97721
97712
78153
78146
78152
78149
78133
79178
79171
79162
79117
79116
40341
40334
40325
40280
40279
40340
40337
40322
40321
40318
40315
40314
40301
40298
40001
40000
35790
31808
19136
18735
18333
40250
80571
80564
80555
76676
76669
76660
76615
76614
76611
76608
76607
...

result:

ok q=100000

Test #18:

score: 0
Accepted
time: 18ms
memory: 19984kb

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
81912
81909
81814
81805
81804
81803
81800
81799
81796
81795
81790
81156
81347
79989
78582
79191
53739
54041
42201
43212
51287
98978
98975
98972
94693
94593
93648
93538
93427
93088
92973
92622
92503
91893
92956
92605
92486
91876
93401
93062
92947
92596
92477
91867
93620
93510
93399
93060
92945
...

result:

ok q=100000

Test #19:

score: 0
Accepted
time: 55ms
memory: 24500kb

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:

98404

result:

ok q=100000

Test #20:

score: 0
Accepted
time: 1351ms
memory: 24540kb

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:

14456
99363
99086
98735
96278
18678
18677
64436
28805
63366
455
1551
97536
99545
26910
1282
53928
870
95403
99666
911
47031
99471
596
26145
56316
36491
36490
655
98546
89810
99370
88356
348
36489
97703
36477
1358
98406
24988
97051
97784
97781
69789
81151
57193
253
59181
59178
24971
26144
26143
42388...

result:

ok q=100000

Test #21:

score: 0
Accepted
time: 1266ms
memory: 23652kb

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:

42406
685
69546
64965
78566
97196
99680
14603
14602
14597
71478
77736
99246
31785
40685
36491
36490
89811
87746
87745
18678
18677
75810
99545
97536
99539
95495
71001
98600
98599
98940
98939
1578
81726
91806
91805
96195
1518
98085
98978
76242
94116
1120
89670
99215
63366
97665
64169
64964
81345
81344...

result:

ok q=100000

Test #22:

score: 0
Accepted
time: 1040ms
memory: 22772kb

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
375
820
1264
15426
15425
15424
78771
164
98691
98690
99303
99302
99301
83210
94631
27671
303
90228
90227
90226
90225
90224
90223
90220
90219
90218
53016
53015
53014
79781
84105
37905
37904
97470
3101
3100
3099
3098
99275
99051
99050
36135
36134
36133
29930
95853
90636
90635
84975
96111
96110
961...

result:

ok q=100000

Test #23:

score: 0
Accepted
time: 749ms
memory: 21988kb

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:

86054
66011
66010
66009
66008
66007
88506
88505
88504
88503
50226
47355
47354
47353
81153
81152
81151
81150
19481
19480
16653
16652
16651
16650
6585
6584
6583
6582
6581
6580
89811
89810
89809
89808
89807
89806
89805
92660
88356
88355
88354
72885
72884
72883
72882
72881
38606
69300
69299
99356
99355
...

result:

ok q=100000

Test #24:

score: 0
Accepted
time: 421ms
memory: 21412kb

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
94324
94323
94322
94321
94320
59495
59494
59493
59492
70035
70034
70033
70032
70031
70030
70029
70028
70027
70026
70025
70024
70023
61731
61730
99428
91553
91552
56610
56609
56608
3115
97911
97910
97909
97908
97907
40685
92541
92540
90228
56316
56315
56314
98456
98455
98454
98453
98452...

result:

ok q=100000

Test #25:

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

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: 54ms
memory: 25212kb

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: 1407ms
memory: 24592kb

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
92972
25000
24999
24978
1778
1761
98778
99955
75728
87616
22285
76167
76156
86159
86148
96438
90145
96521
64806
84626
99997
...

result:

ok q=100000

Test #28:

score: 0
Accepted
time: 1318ms
memory: 24000kb

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
97584
97583
86648
...

result:

ok q=100000

Test #29:

score: 0
Accepted
time: 1047ms
memory: 23236kb

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
58428
58423
97226
97221
99988
99950
47741
93219
93210
93209
96262
96253
96252
68403
68394
68393
68390
88379
88370
33650
33641
33640
33637
33636
98514
98505
98504
98501
98500
98497
98496
28077
28068
28067
...

result:

ok q=100000

Test #30:

score: 0
Accepted
time: 748ms
memory: 22396kb

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: 419ms
memory: 21420kb

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: 14ms
memory: 19980kb

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: 50ms
memory: 25212kb

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:

4844

result:

ok q=100000

Test #34:

score: 0
Accepted
time: 1417ms
memory: 24576kb

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:

29169
99160
99119
99077
99791
98928
68156
76335
66067
94717
56359
29554
99940
99556
94219
55490
55489
11270
90954
96836
96835
67385
95436
99640
84778
99964
1777
99955
85815
85814
86480
86315
92007
91990
36886
97155
97148
98516
99536
891
858
95820
6588
71113
95056
78702
97000
96979
59577
99811
62091
...

result:

ok q=100000

Test #35:

score: 0
Accepted
time: 1324ms
memory: 23908kb

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:

63133
63130
43401
45399
94592
38950
76096
64477
94899
97399
97398
97395
98552
91820
91436
91433
28784
28781
28780
28779
28772
28753
68598
96106
29148
29216
29215
29212
22201
96275
43372
82357
31371
32843
95825
95824
73149
96566
74534
74533
74532
98167
17835
17830
97667
44736
44731
78644
96787
96786
...

result:

ok q=100000

Test #36:

score: 0
Accepted
time: 1082ms
memory: 22920kb

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:

95537
95536
92747
82443
51236
51244
51243
51171
51170
55511
89429
89428
92258
44131
44130
66111
93564
93572
93571
93495
71114
61545
61544
15439
42109
42108
97368
97367
97356
97355
20699
72538
86650
86649
86638
82630
95442
95450
95449
92986
92985
92974
92973
92970
92969
98104
85313
71113
71102
71101
...

result:

ok q=100000

Test #37:

score: 0
Accepted
time: 747ms
memory: 22104kb

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
23025
89858
44132
80909
80908
80907
93335
47424
47423
18698
18697
18696
18679
18678
18667
88385
88384
88332
88329
19503
19457
90965
90964
62099
62098
62097
26180
26134
26131
26092
14204
14203
14202
14187
14186
14185
99406
99405
99404
99391
98872
98871
98858
21100
21099
21098
21085
...

result:

ok q=100000

Test #38:

score: 0
Accepted
time: 435ms
memory: 21428kb

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
81287
81240
81187
64792
64791
81158
81155
81154
73693
73692
80320
70627
70626
97151
97150
97149
97138
97091
94781
93604
13370
13365
94755
92260
92259
92258
92247
92257
92256
92255
82066
82065
82064
33287
33286
33285
33274
33284
33283
33282
33281
33263
61260
61259
61258
61247
61200
...

result:

ok q=100000

Test #39:

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

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:

99860
99859
99858
99851
99813
99708
99244
99205
99082
99039
98995
85637
85467
84952
84778
50127
50126
71347
62907
25011
61811
99995
99992
99988
99983
99920
99723
99259
99220
99097
99054
99010
85482
84967
84793
86051
85547
85377
84862
84689
91381
88425
88273
88120
87966
87811
86046
85542
85372
84857
...

result:

ok q=100000

Test #40:

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

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: 1429ms
memory: 24336kb

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:

33685
56396
25786
96515
840
414
97445
97444
97441
99259
25
33286
33285
396
75584
30548
97723
311
97722
313
349
18695
62373
89567
99993
45785
5286
99592
5284
66114
64533
65064
82061
49344
99533
67402
66630
62918
5721
62916
92379
5298
98514
99808
35457
92255
92004
96759
10434
87607
87609
59866
69901
8...

result:

ok q=100000

Test #42:

score: 0
Accepted
time: 1332ms
memory: 23932kb

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
94957
91759
91758
80329
95999
95998
71597
71596
89290
91270
45455
45454
93457
93456
53394
99994
46112
95351
46108
50294
95347
98172
12118
11274
29211
176
622
99972
72061
32922
75280
72071
670
224
56099
42094
89866
89865
96088
93109
68162
71359
72307
72306
94562
71327
48704
9589
57275
57274
9...

result:

ok q=100000

Test #43:

score: 0
Accepted
time: 1081ms
memory: 22860kb

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
97374
97373
91228
91227
91226
78496
82249
6593
6592
6591
52467
52466
52465
52464
6586
547
101
40764
98726
98725
98724
40729
40728
65585
97587
97586
97585
2657
35456
93562
35454
35453
35452
35451
35450
55497
55496
55495
68908
68907
68906
1688
354
68905
98825
98824
9599...

result:

ok q=100000

Test #44:

score: 0
Accepted
time: 743ms
memory: 22496kb

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:

1000
42815
42845
42876
704
78503
78502
78501
78500
78499
78498
78497
78496
78495
78494
78493
44791
65589
44789
44788
92633
92632
92631
92630
92629
92628
92627
98328
75222
94856
36535
36534
66372
47415
74609
95445
95909
67143
67142
67141
95908
48061
95906
96434
9164
96432
94548
94547
893
892
80125
80...

result:

ok q=100000

Test #45:

score: 0
Accepted
time: 420ms
memory: 21512kb

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
75268
97299
97298
97297
97296
97295
97294
97293
97292
97291
97290
97289
53088
53087
68909
62912
62911
62910
99675
99674
99673
99672
99671
99670
99669
99668
99667
99666
99665
99829
99828
99827
99826
99825
99824
99823
86314
86313
86312
86311
86310
86309
86308
86307
86306
86305
8630...

result:

ok q=100000

Test #46:

score: 0
Accepted
time: 28ms
memory: 19932kb

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: 94ms
memory: 30084kb

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:

1616

result:

ok q=100000

Test #48:

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

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: 103ms
memory: 28392kb

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: 77ms
memory: 27300kb

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: 57ms
memory: 25900kb

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: 39ms
memory: 23984kb

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: 22ms
memory: 21888kb

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: 91ms
memory: 29732kb

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: 104ms
memory: 30288kb

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:

35267
67766
38280
26801
10102
69541
61456
49240
33023
9836
93174
12758
12779
10381
10380
12780
61457
27140
85349
99045
94667
26395
16284
65622
42262
66069
42330
10232
42329
16331
45676
2241
85765
99535
29139
29138
17424
5690
59858
2847
13427
47007
28753
73162
82184
46688
74149
87145
63905
37591
3347...

result:

ok q=100000

Test #56:

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

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:

98352
63425
84146
2308
99712
99711
99350
36150
78452
58524
25165
66262
75727
1319
78453
84115
69277
77514
58909
20392
98409
77516
93699
77515
87174
15163
1854
76360
7832
53484
53486
49207
41388
80866
93580
24641
75206
39228
48953
54764
50189
63563
57598
86770
96408
67280
92676
89213
79787
64934
2194...

result:

ok q=100000

Test #57:

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

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:

15521
21725
15523
34931
95383
36320
25341
84523
33338
82590
44497
91379
56857
25342
63894
9412
6141
25025
65919
34206
50227
14161
24703
14160
16282
62454
33176
81774
44862
44861
11446
28767
21506
90274
81422
33682
4801
66918
39835
88142
61263
91160
18488
76898
74644
71781
10108
58335
15761
15762
447...

result:

ok q=100000

Test #58:

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

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:

4176
30306
4136
10066
28688
9947
29589
66813
26139
56242
47052
60154
85208
56241
31081
71925
50128
53882
88991
4741
4134
72931
88124
79434
43019
71957
67470
24008
23291
43018
7732
66439
48045
22096
73599
69290
56475
50014
94649
82335
80814
80420
77595
92010
43779
42087
61265
76882
21481
57472
61262
...

result:

ok q=100000

Test #59:

score: 0
Accepted
time: 75ms
memory: 27504kb

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
67022
69202
19275
52282
47824
77548
36486
75877
13349
98772
96318
3277
99678
85365
9079
69569
26329
71141
79518
78206
61739
99227
65986
34237
3190
2715
22739
89068
30040
13180
50884
27532
27531
27530
10000
73794
5244
71978
12147
59260
57945
88038
61480
44148
42523
20093
16376
88747...

result:

ok q=100000

Test #60:

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

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:

72435
11987
88913
20364
77154
98251
84739
45946
97545
95978
97629
7837
99843
87368
18357
99448
77174
40071
99965
32298
80790
23547
99191
94580
68500
59970
99349
82670
99660
59893
55984
49754
13921
88628
61269
94407
78996
53229
5416
86820
98462
77594
25207
88937
10943
57204
17759
77531
17029
81473
27...

result:

ok q=100000

Test #61:

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

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: 83ms
memory: 31444kb

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: 87ms
memory: 31372kb

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: 88ms
memory: 30492kb

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: 81ms
memory: 30772kb

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: 95ms
memory: 30260kb

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: 95ms
memory: 31364kb

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: 32ms
memory: 28672kb

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: 15ms
memory: 22992kb

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: