QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#440436#6759. 字符串Max_s_xaM16 277ms16732kbC++145.1kb2024-06-13 18:39:332024-06-13 18:39:34

Judging History

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

  • [2024-06-13 18:39:34]
  • 评测
  • 测评结果:16
  • 用时:277ms
  • 内存:16732kb
  • [2024-06-13 18:39:33]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstring>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 2e5 + 10;

int n, q, N, res[MAXN];
char s[MAXN];
struct Qry
{
    int x, r, id;
}qt[MAXN];

int m, sa[MAXN], rk[MAXN], cnt[MAXN], p[MAXN << 1];
int f[MAXN];

struct BIT
{
    int bit[MAXN];
    inline void Add(int x, int k) {for (; x <= n; x += x & -x) bit[x] += k;}
    inline int Ask(int x) {int res = 0; for (; x; x -= x & -x) res += bit[x]; return res;}
}bt[2];

pair <int, int> st[MAXN];

int main()
{
    // freopen("string.in", "r", stdin);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    int CASE, T;
    Read(CASE), Read(T);
    while (T--)
    {
        Read(n), Read(q), Read(s + 1), N = n, s[n + 1] = 123;
        for (int i = 1; i <= n; i++) s[2 * n + 2 - i] = s[i];
        n = 2 * n + 2, s[n] = 124;
        for (int i = 1; i <= q; i++) Read(qt[i].x), Read(qt[i].r), qt[i].id = i, res[i] = 0;

        memset(cnt, 0, sizeof(cnt)), memset(rk, 0, sizeof(rk));
        m = 256;
        for (int i = 1; i <= n; i++) cnt[rk[i] = s[i]]++;
        for (int i = 2; i <= m; i++) cnt[i] += cnt[i - 1];
        for (int i = 1; i <= n; i++) sa[++cnt[rk[i] - 1]] = i;
        for (int w = 1; w < n; w <<= 1)
        {
            int top = 0;
            for (int i = n - w + 1; i <= n; i++) p[++top] = i;
            for (int i = 1; i <= n; i++)
                if (sa[i] > w) p[++top] = sa[i] - w;
            memset(cnt, 0, sizeof(cnt));
            for (int i = 1; i <= n; i++) cnt[rk[p[i]]]++;
            for (int i = 2; i <= m; i++) cnt[i] += cnt[i - 1];
            for (int i = 1; i <= n; i++) sa[++cnt[rk[p[i]] - 1]] = p[i];
            memcpy(p, rk, sizeof(rk));
            m = 0;
            for (int i = 1; i <= n; i++)
                rk[sa[i]] = (p[sa[i]] == p[sa[i - 1]] && p[sa[i] + w] == p[sa[i - 1] + w] ? m : ++m);
            if (m == n) break;
        }
        
        memset(bt[0].bit, 0, sizeof(bt[0].bit));
        memset(bt[1].bit, 0, sizeof(bt[1].bit));
        sort(qt + 1, qt + q + 1, [&](Qry u, Qry v) {return rk[u.x] > rk[v.x];});
        for (int i = n, j = 1; i >= 1; i--)
        {
            while (j <= q && qt[j].x == sa[i]) res[qt[j].id] += bt[(qt[j].x & 1) ^ 1].Ask(qt[j].x + 2 * qt[j].r - 1) - bt[(qt[j].x & 1) ^ 1].Ask(qt[j].x), j++;
            if (sa[i] > N + 1 && sa[i] < n) bt[(n - sa[i]) & 1].Add(n - sa[i], 1);
        }

        n = N;
        for (int i = 1, l = 0, r = 0; i <= n; i++)
        {
            f[i] = (i > r ? 0 : min(f[r - i + l - 1], r - i));
            while (i - f[i] > 0 && i + f[i] + 1 <= n && s[i - f[i]] == s[i + f[i] + 1]) f[i]++;
            if (i + f[i] > r) r = i + f[i], l = i - f[i] + 1;
        }
        for (int i = 1; i <= n; i++) st[i] = make_pair(i - f[i] + 1, i);
        sort(st + 1, st + n + 1), sort(qt + 1, qt + q + 1, [&](Qry u, Qry v) {return u.x < v.x;});
        memset(bt[0].bit, 0, sizeof(bt[0].bit));
        for (int i = 1, j = 1; i <= q; i++)
        {
            while (j <= n && st[j].first <= qt[i].x) bt[0].Add(st[j].second, 1), j++;
            res[qt[i].id] -= bt[0].Ask(qt[i].x + qt[i].r - 1) - bt[0].Ask(qt[i].x - 1);
        }
        for (int i = 1; i <= q; i++) cout << res[i] << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 16008kb

input:

1 5
5 5
aaaaa
4 1
2 1
2 2
2 2
4 1
5 5
abaab
1 1
1 2
2 1
3 1
1 1
5 5
baaaa
1 2
2 2
2 2
2 1
2 2
5 5
babab
1 2
2 2
4 1
2 2
2 2
5 5
baaab
2 2
2 1
1 1
1 2
2 2

output:

-1
0
-1
-1
-1
1
1
0
-1
1
0
-1
-1
0
-1
0
2
1
2
2
1
0
0
0
1

result:

wrong answer 1st numbers differ - expected: '0', found: '-1'

Test #2:

score: 0
Wrong Answer
time: 3ms
memory: 15916kb

input:

2 5
10 10
babbbbbaaa
1 4
9 1
6 2
2 3
2 1
1 5
1 5
4 2
1 2
2 4
10 10
baabbaabab
1 5
2 4
2 4
2 3
3 4
5 3
2 3
1 5
3 1
4 1
10 10
aaaaabaabb
1 5
6 2
3 2
2 2
1 1
5 1
1 5
1 5
1 4
3 3
10 10
babbaababb
5 3
7 1
7 2
1 4
6 1
4 2
2 4
2 4
4 1
1 5
10 10
babbbaabba
2 3
1 5
6 2
2 4
1 5
4 1
2 3
5 2
2 3
1 5

output:

2
-1
0
3
1
2
2
-1
1
3
1
2
2
1
3
1
1
1
1
0
3
-1
0
-1
0
1
3
3
2
1
2
0
1
1
1
0
3
3
0
2
2
1
1
3
1
0
2
0
2
1

result:

wrong answer 2nd numbers differ - expected: '0', found: '-1'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 13940kb

input:

3 5
19 19
baaababbbbbaaabbbaa
13 1
1 7
7 6
10 2
4 5
18 1
16 1
7 6
6 5
6 5
3 8
4 7
6 3
2 8
14 3
11 4
11 3
1 4
1 9
19 19
bbaababbaaaaababbba
9 1
10 4
16 1
1 9
4 6
5 4
15 1
1 7
2 6
5 7
14 3
1 9
11 3
1 7
8 6
2 8
10 1
2 8
8 2
20 19
baabaaabaabaaaababba
3 7
1 8
4 5
14 2
7 7
1 5
1 8
15 2
2 8
2 6
3 5
2 4
6 ...

output:

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

result:

wrong answer 1st numbers differ - expected: '0', found: '-1'

Test #4:

score: 0
Wrong Answer
time: 3ms
memory: 13876kb

input:

4 5
46 50
abababbbbbbbbbabaabaaababbaaaaabababbababaaaaa
1 13
19 1
7 19
22 7
3 21
3 17
3 21
31 6
1 23
11 4
19 11
4 17
2 21
7 20
10 8
25 9
9 19
6 4
7 18
5 4
2 1
12 9
6 20
17 13
7 1
9 17
1 21
12 6
11 11
1 23
5 16
28 6
4 17
10 2
3 19
34 5
21 13
1 23
13 6
31 5
6 20
4 20
3 21
16 1
1 21
17 2
2 19
23 4
1 7...

output:

9
0
-3
3
12
11
12
4
14
0
3
5
6
-3
0
0
-1
-4
-3
4
0
0
-4
10
-1
-1
14
0
0
14
10
3
5
0
12
0
8
14
0
5
-4
5
12
0
14
1
6
1
7
8
8
6
5
15
5
0
16
0
-1
12
0
5
14
9
1
14
5
-1
5
15
13
9
7
1
-1
3
15
4
5
5
3
0
6
0
11
3
0
15
1
7
6
3
13
0
2
-1
14
0
3
1
4
0
7
6
3
8
8
13
7
1
13
13
14
3
9
3
9
10
1
10
1
0
10
14
5
-4
5
...

result:

wrong answer 3rd numbers differ - expected: '0', found: '-3'

Test #5:

score: 0
Wrong Answer
time: 4ms
memory: 13976kb

input:

5 5
97 98
bbaabaabbababaaaababaabababaabaababbbbbbaababaabaaabbaabbabaabbaababbabbbbbaababbbbabbbbbbbaaaaab
71 13
77 7
13 3
14 40
18 21
13 38
20 18
2 48
30 27
84 4
3 34
4 15
18 36
55 20
3 44
9 36
10 24
15 8
55 15
48 6
38 18
30 16
19 7
4 47
76 4
36 28
3 38
7 43
13 3
7 22
55 12
9 22
26 17
30 23
24 31
...

output:

-1
7
0
38
6
18
7
25
14
4
30
9
16
13
40
5
14
7
9
3
1
7
3
31
3
2
34
23
0
7
6
3
12
12
20
8
-1
0
6
4
8
10
16
21
1
16
1
24
2
9
5
9
30
13
26
5
8
11
25
0
17
-1
19
24
31
17
41
3
9
12
10
18
-2
0
24
1
0
22
27
16
34
0
5
9
3
9
20
5
13
-1
33
0
5
4
18
23
9
20
5
13
1
11
4
14
0
10
9
2
5
18
1
9
3
31
13
25
12
0
12
5
...

result:

wrong answer 1st numbers differ - expected: '1', found: '-1'

Test #6:

score: 0
Wrong Answer
time: 3ms
memory: 12012kb

input:

6 5
998 992
bibbaabpaapbaabbibbbbabbaabbaafbaabbaabbaabbaabfaabbaabbabbbabbbaabpaapbaabbbabobabbaabbaafbaabbaabbaabbaabfaabbaabbabbbbbbbaabpaapbaabbbbbbbabbaabbaafbaabbaabbaabbaabfaabbaabbabobabbbaabpaapbaabbbabbbabbaabbaafbaabbaabbaabbaabfaabbaabbabbbbibbaabpaapbaabbibbbbabbaabbaafbaabbaabbaabbaabf...

output:

31
48
41
61
267
133
144
111
336
311
87
334
138
173
173
95
77
19
154
290
123
20
110
17
12
166
60
125
5
73
214
56
0
199
42
47
123
5
3
119
132
216
0
30
105
60
4
354
140
38
52
59
88
38
52
208
258
17
11
192
354
76
65
53
296
59
137
307
198
119
118
114
207
8
7
66
264
307
365
1
355
6
15
31
119
56
6
93
66
35...

result:

wrong answer 1st numbers differ - expected: '32', found: '31'

Test #7:

score: 0
Wrong Answer
time: 4ms
memory: 12164kb

input:

7 5
1988 1997
bvappavbbaabavavpavbbaabbvappavbbaabbvappavbbaabbvappavbbaaqbvappavbbaabbvappavbqaabbvappavbbaabbvappavbbaabbvappavbbaabbvappavabaabbvappavbbaaqbvappavbbaabbpappavbqaabbvappavbbaabavappavbbaabbvappavbbapbbvappavbbaabbvappavbbaaqbvappavbbaabbvappavbqaabbvappavbbaabbvappavbbpabbvappavbba...

output:

20
302
416
404
5
12
674
787
520
151
143
125
633
3
156
792
146
103
326
391
41
37
130
151
218
1
8
301
47
312
89
194
36
53
5
123
557
828
512
87
13
138
221
46
490
94
123
109
63
11
436
34
0
168
679
134
202
302
114
453
96
226
420
112
663
85
43
104
713
28
41
7
14
180
612
79
15
712
89
445
260
171
14
501
56
...

result:

wrong answer 3rd numbers differ - expected: '418', found: '416'

Test #8:

score: 0
Wrong Answer
time: 13ms
memory: 16028kb

input:

8 5
2977 2978
aabaaaabaabaaaabaabaaaabaabnaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaanbaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaaabaabaaa...

output:

462
307
731
0
426
922
7
412
130
207
526
721
381
375
124
1044
565
1107
1070
1041
69
391
878
1254
27
1028
849
35
608
1089
68
739
105
831
38
372
16
1
901
119
1067
688
222
760
539
16
371
261
52
1245
658
380
-19
349
456
669
1188
428
150
109
484
721
228
115
584
53
1150
231
1203
847
829
138
366
235
395
113...

result:

wrong answer 1st numbers differ - expected: '465', found: '462'

Test #9:

score: 0
Wrong Answer
time: 14ms
memory: 15968kb

input:

9 5
3992 3963
baaamarbaaaabramaaabbaabmarbaaaabrambaabbaabmarbaaaabrambaabbaabmarbaaaabrambbabbaabmarbaaaabrambaabbaabmarbaaaabrambaabbaaamarbaaaabramaaabbaabmarbaaaabrambaabbaabmarbaaaabrambaabbabbmarbaaaabrambaabbaabmarbaaaabrambaabbaabmarbaaaabrambaabbaaamarbaaaabramaaabbaabmarbaaaabrambaabbaabma...

output:

333
174
335
698
21
1026
508
922
1487
1775
101
446
1238
1606
540
15
312
266
322
472
84
1126
18
371
309
1047
460
79
1174
967
199
5
624
845
652
717
476
86
360
698
826
496
1739
116
323
433
38
890
201
204
61
131
1252
50
810
491
866
844
793
59
1431
1541
4
23
46
19
427
839
1240
749
1301
224
175
108
1149
31...

result:

wrong answer 1st numbers differ - expected: '336', found: '333'

Test #10:

score: 0
Wrong Answer
time: 40ms
memory: 16188kb

input:

10 5
21773 22026
babaaababbabbbbbaababbababaabbababbabbbbabaaaaabaabbabbbbbbaaaabaababbbabbbbbabaababbaababbbbaaabaabbaaaabbbbaaaabbbbbabaaaaaaaabbabbabbaabbbbabbbaaabbabbabababbaabaabbaabbaaaaabaabaababaabbaaaaaabababbaabbababaabbabbaaaaaaaaabbaabbbaabbababbbbbaaaaaabaaabbbaabaaabbabbabaabbbbabbabb...

output:

604
606
870
1877
2959
7799
3875
2951
36
6360
3249
66
2081
6986
392
190
1152
892
2733
2346
23
1129
3783
41
2336
1221
546
1244
167
4481
7213
4746
125
1064
6830
1658
2057
3586
1335
1397
1853
1172
6993
37
5092
2549
3490
3991
160
603
43
935
1271
333
249
1311
7944
6837
-1
3572
332
1692
6539
5739
1893
8430...

result:

wrong answer 1st numbers differ - expected: '605', found: '604'

Test #11:

score: 0
Wrong Answer
time: 94ms
memory: 16232kb

input:

11 5
47391 45803
aababababbbbbbbbbbbaabaabababaababbbbabbabbabaabbbbabbbbaaaababbabababbabbabbaabbbaaabaaaabbbabababbaababbbabbabbabbbabaabbabaabaaaabbbbbbbbabbbbbababbaaababbbababbabaababbaaaaaaaaabaababaababbaaaabbbbaaababbaabaaabbabaaaaaabbababababbababaaaabbbaaaaaaaaaaabbbbbbbabbbaaabababaaababa...

output:

4186
3688
100
3723
2769
13826
13978
644
1458
10310
4489
1555
3875
1467
346
635
252
29
13744
3311
4567
8057
8348
1533
688
13111
482
8597
8775
4255
9923
3224
1010
79
8864
3892
7422
1582
7336
3033
10456
7158
3243
16101
3328
8457
364
1123
2163
1565
7740
4080
2561
18853
1238
10074
1013
2604
1381
4437
663...

result:

wrong answer 1st numbers differ - expected: '4187', found: '4186'

Test #12:

score: 0
Wrong Answer
time: 135ms
memory: 16436kb

input:

12 5
69918 68763
bbabbbabbbaaabaabbbbbbbbbabbbbbbbbaaabaabaabbbaabaaaabbabbabbbbbabbbbaabaaaabaabbababbbbbaaababbabbbbaabbbaaabaaaaababaaabbbbababababbababbbaaabbbbaabbabbbbbbbbabbabbbbaaabbbbaaababbbaaabaaabbabaaabbaabbbaaabbbbbbaabaabbbaabaaabbbabbbbbaabaabbabbbabbababbaaaabbbbbbbaabaaaabbabaaaaab...

output:

613
22361
3579
4070
4361
2217
17420
6215
4183
8817
7589
19790
8267
1773
43
1286
3820
25097
6602
10306
7692
26752
13717
3089
147
339
23283
4036
10047
3451
2000
685
4221
3169
17768
13155
8108
10690
4354
3601
9030
8539
3752
15172
18008
2243
1614
220
6139
22729
21067
1843
14873
1759
5013
2671
4513
13168...

result:

wrong answer 1st numbers differ - expected: '614', found: '613'

Test #13:

score: 0
Wrong Answer
time: 169ms
memory: 16016kb

input:

13 5
86855 85346
bbaaababbbbbaaaabbbaabbabbabbaabbbabbbbbbbaabaabbaabbaaaabbabaaaabbaaaabababbbbbbbbaabbabababaabaababaaabbabaabaaabaabaabbbabbabbbaabaaaabbbbabbbaabbabaabbabbbaabbbbbaaaaabbbbaaaababbbabaaabaababaababaaabbbaaaababbabaababaabababaababbabbbabaabaaabbabababbbbbbaaaababababbabaabaaaaabb...

output:

23396
495
37520
13084
16190
5014
39195
2818
7675
13149
29387
16788
9755
6908
28102
17426
12691
25728
7137
20352
5086
8737
2657
495
34202
3815
7689
18151
205
26130
7994
21087
3197
3550
17965
13389
12003
1097
4936
2049
9546
458
8972
3717
24214
1105
1631
6965
22150
16896
21691
16808
2538
32407
12849
11...

result:

wrong answer 1st numbers differ - expected: '23397', found: '23396'

Test #14:

score: 0
Wrong Answer
time: 198ms
memory: 16580kb

input:

14 5
95651 97657
babbbababaaaabaaaaaaaabbaaabaababbaabbaabbabbaaabababaabaaaabaaaabbbabbabbaaaabbaabbbbbbbbaabbaabbbaaabaaabababbabababbabbbababaabaababbaabbababbbabbbbabbbbabbaaaaabaaaabbabbbabbbabbaababbbabbaaabaabbbbbbbabbabbbabaaaabaaaaaaaababaababbabaaaabaababaababbaaaaababaaabbbbabababbbabaabb...

output:

16666
26259
7301
9219
17848
7040
13588
537
10509
5249
30399
9347
28341
3846
7512
9692
41788
18592
13194
7422
18367
4493
733
9223
199
13124
6890
31855
5054
34071
32147
1798
17634
3487
15848
8095
2946
5925
5118
5354
12682
10064
37286
36555
10884
2816
19446
15734
2004
27802
26891
12198
14431
36470
9212...

result:

wrong answer 2nd numbers differ - expected: '26260', found: '26259'

Test #15:

score: 4
Accepted
time: 49ms
memory: 16004kb

input:

15 5
21209 21227
babababakakababfbrbabababauabababfbababababakabababfbababababakabababfbababababakabababfbababababakabababfbababababakabababfbalabababakabababfbababababakabababfbrbabababauabababfbababababakabababfbababababakabababfbababababakabababfbababababakabababfbababababakabababfbababababakabab...

output:

875
8428
694
990
9417
1004
607
3128
8428
528
10263
451
1510
1
8757
272
5285
2056
178
54
3412
1160
491
6677
6540
7486
707
409
919
377
3178
339
3932
28
338
421
39
992
1206
2689
712
20
437
5233
6165
9492
49
1315
3028
778
981
4525
4967
10255
1306
1015
1095
2415
1040
933
3517
1255
1117
8592
55
124
780
52...

result:

ok 110426 numbers

Test #16:

score: 4
Accepted
time: 179ms
memory: 15328kb

input:

16 5
73529 68306
babsbababwbsbabsbabababsbabsbababwbsbadsbababwbsbabsbabsbwbsbabsbababwbsbabsbababwbsbabsbababwbsbabsbabababsbabsbababwbsbadsbababwbsbabsbabsbwbsbabsbababwbsbabsbababwbsbrbsbababwbsbabsbabababsbabsbababwbsbadsbababwbsbabsbabsbwbsbabsbababwbsbabsbababwbsbabsbababwbsbabsbabababsbabsbab...

output:

1
1262
2399
1
0
1
10730
1
0
1
30489
3312
4248
935
8645
14603
10699
0
0
13368
35363
10221
11654
32384
7456
15281
0
1
3274
17255
1
14138
8866
11994
34570
1
15001
8483
10232
4695
1473
635
16542
0
16332
4700
9621
2069
11473
0
3673
23257
4871
1
5197
13419
7209
1
14946
1
1
2201
9540
455
12114
15470
1
0
17...

result:

ok 359447 numbers

Test #17:

score: 4
Accepted
time: 217ms
memory: 16536kb

input:

17 5
87085 88577
ababababababvbabababababababababababvbabababababababababababvbabababatabababababababvbabababababababababababvbabababababababababababvbabababababababababababvbabababababababababababvbabababababababababababvbabababababababababababvbabababababababababababvbabababatabababababababvbababa...

output:

11254
27
760
3385
0
4335
871
683
513
2774
1250
1998
2174
2463
974
6871
13078
2817
2453
1096
3372
2677
0
513
36833
1611
6019
1681
43004
1353
12306
18622
39485
2589
37733
9624
589
1277
3638
526
1272
0
14907
40922
484
536
1394
35414
3661
37
0
1118
40967
2330
2103
1458
2071
3250
982
1862
190
1907
0
0
0
...

result:

ok 436679 numbers

Test #18:

score: 4
Accepted
time: 241ms
memory: 15036kb

input:

18 5
99489 97628
abababacababababacababababacababababacababababacababababacababababacababababacababababacababayabacababababacabababxbacababababacababababacababababacababababacababababacababababacababababacababababacababababacababayabacababababacababababacababababacababababacababababacababababacababa...

output:

445
707
42132
580
26762
655
39
497
44253
161
2051
39980
19110
40444
266
38617
11389
4931
29403
376
333
626
12248
653
10
648
686
24032
665
291
252
24777
44211
463
313
566
178
49505
25926
647
36
407
625
44175
46231
461
30278
25555
46539
15563
365
46328
554
624
524
27228
32996
577
33323
11690
459
36932...

result:

ok 475535 numbers

Test #19:

score: 0
Wrong Answer
time: 58ms
memory: 16068kb

input:

19 5
23197 23286
abbbaabaaabbaabbaaabaabbbabbabbhaabaaabbaabbaaabaabbbabbambbaabaaabbaabbaaabaabbmabbabbbaabaaabbaabbaaabaabbbabbabbbaabaaabbaabbaaabaabbbabbabbbaabaaabbaabbaaabaabbaabbambbaabaaabbaabbaaabaabbmabbabbbaabaaabbaabbaaabaahbbabbabbbaabaaabbaabbbaabaabbbabbabbbaabaaabbaabbaaabaabbbabbamb...

output:

1908
2677
1801
4505
5626
1089
2561
4916
2069
2053
434
2764
10
3748
3029
1095
8737
7613
2664
790
3837
5635
3104
4973
96
877
4763
37
668
7197
4565
2551
130
819
162
426
5241
6145
3667
4355
271
5173
2956
5076
5645
369
3908
6777
1672
2846
2620
1161
268
4196
2349
2210
1826
478
8843
2888
4023
10343
6666
18...

result:

wrong answer 1st numbers differ - expected: '1910', found: '1908'

Test #20:

score: 0
Wrong Answer
time: 129ms
memory: 14648kb

input:

20 5
49694 49669
bbabbbbbbabbbbbbbaabbbbbbaabbbbbbasbbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbsabbbbbbaabbbbbbaabbbbbbbabbbbbbabbbbbbbaabbbbbbaabbbbbbasbbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbaabbbbbbsabbbbbbaabbbbbbaabbbbbbbabbbbbbabbbbbbbaabbbbbbaabbbbbbasbbbbbbaabbbbbbaabbbbbbaa...

output:

13560
1008
5371
9516
1688
1788
27
1964
2433
2422
20679
5749
7251
1039
11890
19150
10705
2550
2216
1555
632
5200
22608
9923
5386
16725
4138
14312
438
1306
20348
5053
6226
209
8647
3341
4783
4196
2192
4607
15380
5462
4243
21896
10072
6403
293
2140
2469
33
759
6934
3384
363
11733
6213
131
1021
2369
20
...

result:

wrong answer 1st numbers differ - expected: '13569', found: '13560'

Test #21:

score: 0
Wrong Answer
time: 201ms
memory: 16600kb

input:

21 5
74422 74421
baabbllbbaabblabbaabbllbbaabbllbblabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbblbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllbbaabbllpbaabbllbbaabbllbbaabpllbbaa...

output:

8454
12803
14889
15417
2081
15615
4842
25178
3558
9948
10857
453
8980
3486
13286
6657
9948
1372
10600
9950
20948
10709
284
342
677
19332
23362
3200
6238
25
23127
3416
17629
4449
5774
15875
25360
32441
23794
8002
17227
10466
24066
1540
17208
20146
949
15956
317
4402
7356
29538
13598
3138
19988
4764
9...

result:

wrong answer 1st numbers differ - expected: '8464', found: '8454'

Test #22:

score: 0
Wrong Answer
time: 243ms
memory: 16308kb

input:

22 5
89983 89431
bajbbbzbbaabbzabbjabbaabbajbbazbbaabbzbbbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbjabbaabbajbbbzbbaabbzabbjabbaabbajbbazbbaabbzbbbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbjabbaabbajbbazbbaabbzabbja...

output:

11832
4458
9652
10838
25347
5860
5141
8014
8830
7863
14462
384
6539
4568
23176
18625
2234
20326
728
1460
515
21127
32894
12083
10306
27892
26174
7130
2500
34747
4765
9995
1162
16999
5011
246
569
19520
26190
15067
437
103
12040
15340
8016
278
19808
25556
31739
7980
11744
12176
175
9910
19045
14273
30...

result:

wrong answer 1st numbers differ - expected: '11849', found: '11832'

Test #23:

score: 0
Wrong Answer
time: 270ms
memory: 16716kb

input:

23 5
94783 94700
baabaaaabaabbaabbaabaaaabaabbaabbaabaaaabaabbaaabaabavaabaabaaabbaabaaaabaabbaabbaapaaaabaabbaabbaabaaaabaabbaaabaabaaaabaabaaabbaabaaaabaabbaaabaabaaaabaabbaabbaabaaaabaabbaaabaabaaaabaabaaabbaabaaaabaabbaabbaabaaaabaabbaabbaabaaaabaabbaaabaabaaaabaabaaabbaabaaaabaabbaabbaabaaaabaa...

output:

8010
2002
11758
26950
10310
14082
36027
9182
29674
9945
26250
3326
1312
4302
3823
936
29511
20417
13018
2469
14558
8860
15585
213
761
8761
3046
10305
15462
1133
7841
9735
11318
0
1834
8594
270
3098
14912
2022
8293
1531
6939
535
2842
16562
2031
26660
37539
3137
31234
5554
3331
2882
1756
7851
5843
279...

result:

wrong answer 2nd numbers differ - expected: '2025', found: '2002'

Test #24:

score: 0
Wrong Answer
time: 277ms
memory: 16732kb

input:

24 5
99576 99977
babbbaabbaabbbabbaabbadbbaabbaabbdabbaabbadbbaabbaabbdabbaabbabbbaabbaabbbabbaabbadbbaabbaabbdabbaabbadbbaabbaabbdabbaabbabbbaabbaabbbabbaabbadbbaabbaabbdabbaabbadbbaabbaabbdabbaabbabbbbabbaabbbabbaabbadbbaabbaabbdabbaabbadbbaabbaabbdabbaabbabbbaabbaabbbabbaabbadbbaabbaabbdabbaabbad...

output:

25220
22873
4195
25965
30487
8680
15576
4262
19
-3
676
3525
18268
716
29245
5663
2294
34053
1093
2136
1217
17794
26148
302
13471
7889
938
13538
7380
17391
16699
13902
4714
35010
5761
16845
1659
3838
5421
13554
7241
916
39104
2821
1093
13484
20002
19222
16471
4050
1261
16428
538
13216
11877
15992
191...

result:

wrong answer 1st numbers differ - expected: '25224', found: '25220'

Test #25:

score: 0
Wrong Answer
time: 274ms
memory: 15980kb

input:

25 5
99821 99309
aabbaabbaxbbaabbaabbaabbxabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbabbbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbbabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaxbbaabbaabbaabbxabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbabbbaabeaabbaab...

output:

9288
10224
15496
4879
29713
9458
6162
10260
13782
30273
4370
12578
23512
10294
1226
14614
18811
3738
8897
7647
2496
27154
3506
12915
14117
24123
18
962
4115
15308
1059
3206
5252
311
32573
179
5346
15117
7332
5488
20814
1599
7631
17278
9813
9684
264
2993
501
33940
4997
2390
13456
1886
814
7449
27097
...

result:

wrong answer 1st numbers differ - expected: '9293', found: '9288'