Submission ID Problem Status Score Time Memory Code / Answer files User Submit time
#18593 #59. 猜字母王 Hexguesser Accepted 100 34624 ms 17904 K C++ 17 / 2.2 K HKSCF2023-074 2023-07-15 16:10:04
Show orginal code
#include <iostream>
#define f first
#define s second
using namespace std;

int n, q, node[13][400010], fs[10], ft[10], freq[13][100010];
string ss, tt;

void build(int i, int id, int x, int y) {
    if (x == y) {
        node[i][id] = freq[i][x];
        return;
    }
    int mid = (x + y) / 2;
    build(i, id * 2, x, mid);
    build(i, id * 2 + 1, mid + 1, y);
    if (i <= 6)
        node[i][id] = max(node[i][id * 2], node[i][id * 2 + 1]);
    else {
        if ((node[i][id * 2] != 1e9) && (node[i][id * 2 + 1] != 1e9)) {
            if (node[i][id * 2] != node[i][id * 2 + 1])
                node[i][id] = -1;
            else
                node[i][id] = node[i][id * 2];
        } else
            node[i][id] = min(node[i][id * 2], node[i][id * 2 + 1]);
    }
}

int query(int i, int id, int x, int y, int l, int r) {
    if ((l <= x) && (y <= r))
        return node[i][id];
    if ((y < l) || (r < x)) {
        if (i <= 6)
            return 0;
        else
            return 1e9;
    }
    int mid = (x + y) / 2;
    if (i <= 6)
        return max(query(i, id * 2, x, mid, l, r), query(i, id * 2 + 1, mid + 1, y, l, r));
    else {
        int tmpx = query(i, id * 2, x, mid, l, r), tmpy = query(i, id * 2 + 1, mid + 1, y, l, r);
        if ((tmpx != 1e9) && (tmpy != 1e9)) {
            if (tmpx != tmpy)
                return -1;
            else
                return tmpx;
        } else
            return min(tmpx, tmpy);
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= 6; j++) freq[j][i] = 0;
        for (int j = 7; j <= 12; j++) freq[j][i] = 1e9;
    }
    for (int i = 1; i <= n; i++) {
        cin >> ss >> tt;
        for (int j = 1; j <= 6; j++) fs[j] = ft[j] = 0;
        for (int j = 0; j < 6; j++) {
            fs[ss[j] - 96]++;
            if (tt[j] == 'o')
                ft[ss[j] - 96]++;
        }
        for (int j = 1; j <= 6; j++) {
            if (fs[j] == ft[j])
                freq[j][i] = fs[j];
            else
                freq[j + 6][i] = ft[j];
        }
    }
    for (int i = 1; i <= 12; i++) build(i, 1, 1, n);
    while (q--) {
        int l, r;
        cin >> l >> r;
        int sum = 0, cnt = 0;
        for (int i = 1; i <= 6; i++) {
            int maxx = query(i, 1, 1, n, l, r), num = query(i + 6, 1, 1, n, l, r);
            if (num < maxx) {
                cout << -1 << endl;
                goto skip;
            } else {
                if (num == 1e9)
                    sum += maxx;
                else
                    sum += num, cnt++;
            }
        }
        if (sum > 6)
            cout << -1 << endl;
        else {
            if (cnt == 6) {
                if (sum != 6)
                    cout << -1 << endl;
                else
                    cout << 6 << endl;
            } else if (cnt == 5)
                cout << 6 << endl;
            else
                cout << sum << endl;
        }
    skip:;
    }
}
Subtask #1
Accepted
Score: 8
Test case #1
Accepted
Score: 100
Time: 206 ms
Memory: 16712 KiB

Input file

84590 42147
aabbcb
ooxoxx
babbbc
xoxoxx
bbbabb
xoxoox
caaaca
xoxoxo
cbbaab
xxoooo
abcaac
ooxoox
acbc
<1678940 bytes omitted>

Output file

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

<84194 bytes omitted>

Your output

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

<84166 bytes omitted>

System message

Exited with return code 0
Test case #2
Accepted
Score: 100
Time: 74 ms
Memory: 16616 KiB

Input file

83386 7411
acbccb
xooxxo
aaacac
ooxoxx
babaca
ooooox
bcccab
oooxoo
aababb
xooxox
aabbbc
ooxooo
abbbc
<1254249 bytes omitted>

Output file

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

<14722 bytes omitted>

Your output

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

<14694 bytes omitted>

System message

Exited with return code 0
Test case #3
Accepted
Score: 100
Time: 242 ms
Memory: 16620 KiB

Input file

82181 39971
ccbacb
oxooox
cbabbc
oxooxo
acbbbb
ooxoxx
ccbcbc
ooxxox
bbbcab
oxxoox
accbac
ooooxx
bcca
<1619364 bytes omitted>

Output file

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

<79842 bytes omitted>

Your output

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

<79814 bytes omitted>

System message

Exited with return code 0
Test case #4
Accepted
Score: 100
Time: 391 ms
Memory: 17488 KiB

Input file

99997 100000
aaccbb
ooooox
caabac
ooxoxo
bbcbcc
oxoxoo
aabbcb
xoxooo
bbccaa
xoxoxo
bbbbcb
xxxxoo
bcc
<2578001 bytes omitted>

Output file

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

<199900 bytes omitted>

Your output

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

<199872 bytes omitted>

System message

Exited with return code 0
Test case #5
Accepted
Score: 100
Time: 394 ms
Memory: 17516 KiB

Input file

99999 99998
cacaca
oxooxo
abbcab
oxooox
ccbccc
xxooox
cbbbbb
ooxxox
cbcccc
xooxxo
bcaaca
oxooox
abac
<2578006 bytes omitted>

Output file

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4

<199896 bytes omitted>

Your output

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4
5
2
5
4
2
4
5
5
4
3
5
4
4
4

<199868 bytes omitted>

System message

Exited with return code 0
Subtask #2
Accepted
Score: 10
Test case #1
Accepted
Score: 100
Time: 206 ms
Memory: 16712 KiB

Input file

84590 42147
aabbcb
ooxoxx
babbbc
xoxoxx
bbbabb
xoxoox
caaaca
xoxoxo
cbbaab
xxoooo
abcaac
ooxoox
acbc
<1678940 bytes omitted>

Output file

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

<84194 bytes omitted>

Your output

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

<84166 bytes omitted>

System message

Exited with return code 0
Test case #2
Accepted
Score: 100
Time: 74 ms
Memory: 16616 KiB

Input file

83386 7411
acbccb
xooxxo
aaacac
ooxoxx
babaca
ooooox
bcccab
oooxoo
aababb
xooxox
aabbbc
ooxooo
abbbc
<1254249 bytes omitted>

Output file

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

<14722 bytes omitted>

Your output

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

<14694 bytes omitted>

System message

Exited with return code 0
Test case #3
Accepted
Score: 100
Time: 391 ms
Memory: 17488 KiB

Input file

99997 100000
aaccbb
ooooox
caabac
ooxoxo
bbcbcc
oxoxoo
aabbcb
xoxooo
bbccaa
xoxoxo
bbbbcb
xxxxoo
bcc
<2578001 bytes omitted>

Output file

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

<199900 bytes omitted>

Your output

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

<199872 bytes omitted>

System message

Exited with return code 0
Test case #4
Accepted
Score: 100
Time: 394 ms
Memory: 17516 KiB

Input file

99999 99998
cacaca
oxooxo
abbcab
oxooox
ccbccc
xxooox
cbbbbb
ooxxox
cbcccc
xooxxo
bcaaca
oxooox
abac
<2578006 bytes omitted>

Output file

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4

<199896 bytes omitted>

Your output

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4
5
2
5
4
2
4
5
5
4
3
5
4
4
4

<199868 bytes omitted>

System message

Exited with return code 0
Test case #5
Accepted
Score: 100
Time: 299 ms
Memory: 8428 KiB

Input file

36673 94424
fbefbf
xoxxox
cedcdf
xxoxox
cfcfba
xxxxxo
cbceda
xoxxoo
dadcda
oxoxox
eebaae
xxooxx
fded
<1589112 bytes omitted>

Output file

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

<188748 bytes omitted>

Your output

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

<188720 bytes omitted>

System message

Exited with return code 0
Test case #6
Accepted
Score: 100
Time: 140 ms
Memory: 8432 KiB

Input file

35469 26985
cbaeba
oxooxo
accfde
oxxooo
daebbf
oooxxo
bdddcf
xoxxoo
effaff
ooxoxx
acdfdc
oxxooo
aaba
<803588 bytes omitted>

Output file

5
4
5
3
2
2
4
3
4
4
4
2
3
4
4
5
3
4
3
2
2
3
4
4
4
3
4
5
4
2
5
3
4
3
3
5
4
4
3
3
3
3
5
3
3
3
3
4
3
2

<53870 bytes omitted>

Your output

5
4
5
3
2
2
4
3
4
4
4
2
3
4
4
5
3
4
3
2
2
3
4
4
4
3
4
5
4
2
5
3
4
3
3
5
4
4
3
3
3
3
5
3
3
3
3
4
3
2
4
4
4
3
4
3
3
2
3
2
4
3
3
4

<53842 bytes omitted>

System message

Exited with return code 0
Test case #7
Accepted
Score: 100
Time: 402 ms
Memory: 17108 KiB

Input file

88751 98586
aaacde
oxoxox
dcfdfc
oxxxxx
babdba
oooooo
fcedfe
xxxxxx
acffbb
oxxxoo
fecccd
xxxxxo
dacf
<2400756 bytes omitted>

Output file

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

<197072 bytes omitted>

Your output

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

<197044 bytes omitted>

System message

Exited with return code 0
Test case #8
Accepted
Score: 100
Time: 551 ms
Memory: 17512 KiB

Input file

99998 99997
fbcfcf
ooxxox
eccdde
xxxxoo
dfbcbe
ooxxoo
fffcaf
xoxxox
faacab
oxoxox
dafeaf
ooooxx
ccac
<2577652 bytes omitted>

Output file

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

<199894 bytes omitted>

Your output

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

<199866 bytes omitted>

System message

Exited with return code 0
Test case #9
Accepted
Score: 100
Time: 552 ms
Memory: 17648 KiB

Input file

99993 99997
fcbcea
xoooxo
edacfa
xoxoxo
bfccfd
oxooxo
cabbca
ooooxx
eacdee
xoooxx
dbcffa
oooxxo
ceae
<2577464 bytes omitted>

Output file

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

<199894 bytes omitted>

Your output

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

<199866 bytes omitted>

System message

Exited with return code 0
Test case #10
Accepted
Score: 100
Time: 7 ms
Memory: 624 KiB

Input file

4 4
abcdee
xxxxox
abcdee
oxxxxx
abcdee
xxxxxx
aabcde
oxxxxx
1 1
2 2
3 3
4 4

Output file

6
1
6
6

Your output

6
1
6
6

System message

Exited with return code 0
Test case #11
Accepted
Score: 100
Time: 7 ms
Memory: 500 KiB

Input file

1 1
abcdef
xxxxxx
1 1

Output file

-1

Your output

-1

System message

Exited with return code 0
Subtask #3
Accepted
Score: 19
Test case #1
Accepted
Score: 100
Time: 206 ms
Memory: 16712 KiB

Input file

84590 42147
aabbcb
ooxoxx
babbbc
xoxoxx
bbbabb
xoxoox
caaaca
xoxoxo
cbbaab
xxoooo
abcaac
ooxoox
acbc
<1678940 bytes omitted>

Output file

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

<84194 bytes omitted>

Your output

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

<84166 bytes omitted>

System message

Exited with return code 0
Test case #2
Accepted
Score: 100
Time: 74 ms
Memory: 16616 KiB

Input file

83386 7411
acbccb
xooxxo
aaacac
ooxoxx
babaca
ooooox
bcccab
oooxoo
aababb
xooxox
aabbbc
ooxooo
abbbc
<1254249 bytes omitted>

Output file

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

<14722 bytes omitted>

Your output

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

<14694 bytes omitted>

System message

Exited with return code 0
Test case #3
Accepted
Score: 100
Time: 391 ms
Memory: 17488 KiB

Input file

99997 100000
aaccbb
ooooox
caabac
ooxoxo
bbcbcc
oxoxoo
aabbcb
xoxooo
bbccaa
xoxoxo
bbbbcb
xxxxoo
bcc
<2578001 bytes omitted>

Output file

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

<199900 bytes omitted>

Your output

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

<199872 bytes omitted>

System message

Exited with return code 0
Test case #4
Accepted
Score: 100
Time: 394 ms
Memory: 17516 KiB

Input file

99999 99998
cacaca
oxooxo
abbcab
oxooox
ccbccc
xxooox
cbbbbb
ooxxox
cbcccc
xooxxo
bcaaca
oxooox
abac
<2578006 bytes omitted>

Output file

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4

<199896 bytes omitted>

Your output

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4
5
2
5
4
2
4
5
5
4
3
5
4
4
4

<199868 bytes omitted>

System message

Exited with return code 0
Test case #5
Accepted
Score: 100
Time: 299 ms
Memory: 8428 KiB

Input file

36673 94424
fbefbf
xoxxox
cedcdf
xxoxox
cfcfba
xxxxxo
cbceda
xoxxoo
dadcda
oxoxox
eebaae
xxooxx
fded
<1589112 bytes omitted>

Output file

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

<188748 bytes omitted>

Your output

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

<188720 bytes omitted>

System message

Exited with return code 0
Test case #6
Accepted
Score: 100
Time: 42 ms
Memory: 4340 KiB

Input file

17541 11593
bbcaac
oxoxoo
ccabac
ooxooo
bcbacb
xoxooo
ccabba
oooxox
babaca
xxooox
cbacab
ooxoox
bcca
<369890 bytes omitted>

Output file

4
4
4
4
4
5
3
6
4
4
4
4
2
-1
5
4
5
3
2
2
2
1
-1
5
5
4
-1
4
6
5
-1
-1
5
-1
4
3
4
5
4
-1
5
-1
4
4
5
-1
<24894 bytes omitted>

Your output

4
4
4
4
4
5
3
6
4
4
4
4
2
-1
5
4
5
3
2
2
2
1
-1
5
5
4
-1
4
6
5
-1
-1
5
-1
4
3
4
5
4
-1
5
-1
4
4
5
-1
5
4
3
2
-1
-1
5
3
5
3
4
5
4
<24866 bytes omitted>

System message

Exited with return code 0
Test case #7
Accepted
Score: 100
Time: 371 ms
Memory: 17644 KiB

Input file

99997 99992
baaabc
oxxxoo
cbcbab
oxxoxo
bbbbcc
xxooox
abaabb
xoxxxo
abccca
xoxoxx
bbbaaa
oxoxxx
cbab
<2577694 bytes omitted>

Output file

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

<216400 bytes omitted>

Your output

1
-1
3
3
4
3
3
2
2
-1
3
3
3
2
3
2
3
4
-1
2
2
3
3
-1
3
-1
3
3
-1
2
4
-1
3
3
-1
3
1
0
1
4
3
2
3
1
3
2
4
4
2
2
2
3
3
1
2
-1
3
3
3
3
<216372 bytes omitted>

System message

Exited with return code 0
Test case #8
Accepted
Score: 100
Time: 436 ms
Memory: 17640 KiB

Input file

99998 99993
babbcc
oxxxox
bcbabb
xooxxx
ccccab
xxoxxo
bcbbcc
xxooox
bbbbba
oxoxxx
aaacab
xxxoxo
abcc
<2577579 bytes omitted>

Output file

2
3
2
2
2
2
-1
1
2
2
2
2
-1
2
2
2
-1
2
2
2
2
2
3
-1
2
2
3
1
2
-1
2
2
2
2
2
2
-1
3
2
2
2
2
3
2
1
-1
2
<217609 bytes omitted>

Your output

2
3
2
2
2
2
-1
1
2
2
2
2
-1
2
2
2
-1
2
2
2
2
2
3
-1
2
2
3
1
2
-1
2
2
2
2
2
2
-1
3
2
2
2
2
3
2
1
-1
2
2
2
2
1
2
2
2
2
-1
2
1
2
-1
<217581 bytes omitted>

System message

Exited with return code 0
Test case #9
Accepted
Score: 100
Time: 7 ms
Memory: 488 KiB

Input file

14 7
aaaaaa
oooooo
aabbcc
ooxxxx
aaaaaa
ooooox
aabbbb
ooxxox
aabbcc
oxoxoo
bbbbcc
xoxoxo
aabbcc
oooo
<134 bytes omitted>

Output file

6
6
-1
4
-1
-1
-1

Your output

6
6
-1
4
-1
-1
-1

System message

Exited with return code 0
Subtask #4
Accepted
Score: 6
Test case #1
Accepted
Score: 100
Time: 6 ms
Memory: 504 KiB

Input file

2 2
aabbcc
oxoxox
dddeee
ooxxxx
1 1
1 2

Output file

3
6

Your output

3
6

System message

Exited with return code 0
Test case #2
Accepted
Score: 100
Time: 206 ms
Memory: 16712 KiB

Input file

84590 42147
aabbcb
ooxoxx
babbbc
xoxoxx
bbbabb
xoxoox
caaaca
xoxoxo
cbbaab
xxoooo
abcaac
ooxoox
acbc
<1678940 bytes omitted>

Output file

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

<84194 bytes omitted>

Your output

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

<84166 bytes omitted>

System message

Exited with return code 0
Test case #3
Accepted
Score: 100
Time: 74 ms
Memory: 16616 KiB

Input file

83386 7411
acbccb
xooxxo
aaacac
ooxoxx
babaca
ooooox
bcccab
oooxoo
aababb
xooxox
aabbbc
ooxooo
abbbc
<1254249 bytes omitted>

Output file

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

<14722 bytes omitted>

Your output

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

<14694 bytes omitted>

System message

Exited with return code 0
Test case #4
Accepted
Score: 100
Time: 391 ms
Memory: 17488 KiB

Input file

99997 100000
aaccbb
ooooox
caabac
ooxoxo
bbcbcc
oxoxoo
aabbcb
xoxooo
bbccaa
xoxoxo
bbbbcb
xxxxoo
bcc
<2578001 bytes omitted>

Output file

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

<199900 bytes omitted>

Your output

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

<199872 bytes omitted>

System message

Exited with return code 0
Test case #5
Accepted
Score: 100
Time: 394 ms
Memory: 17516 KiB

Input file

99999 99998
cacaca
oxooxo
abbcab
oxooox
ccbccc
xxooox
cbbbbb
ooxxox
cbcccc
xooxxo
bcaaca
oxooox
abac
<2578006 bytes omitted>

Output file

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4

<199896 bytes omitted>

Your output

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4
5
2
5
4
2
4
5
5
4
3
5
4
4
4

<199868 bytes omitted>

System message

Exited with return code 0
Test case #6
Accepted
Score: 100
Time: 299 ms
Memory: 8428 KiB

Input file

36673 94424
fbefbf
xoxxox
cedcdf
xxoxox
cfcfba
xxxxxo
cbceda
xoxxoo
dadcda
oxoxox
eebaae
xxooxx
fded
<1589112 bytes omitted>

Output file

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

<188748 bytes omitted>

Your output

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

<188720 bytes omitted>

System message

Exited with return code 0
Test case #7
Accepted
Score: 100
Time: 140 ms
Memory: 8432 KiB

Input file

35469 26985
cbaeba
oxooxo
accfde
oxxooo
daebbf
oooxxo
bdddcf
xoxxoo
effaff
ooxoxx
acdfdc
oxxooo
aaba
<803588 bytes omitted>

Output file

5
4
5
3
2
2
4
3
4
4
4
2
3
4
4
5
3
4
3
2
2
3
4
4
4
3
4
5
4
2
5
3
4
3
3
5
4
4
3
3
3
3
5
3
3
3
3
4
3
2

<53870 bytes omitted>

Your output

5
4
5
3
2
2
4
3
4
4
4
2
3
4
4
5
3
4
3
2
2
3
4
4
4
3
4
5
4
2
5
3
4
3
3
5
4
4
3
3
3
3
5
3
3
3
3
4
3
2
4
4
4
3
4
3
3
2
3
2
4
3
3
4

<53842 bytes omitted>

System message

Exited with return code 0
Test case #8
Accepted
Score: 100
Time: 402 ms
Memory: 17108 KiB

Input file

88751 98586
aaacde
oxoxox
dcfdfc
oxxxxx
babdba
oooooo
fcedfe
xxxxxx
acffbb
oxxxoo
fecccd
xxxxxo
dacf
<2400756 bytes omitted>

Output file

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

<197072 bytes omitted>

Your output

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

<197044 bytes omitted>

System message

Exited with return code 0
Test case #9
Accepted
Score: 100
Time: 551 ms
Memory: 17512 KiB

Input file

99998 99997
fbcfcf
ooxxox
eccdde
xxxxoo
dfbcbe
ooxxoo
fffcaf
xoxxox
faacab
oxoxox
dafeaf
ooooxx
ccac
<2577652 bytes omitted>

Output file

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

<199894 bytes omitted>

Your output

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

<199866 bytes omitted>

System message

Exited with return code 0
Test case #10
Accepted
Score: 100
Time: 552 ms
Memory: 17648 KiB

Input file

99993 99997
fcbcea
xoooxo
edacfa
xoxoxo
bfccfd
oxooxo
cabbca
ooooxx
eacdee
xoooxx
dbcffa
oooxxo
ceae
<2577464 bytes omitted>

Output file

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

<199894 bytes omitted>

Your output

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

<199866 bytes omitted>

System message

Exited with return code 0
Test case #11
Accepted
Score: 100
Time: 42 ms
Memory: 4340 KiB

Input file

17541 11593
bbcaac
oxoxoo
ccabac
ooxooo
bcbacb
xoxooo
ccabba
oooxox
babaca
xxooox
cbacab
ooxoox
bcca
<369890 bytes omitted>

Output file

4
4
4
4
4
5
3
6
4
4
4
4
2
-1
5
4
5
3
2
2
2
1
-1
5
5
4
-1
4
6
5
-1
-1
5
-1
4
3
4
5
4
-1
5
-1
4
4
5
-1
<24894 bytes omitted>

Your output

4
4
4
4
4
5
3
6
4
4
4
4
2
-1
5
4
5
3
2
2
2
1
-1
5
5
4
-1
4
6
5
-1
-1
5
-1
4
3
4
5
4
-1
5
-1
4
4
5
-1
5
4
3
2
-1
-1
5
3
5
3
4
5
4
<24866 bytes omitted>

System message

Exited with return code 0
Test case #12
Accepted
Score: 100
Time: 371 ms
Memory: 17644 KiB

Input file

99997 99992
baaabc
oxxxoo
cbcbab
oxxoxo
bbbbcc
xxooox
abaabb
xoxxxo
abccca
xoxoxx
bbbaaa
oxoxxx
cbab
<2577694 bytes omitted>

Output file

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

<216400 bytes omitted>

Your output

1
-1
3
3
4
3
3
2
2
-1
3
3
3
2
3
2
3
4
-1
2
2
3
3
-1
3
-1
3
3
-1
2
4
-1
3
3
-1
3
1
0
1
4
3
2
3
1
3
2
4
4
2
2
2
3
3
1
2
-1
3
3
3
3
<216372 bytes omitted>

System message

Exited with return code 0
Test case #13
Accepted
Score: 100
Time: 436 ms
Memory: 17640 KiB

Input file

99998 99993
babbcc
oxxxox
bcbabb
xooxxx
ccccab
xxoxxo
bcbbcc
xxooox
bbbbba
oxoxxx
aaacab
xxxoxo
abcc
<2577579 bytes omitted>

Output file

2
3
2
2
2
2
-1
1
2
2
2
2
-1
2
2
2
-1
2
2
2
2
2
3
-1
2
2
3
1
2
-1
2
2
2
2
2
2
-1
3
2
2
2
2
3
2
1
-1
2
<217609 bytes omitted>

Your output

2
3
2
2
2
2
-1
1
2
2
2
2
-1
2
2
2
-1
2
2
2
2
2
3
-1
2
2
3
1
2
-1
2
2
2
2
2
2
-1
3
2
2
2
2
3
2
1
-1
2
2
2
2
1
2
2
2
2
-1
2
1
2
-1
<217581 bytes omitted>

System message

Exited with return code 0
Test case #14
Accepted
Score: 100
Time: 288 ms
Memory: 16300 KiB

Input file

70828 65903
cedfca
ooxooo
abbfba
oxxoxx
fddfad
xxxoox
bcbcbb
ooxoxx
ebcdce
oxoxox
fbeeff
xxxooo
aebf
<1761814 bytes omitted>

Output file

6
1
5
5
4
3
3
4
4
4
4
3
-1
4
4
-1
4
4
6
-1
5
3
2
-1
3
1
4
-1
1
4
5
5
3
2
3
4
4
3
4
3
-1
-1
2
4
5
3
3
<140089 bytes omitted>

Your output

6
1
5
5
4
3
3
4
4
4
4
3
-1
4
4
-1
4
4
6
-1
5
3
2
-1
3
1
4
-1
1
4
5
5
3
2
3
4
4
3
4
3
-1
-1
2
4
5
3
3
2
3
1
4
1
3
-1
3
-1
4
4
3
-
<140061 bytes omitted>

System message

Exited with return code 0
Test case #15
Accepted
Score: 100
Time: 176 ms
Memory: 16108 KiB

Input file

69624 31167
cafeab
ooxoxo
afabfa
oxxoxx
baefbe
oooxxo
dfacfe
xxooxo
cfaaca
oxoxxo
cbddad
xoxxox
dabb
<1338647 bytes omitted>

Output file

3
-1
5
4
6
4
5
-1
4
3
4
5
4
3
5
4
4
2
5
3
4
-1
4
2
4
4
1
3
4
3
6
-1
3
4
5
6
2
4
6
4
4
4
-1
5
5
3
4
3
<66198 bytes omitted>

Your output

3
-1
5
4
6
4
5
-1
4
3
4
5
4
3
5
4
4
2
5
3
4
-1
4
2
4
4
1
3
4
3
6
-1
3
4
5
6
2
4
6
4
4
4
-1
5
5
3
4
3
2
4
-1
-1
5
4
4
3
2
6
3
3
-
<66170 bytes omitted>

System message

Exited with return code 0
Test case #16
Accepted
Score: 100
Time: 497 ms
Memory: 17648 KiB

Input file

99998 99999
cbeacb
oxxoox
deceaa
oxoxoo
ecaeef
xooxxo
bafafd
xoxooo
fdbbfd
xxxxoo
cccece
oxxxox
ccdc
<2577321 bytes omitted>

Output file

3
4
2
5
-1
4
5
5
4
3
4
6
3
3
2
1
6
6
-1
-1
4
3
3
2
-1
4
-1
4
4
3
6
5
6
-1
-1
6
4
5
-1
3
-1
5
-1
4
3

<212373 bytes omitted>

Your output

3
4
2
5
-1
4
5
5
4
3
4
6
3
3
2
1
6
6
-1
-1
4
3
3
2
-1
4
-1
4
4
3
6
5
6
-1
-1
6
4
5
-1
3
-1
5
-1
4
3
5
3
4
-1
4
-1
3
-1
4
3
-1
-1
<212345 bytes omitted>

System message

Exited with return code 0
Test case #17
Accepted
Score: 100
Time: 451 ms
Memory: 17548 KiB

Input file

99999 99997
cbbebc
oxxxxo
babfee
xoxxox
feabdc
xxxxoo
caaded
ooooxx
facada
xooooo
baeafd
xoxoxo
efea
<2577655 bytes omitted>

Output file

5
3
3
1
2
1
3
6
5
4
-1
3
5
3
3
3
2
3
3
2
2
3
1
-1
3
3
3
6
-1
-1
4
1
2
2
2
4
2
2
3
3
3
4
3
3
-1
-1
4

<212453 bytes omitted>

Your output

5
3
3
1
2
1
3
6
5
4
-1
3
5
3
3
3
2
3
3
2
2
3
1
-1
3
3
3
6
-1
-1
4
1
2
2
2
4
2
2
3
3
3
4
3
3
-1
-1
4
3
6
3
3
-1
6
3
-1
2
3
4
4
3

<212425 bytes omitted>

System message

Exited with return code 0
Test case #18
Accepted
Score: 100
Time: 536 ms
Memory: 17904 KiB

Input file

99994 99994
fddbbd
ooxoxo
ffbced
xxoooo
afbcfb
xoxoxo
dffffc
oxxoxo
fdeceb
ooooxo
dfccff
ooxoxx
bdab
<2577440 bytes omitted>

Output file

4
5
5
2
5
5
6
-1
4
3
2
4
2
4
3
3
4
6
3
5
4
3
2
-1
5
-1
-1
5
4
5
3
4
4
5
5
6
4
5
6
5
4
5
3
-1
5
5
4
5
<213092 bytes omitted>

Your output

4
5
5
2
5
5
6
-1
4
3
2
4
2
4
3
3
4
6
3
5
4
3
2
-1
5
-1
-1
5
4
5
3
4
4
5
5
6
4
5
6
5
4
5
3
-1
5
5
4
5
6
6
5
6
2
3
3
5
4
5
3
4
4
3
<213064 bytes omitted>

System message

Exited with return code 0
Test case #19
Accepted
Score: 100
Time: 527 ms
Memory: 17616 KiB

Input file

99999 99991
ffeafe
xxxoox
ddfccc
oxoxxo
becbbe
oxooox
cabbeb
ooxoxo
ccfabb
oxooox
bdbdbc
ooxxoo
ceba
<2577761 bytes omitted>

Output file

1
6
4
2
3
4
5
2
3
5
3
5
4
4
5
4
6
3
6
4
5
5
5
3
5
4
-1
5
3
-1
5
4
-1
6
6
3
4
5
2
-1
6
4
4
6
6
5
4
3

<213061 bytes omitted>

Your output

1
6
4
2
3
4
5
2
3
5
3
5
4
4
5
4
6
3
6
4
5
5
5
3
5
4
-1
5
3
-1
5
4
-1
6
6
3
4
5
2
-1
6
4
4
6
6
5
4
3
5
4
4
-1
5
5
2
5
4
4
3
4
6
3
<213033 bytes omitted>

System message

Exited with return code 0
Test case #20
Accepted
Score: 100
Time: 7 ms
Memory: 624 KiB

Input file

4 4
abcdee
xxxxox
abcdee
oxxxxx
abcdee
xxxxxx
aabcde
oxxxxx
1 1
2 2
3 3
4 4

Output file

6
1
6
6

Your output

6
1
6
6

System message

Exited with return code 0
Test case #21
Accepted
Score: 100
Time: 7 ms
Memory: 488 KiB

Input file

14 7
aaaaaa
oooooo
aabbcc
ooxxxx
aaaaaa
ooooox
aabbbb
ooxxox
aabbcc
oxoxoo
bbbbcc
xoxoxo
aabbcc
oooo
<134 bytes omitted>

Output file

6
6
-1
4
-1
-1
-1

Your output

6
6
-1
4
-1
-1
-1

System message

Exited with return code 0
Test case #22
Accepted
Score: 100
Time: 6 ms
Memory: 492 KiB

Input file

8 4
aaaaaa
ooooox
bcdeaa
xxxxoo
aaabbb
oooxxx
ccddee
xxxxxx
aaaaab
ooooox
ccddee
xxxxxx
aaaaab
ooooo
<32 bytes omitted>

Output file

6
3
5
6

Your output

6
3
5
6

System message

Exited with return code 0
Test case #23
Accepted
Score: 100
Time: 5 ms
Memory: 508 KiB

Input file

2 1
abcdef
oooooo
abcdee
oooooo
1 2

Output file

-1

Your output

-1

System message

Exited with return code 0
Test case #24
Accepted
Score: 100
Time: 7 ms
Memory: 500 KiB

Input file

1 1
abcdef
xxxxxx
1 1

Output file

-1

Your output

-1

System message

Exited with return code 0
Test case #25
Accepted
Score: 100
Time: 8 ms
Memory: 492 KiB

Input file

2 1
abcdef
xxxxxx
abcdef
xxxxxx
1 2

Output file

-1

Your output

-1

System message

Exited with return code 0
Subtask #5
Accepted
Score: 30
Test case #1
Accepted
Score: 100
Time: 6 ms
Memory: 504 KiB

Input file

2 2
aabbcc
oxoxox
dddeee
ooxxxx
1 1
1 2

Output file

3
6

Your output

3
6

System message

Exited with return code 0
Test case #2
Accepted
Score: 100
Time: 206 ms
Memory: 16712 KiB

Input file

84590 42147
aabbcb
ooxoxx
babbbc
xoxoxx
bbbabb
xoxoox
caaaca
xoxoxo
cbbaab
xxoooo
abcaac
ooxoox
acbc
<1678940 bytes omitted>

Output file

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

<84194 bytes omitted>

Your output

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

<84166 bytes omitted>

System message

Exited with return code 0
Test case #3
Accepted
Score: 100
Time: 74 ms
Memory: 16616 KiB

Input file

83386 7411
acbccb
xooxxo
aaacac
ooxoxx
babaca
ooooox
bcccab
oooxoo
aababb
xooxox
aabbbc
ooxooo
abbbc
<1254249 bytes omitted>

Output file

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

<14722 bytes omitted>

Your output

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

<14694 bytes omitted>

System message

Exited with return code 0
Test case #4
Accepted
Score: 100
Time: 391 ms
Memory: 17488 KiB

Input file

99997 100000
aaccbb
ooooox
caabac
ooxoxo
bbcbcc
oxoxoo
aabbcb
xoxooo
bbccaa
xoxoxo
bbbbcb
xxxxoo
bcc
<2578001 bytes omitted>

Output file

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

<199900 bytes omitted>

Your output

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

<199872 bytes omitted>

System message

Exited with return code 0
Test case #5
Accepted
Score: 100
Time: 394 ms
Memory: 17516 KiB

Input file

99999 99998
cacaca
oxooxo
abbcab
oxooox
ccbccc
xxooox
cbbbbb
ooxxox
cbcccc
xooxxo
bcaaca
oxooox
abac
<2578006 bytes omitted>

Output file

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4

<199896 bytes omitted>

Your output

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4
5
2
5
4
2
4
5
5
4
3
5
4
4
4

<199868 bytes omitted>

System message

Exited with return code 0
Test case #6
Accepted
Score: 100
Time: 299 ms
Memory: 8428 KiB

Input file

36673 94424
fbefbf
xoxxox
cedcdf
xxoxox
cfcfba
xxxxxo
cbceda
xoxxoo
dadcda
oxoxox
eebaae
xxooxx
fded
<1589112 bytes omitted>

Output file

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

<188748 bytes omitted>

Your output

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

<188720 bytes omitted>

System message

Exited with return code 0
Test case #7
Accepted
Score: 100
Time: 140 ms
Memory: 8432 KiB

Input file

35469 26985
cbaeba
oxooxo
accfde
oxxooo
daebbf
oooxxo
bdddcf
xoxxoo
effaff
ooxoxx
acdfdc
oxxooo
aaba
<803588 bytes omitted>

Output file

5
4
5
3
2
2
4
3
4
4
4
2
3
4
4
5
3
4
3
2
2
3
4
4
4
3
4
5
4
2
5
3
4
3
3
5
4
4
3
3
3
3
5
3
3
3
3
4
3
2

<53870 bytes omitted>

Your output

5
4
5
3
2
2
4
3
4
4
4
2
3
4
4
5
3
4
3
2
2
3
4
4
4
3
4
5
4
2
5
3
4
3
3
5
4
4
3
3
3
3
5
3
3
3
3
4
3
2
4
4
4
3
4
3
3
2
3
2
4
3
3
4

<53842 bytes omitted>

System message

Exited with return code 0
Test case #8
Accepted
Score: 100
Time: 402 ms
Memory: 17108 KiB

Input file

88751 98586
aaacde
oxoxox
dcfdfc
oxxxxx
babdba
oooooo
fcedfe
xxxxxx
acffbb
oxxxoo
fecccd
xxxxxo
dacf
<2400756 bytes omitted>

Output file

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

<197072 bytes omitted>

Your output

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

<197044 bytes omitted>

System message

Exited with return code 0
Test case #9
Accepted
Score: 100
Time: 551 ms
Memory: 17512 KiB

Input file

99998 99997
fbcfcf
ooxxox
eccdde
xxxxoo
dfbcbe
ooxxoo
fffcaf
xoxxox
faacab
oxoxox
dafeaf
ooooxx
ccac
<2577652 bytes omitted>

Output file

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

<199894 bytes omitted>

Your output

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

<199866 bytes omitted>

System message

Exited with return code 0
Test case #10
Accepted
Score: 100
Time: 552 ms
Memory: 17648 KiB

Input file

99993 99997
fcbcea
xoooxo
edacfa
xoxoxo
bfccfd
oxooxo
cabbca
ooooxx
eacdee
xoooxx
dbcffa
oooxxo
ceae
<2577464 bytes omitted>

Output file

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

<199894 bytes omitted>

Your output

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

<199866 bytes omitted>

System message

Exited with return code 0
Test case #11
Accepted
Score: 100
Time: 42 ms
Memory: 4340 KiB

Input file

17541 11593
bbcaac
oxoxoo
ccabac
ooxooo
bcbacb
xoxooo
ccabba
oooxox
babaca
xxooox
cbacab
ooxoox
bcca
<369890 bytes omitted>

Output file

4
4
4
4
4
5
3
6
4
4
4
4
2
-1
5
4
5
3
2
2
2
1
-1
5
5
4
-1
4
6
5
-1
-1
5
-1
4
3
4
5
4
-1
5
-1
4
4
5
-1
<24894 bytes omitted>

Your output

4
4
4
4
4
5
3
6
4
4
4
4
2
-1
5
4
5
3
2
2
2
1
-1
5
5
4
-1
4
6
5
-1
-1
5
-1
4
3
4
5
4
-1
5
-1
4
4
5
-1
5
4
3
2
-1
-1
5
3
5
3
4
5
4
<24866 bytes omitted>

System message

Exited with return code 0
Test case #12
Accepted
Score: 100
Time: 371 ms
Memory: 17644 KiB

Input file

99997 99992
baaabc
oxxxoo
cbcbab
oxxoxo
bbbbcc
xxooox
abaabb
xoxxxo
abccca
xoxoxx
bbbaaa
oxoxxx
cbab
<2577694 bytes omitted>

Output file

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

<216400 bytes omitted>

Your output

1
-1
3
3
4
3
3
2
2
-1
3
3
3
2
3
2
3
4
-1
2
2
3
3
-1
3
-1
3
3
-1
2
4
-1
3
3
-1
3
1
0
1
4
3
2
3
1
3
2
4
4
2
2
2
3
3
1
2
-1
3
3
3
3
<216372 bytes omitted>

System message

Exited with return code 0
Test case #13
Accepted
Score: 100
Time: 436 ms
Memory: 17640 KiB

Input file

99998 99993
babbcc
oxxxox
bcbabb
xooxxx
ccccab
xxoxxo
bcbbcc
xxooox
bbbbba
oxoxxx
aaacab
xxxoxo
abcc
<2577579 bytes omitted>

Output file

2
3
2
2
2
2
-1
1
2
2
2
2
-1
2
2
2
-1
2
2
2
2
2
3
-1
2
2
3
1
2
-1
2
2
2
2
2
2
-1
3
2
2
2
2
3
2
1
-1
2
<217609 bytes omitted>

Your output

2
3
2
2
2
2
-1
1
2
2
2
2
-1
2
2
2
-1
2
2
2
2
2
3
-1
2
2
3
1
2
-1
2
2
2
2
2
2
-1
3
2
2
2
2
3
2
1
-1
2
2
2
2
1
2
2
2
2
-1
2
1
2
-1
<217581 bytes omitted>

System message

Exited with return code 0
Test case #14
Accepted
Score: 100
Time: 288 ms
Memory: 16300 KiB

Input file

70828 65903
cedfca
ooxooo
abbfba
oxxoxx
fddfad
xxxoox
bcbcbb
ooxoxx
ebcdce
oxoxox
fbeeff
xxxooo
aebf
<1761814 bytes omitted>

Output file

6
1
5
5
4
3
3
4
4
4
4
3
-1
4
4
-1
4
4
6
-1
5
3
2
-1
3
1
4
-1
1
4
5
5
3
2
3
4
4
3
4
3
-1
-1
2
4
5
3
3
<140089 bytes omitted>

Your output

6
1
5
5
4
3
3
4
4
4
4
3
-1
4
4
-1
4
4
6
-1
5
3
2
-1
3
1
4
-1
1
4
5
5
3
2
3
4
4
3
4
3
-1
-1
2
4
5
3
3
2
3
1
4
1
3
-1
3
-1
4
4
3
-
<140061 bytes omitted>

System message

Exited with return code 0
Test case #15
Accepted
Score: 100
Time: 176 ms
Memory: 16108 KiB

Input file

69624 31167
cafeab
ooxoxo
afabfa
oxxoxx
baefbe
oooxxo
dfacfe
xxooxo
cfaaca
oxoxxo
cbddad
xoxxox
dabb
<1338647 bytes omitted>

Output file

3
-1
5
4
6
4
5
-1
4
3
4
5
4
3
5
4
4
2
5
3
4
-1
4
2
4
4
1
3
4
3
6
-1
3
4
5
6
2
4
6
4
4
4
-1
5
5
3
4
3
<66198 bytes omitted>

Your output

3
-1
5
4
6
4
5
-1
4
3
4
5
4
3
5
4
4
2
5
3
4
-1
4
2
4
4
1
3
4
3
6
-1
3
4
5
6
2
4
6
4
4
4
-1
5
5
3
4
3
2
4
-1
-1
5
4
4
3
2
6
3
3
-
<66170 bytes omitted>

System message

Exited with return code 0
Test case #16
Accepted
Score: 100
Time: 497 ms
Memory: 17648 KiB

Input file

99998 99999
cbeacb
oxxoox
deceaa
oxoxoo
ecaeef
xooxxo
bafafd
xoxooo
fdbbfd
xxxxoo
cccece
oxxxox
ccdc
<2577321 bytes omitted>

Output file

3
4
2
5
-1
4
5
5
4
3
4
6
3
3
2
1
6
6
-1
-1
4
3
3
2
-1
4
-1
4
4
3
6
5
6
-1
-1
6
4
5
-1
3
-1
5
-1
4
3

<212373 bytes omitted>

Your output

3
4
2
5
-1
4
5
5
4
3
4
6
3
3
2
1
6
6
-1
-1
4
3
3
2
-1
4
-1
4
4
3
6
5
6
-1
-1
6
4
5
-1
3
-1
5
-1
4
3
5
3
4
-1
4
-1
3
-1
4
3
-1
-1
<212345 bytes omitted>

System message

Exited with return code 0
Test case #17
Accepted
Score: 100
Time: 451 ms
Memory: 17548 KiB

Input file

99999 99997
cbbebc
oxxxxo
babfee
xoxxox
feabdc
xxxxoo
caaded
ooooxx
facada
xooooo
baeafd
xoxoxo
efea
<2577655 bytes omitted>

Output file

5
3
3
1
2
1
3
6
5
4
-1
3
5
3
3
3
2
3
3
2
2
3
1
-1
3
3
3
6
-1
-1
4
1
2
2
2
4
2
2
3
3
3
4
3
3
-1
-1
4

<212453 bytes omitted>

Your output

5
3
3
1
2
1
3
6
5
4
-1
3
5
3
3
3
2
3
3
2
2
3
1
-1
3
3
3
6
-1
-1
4
1
2
2
2
4
2
2
3
3
3
4
3
3
-1
-1
4
3
6
3
3
-1
6
3
-1
2
3
4
4
3

<212425 bytes omitted>

System message

Exited with return code 0
Test case #18
Accepted
Score: 100
Time: 536 ms
Memory: 17904 KiB

Input file

99994 99994
fddbbd
ooxoxo
ffbced
xxoooo
afbcfb
xoxoxo
dffffc
oxxoxo
fdeceb
ooooxo
dfccff
ooxoxx
bdab
<2577440 bytes omitted>

Output file

4
5
5
2
5
5
6
-1
4
3
2
4
2
4
3
3
4
6
3
5
4
3
2
-1
5
-1
-1
5
4
5
3
4
4
5
5
6
4
5
6
5
4
5
3
-1
5
5
4
5
<213092 bytes omitted>

Your output

4
5
5
2
5
5
6
-1
4
3
2
4
2
4
3
3
4
6
3
5
4
3
2
-1
5
-1
-1
5
4
5
3
4
4
5
5
6
4
5
6
5
4
5
3
-1
5
5
4
5
6
6
5
6
2
3
3
5
4
5
3
4
4
3
<213064 bytes omitted>

System message

Exited with return code 0
Test case #19
Accepted
Score: 100
Time: 527 ms
Memory: 17616 KiB

Input file

99999 99991
ffeafe
xxxoox
ddfccc
oxoxxo
becbbe
oxooox
cabbeb
ooxoxo
ccfabb
oxooox
bdbdbc
ooxxoo
ceba
<2577761 bytes omitted>

Output file

1
6
4
2
3
4
5
2
3
5
3
5
4
4
5
4
6
3
6
4
5
5
5
3
5
4
-1
5
3
-1
5
4
-1
6
6
3
4
5
2
-1
6
4
4
6
6
5
4
3

<213061 bytes omitted>

Your output

1
6
4
2
3
4
5
2
3
5
3
5
4
4
5
4
6
3
6
4
5
5
5
3
5
4
-1
5
3
-1
5
4
-1
6
6
3
4
5
2
-1
6
4
4
6
6
5
4
3
5
4
4
-1
5
5
2
5
4
4
3
4
6
3
<213033 bytes omitted>

System message

Exited with return code 0
Test case #20
Accepted
Score: 100
Time: 150 ms
Memory: 8788 KiB

Input file

42234 34548
baaaac
ooxxxx
abcbca
xoxoxo
acbcaa
xxoxxo
bacccc
ooxxxx
bccaba
oxxxoo
bcaaac
oxoxxx
abbc
<987843 bytes omitted>

Output file

-1
3
-1
3
3
3
3
-1
3
3
3
3
3
3
-1
3
-1
-1
3
-1
3
3
-1
3
3
3
3
3
3
-1
3
3
3
3
3
-1
3
3
-1
3
3
3
3
-1

<82054 bytes omitted>

Your output

-1
3
-1
3
3
3
3
-1
3
3
3
3
3
3
-1
3
-1
-1
3
-1
3
3
-1
3
3
3
3
3
3
-1
3
3
3
3
3
-1
3
3
-1
3
3
3
3
-1
3
3
3
-1
3
3
3
-1
3
3
-1
2
3
<82026 bytes omitted>

System message

Exited with return code 0
Test case #21
Accepted
Score: 100
Time: 86 ms
Memory: 17008 KiB

Input file

90012 9353
bbbbcc
xxxxoo
bbcbcb
xxoxox
abbaba
oxxxxo
bcbbac
xoxxoo
ccbacb
ooxoxx
babccc
xoxxoo
cccbc
<1369973 bytes omitted>

Output file

-1
4
-1
4
4
4
-1
-1
4
4
-1
-1
4
4
3
-1
4
4
4
4
-1
4
4
4
4
-1
4
4
4
-1
4
4
4
4
4
-1
-1
-1
4
-1
4
4
4

<22008 bytes omitted>

Your output

-1
4
-1
4
4
4
-1
-1
4
4
-1
-1
4
4
3
-1
4
4
4
4
-1
4
4
4
4
-1
4
4
4
-1
4
4
4
4
4
-1
-1
-1
4
-1
4
4
4
4
4
4
4
-1
4
-1
-1
-1
4
-1
4
<21980 bytes omitted>

System message

Exited with return code 0
Test case #22
Accepted
Score: 100
Time: 423 ms
Memory: 17484 KiB

Input file

99995 99992
bbbccc
xxxooo
acbcbc
ooxoxo
cbabca
oxoxoo
abcbca
oxoxoo
aaaabc
xxooxo
bbccbb
xxooxx
abca
<2577796 bytes omitted>

Output file

5
5
5
-1
-1
5
5
5
5
4
-1
-1
-1
5
5
-1
5
-1
5
5
5
-1
-1
4
5
5
5
5
-1
5
5
-1
-1
5
5
5
-1
5
5
-1
5
5
-1
<239463 bytes omitted>

Your output

5
5
5
-1
-1
5
5
5
5
4
-1
-1
-1
5
5
-1
5
-1
5
5
5
-1
-1
4
5
5
5
5
-1
5
5
-1
-1
5
5
5
-1
5
5
-1
5
5
-1
5
5
-1
5
5
5
5
-1
-1
-1
-1

<239435 bytes omitted>

System message

Exited with return code 0
Test case #23
Accepted
Score: 100
Time: 495 ms
Memory: 16720 KiB

Input file

73896 69983
caccbc
xoxoox
aabaaa
xoooxo
ccbaaa
xooooo
bacaab
xooooo
acbbac
oooxox
cbccab
xooxox
cbca
<1839239 bytes omitted>

Output file

5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5

<139866 bytes omitted>

Your output

5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5

<139838 bytes omitted>

System message

Exited with return code 0
Test case #24
Accepted
Score: 100
Time: 468 ms
Memory: 9308 KiB

Input file

56804 97814
aacaca
oooooo
bcaacb
xoooox
cacbcc
xooxxo
bccaac
xoxooo
acbbbc
ooxxxo
acccba
oxooxo
bcba
<1910183 bytes omitted>

Output file

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<195528 bytes omitted>

Your output

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<195500 bytes omitted>

System message

Exited with return code 0
Test case #25
Accepted
Score: 100
Time: 715 ms
Memory: 17388 KiB

Input file

99999 99994
baaabb
xxxoxx
ccbaca
ooxxoo
abcaba
xxoxxo
abcbba
oxoxxx
abcaab
xxooxx
aaaaac
xoxxxo
aaab
<2559863 bytes omitted>

Output file

4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4

<199888 bytes omitted>

Your output

4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4

<199860 bytes omitted>

System message

Exited with return code 0
Test case #26
Accepted
Score: 100
Time: 752 ms
Memory: 17764 KiB

Input file

99992 99995
caabba
oxxoxo
cccaab
oooxoo
bacbac
xoooxo
cbccbb
oxooox
acacab
xoxooo
cababb
oxxoxo
aaca
<2559852 bytes omitted>

Output file

5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5

<199890 bytes omitted>

Your output

5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5

<199862 bytes omitted>

System message

Exited with return code 0
Test case #27
Accepted
Score: 100
Time: 7 ms
Memory: 624 KiB

Input file

4 4
abcdee
xxxxox
abcdee
oxxxxx
abcdee
xxxxxx
aabcde
oxxxxx
1 1
2 2
3 3
4 4

Output file

6
1
6
6

Your output

6
1
6
6

System message

Exited with return code 0
Test case #28
Accepted
Score: 100
Time: 7 ms
Memory: 488 KiB

Input file

14 7
aaaaaa
oooooo
aabbcc
ooxxxx
aaaaaa
ooooox
aabbbb
ooxxox
aabbcc
oxoxoo
bbbbcc
xoxoxo
aabbcc
oooo
<134 bytes omitted>

Output file

6
6
-1
4
-1
-1
-1

Your output

6
6
-1
4
-1
-1
-1

System message

Exited with return code 0
Test case #29
Accepted
Score: 100
Time: 6 ms
Memory: 492 KiB

Input file

8 4
aaaaaa
ooooox
bcdeaa
xxxxoo
aaabbb
oooxxx
ccddee
xxxxxx
aaaaab
ooooox
ccddee
xxxxxx
aaaaab
ooooo
<32 bytes omitted>

Output file

6
3
5
6

Your output

6
3
5
6

System message

Exited with return code 0
Test case #30
Accepted
Score: 100
Time: 5 ms
Memory: 508 KiB

Input file

2 1
abcdef
oooooo
abcdee
oooooo
1 2

Output file

-1

Your output

-1

System message

Exited with return code 0
Test case #31
Accepted
Score: 100
Time: 7 ms
Memory: 500 KiB

Input file

1 1
abcdef
xxxxxx
1 1

Output file

-1

Your output

-1

System message

Exited with return code 0
Test case #32
Accepted
Score: 100
Time: 8 ms
Memory: 492 KiB

Input file

2 1
abcdef
xxxxxx
abcdef
xxxxxx
1 2

Output file

-1

Your output

-1

System message

Exited with return code 0
Subtask #6
Accepted
Score: 27
Test case #1
Accepted
Score: 100
Time: 6 ms
Memory: 504 KiB

Input file

2 2
aabbcc
oxoxox
dddeee
ooxxxx
1 1
1 2

Output file

3
6

Your output

3
6

System message

Exited with return code 0
Test case #2
Accepted
Score: 100
Time: 206 ms
Memory: 16712 KiB

Input file

84590 42147
aabbcb
ooxoxx
babbbc
xoxoxx
bbbabb
xoxoox
caaaca
xoxoxo
cbbaab
xxoooo
abcaac
ooxoox
acbc
<1678940 bytes omitted>

Output file

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

<84194 bytes omitted>

Your output

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

<84166 bytes omitted>

System message

Exited with return code 0
Test case #3
Accepted
Score: 100
Time: 74 ms
Memory: 16616 KiB

Input file

83386 7411
acbccb
xooxxo
aaacac
ooxoxx
babaca
ooooox
bcccab
oooxoo
aababb
xooxox
aabbbc
ooxooo
abbbc
<1254249 bytes omitted>

Output file

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

<14722 bytes omitted>

Your output

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

<14694 bytes omitted>

System message

Exited with return code 0
Test case #4
Accepted
Score: 100
Time: 391 ms
Memory: 17488 KiB

Input file

99997 100000
aaccbb
ooooox
caabac
ooxoxo
bbcbcc
oxoxoo
aabbcb
xoxooo
bbccaa
xoxoxo
bbbbcb
xxxxoo
bcc
<2578001 bytes omitted>

Output file

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

<199900 bytes omitted>

Your output

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

<199872 bytes omitted>

System message

Exited with return code 0
Test case #5
Accepted
Score: 100
Time: 394 ms
Memory: 17516 KiB

Input file

99999 99998
cacaca
oxooxo
abbcab
oxooox
ccbccc
xxooox
cbbbbb
ooxxox
cbcccc
xooxxo
bcaaca
oxooox
abac
<2578006 bytes omitted>

Output file

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4

<199896 bytes omitted>

Your output

3
4
5
4
4
3
5
5
4
3
4
4
3
4
3
3
5
5
4
3
5
3
5
5
3
4
5
4
5
4
5
3
4
4
4
5
4
5
5
4
2
4
5
3
4
4
4
5
5
4
5
2
5
4
2
4
5
5
4
3
5
4
4
4

<199868 bytes omitted>

System message

Exited with return code 0
Test case #6
Accepted
Score: 100
Time: 299 ms
Memory: 8428 KiB

Input file

36673 94424
fbefbf
xoxxox
cedcdf
xxoxox
cfcfba
xxxxxo
cbceda
xoxxoo
dadcda
oxoxox
eebaae
xxooxx
fded
<1589112 bytes omitted>

Output file

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

<188748 bytes omitted>

Your output

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

<188720 bytes omitted>

System message

Exited with return code 0
Test case #7
Accepted
Score: 100
Time: 140 ms
Memory: 8432 KiB

Input file

35469 26985
cbaeba
oxooxo
accfde
oxxooo
daebbf
oooxxo
bdddcf
xoxxoo
effaff
ooxoxx
acdfdc
oxxooo
aaba
<803588 bytes omitted>

Output file

5
4
5
3
2
2
4
3
4
4
4
2
3
4
4
5
3
4
3
2
2
3
4
4
4
3
4
5
4
2
5
3
4
3
3
5
4
4
3
3
3
3
5
3
3
3
3
4
3
2

<53870 bytes omitted>

Your output

5
4
5
3
2
2
4
3
4
4
4
2
3
4
4
5
3
4
3
2
2
3
4
4
4
3
4
5
4
2
5
3
4
3
3
5
4
4
3
3
3
3
5
3
3
3
3
4
3
2
4
4
4
3
4
3
3
2
3
2
4
3
3
4

<53842 bytes omitted>

System message

Exited with return code 0
Test case #8
Accepted
Score: 100
Time: 402 ms
Memory: 17108 KiB

Input file

88751 98586
aaacde
oxoxox
dcfdfc
oxxxxx
babdba
oooooo
fcedfe
xxxxxx
acffbb
oxxxoo
fecccd
xxxxxo
dacf
<2400756 bytes omitted>

Output file

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

<197072 bytes omitted>

Your output

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

<197044 bytes omitted>

System message

Exited with return code 0
Test case #9
Accepted
Score: 100
Time: 551 ms
Memory: 17512 KiB

Input file

99998 99997
fbcfcf
ooxxox
eccdde
xxxxoo
dfbcbe
ooxxoo
fffcaf
xoxxox
faacab
oxoxox
dafeaf
ooooxx
ccac
<2577652 bytes omitted>

Output file

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

<199894 bytes omitted>

Your output

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

<199866 bytes omitted>

System message

Exited with return code 0
Test case #10
Accepted
Score: 100
Time: 552 ms
Memory: 17648 KiB

Input file

99993 99997
fcbcea
xoooxo
edacfa
xoxoxo
bfccfd
oxooxo
cabbca
ooooxx
eacdee
xoooxx
dbcffa
oooxxo
ceae
<2577464 bytes omitted>

Output file

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

<199894 bytes omitted>

Your output

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

<199866 bytes omitted>

System message

Exited with return code 0
Test case #11
Accepted
Score: 100
Time: 42 ms
Memory: 4340 KiB

Input file

17541 11593
bbcaac
oxoxoo
ccabac
ooxooo
bcbacb
xoxooo
ccabba
oooxox
babaca
xxooox
cbacab
ooxoox
bcca
<369890 bytes omitted>

Output file

4
4
4
4
4
5
3
6
4
4
4
4
2
-1
5
4
5
3
2
2
2
1
-1
5
5
4
-1
4
6
5
-1
-1
5
-1
4
3
4
5
4
-1
5
-1
4
4
5
-1
<24894 bytes omitted>

Your output

4
4
4
4
4
5
3
6
4
4
4
4
2
-1
5
4
5
3
2
2
2
1
-1
5
5
4
-1
4
6
5
-1
-1
5
-1
4
3
4
5
4
-1
5
-1
4
4
5
-1
5
4
3
2
-1
-1
5
3
5
3
4
5
4
<24866 bytes omitted>

System message

Exited with return code 0
Test case #12
Accepted
Score: 100
Time: 371 ms
Memory: 17644 KiB

Input file

99997 99992
baaabc
oxxxoo
cbcbab
oxxoxo
bbbbcc
xxooox
abaabb
xoxxxo
abccca
xoxoxx
bbbaaa
oxoxxx
cbab
<2577694 bytes omitted>

Output file

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

<216400 bytes omitted>

Your output

1
-1
3
3
4
3
3
2
2
-1
3
3
3
2
3
2
3
4
-1
2
2
3
3
-1
3
-1
3
3
-1
2
4
-1
3
3
-1
3
1
0
1
4
3
2
3
1
3
2
4
4
2
2
2
3
3
1
2
-1
3
3
3
3
<216372 bytes omitted>

System message

Exited with return code 0
Test case #13
Accepted
Score: 100
Time: 436 ms
Memory: 17640 KiB

Input file

99998 99993
babbcc
oxxxox
bcbabb
xooxxx
ccccab
xxoxxo
bcbbcc
xxooox
bbbbba
oxoxxx
aaacab
xxxoxo
abcc
<2577579 bytes omitted>

Output file

2
3
2
2
2
2
-1
1
2
2
2
2
-1
2
2
2
-1
2
2
2
2
2
3
-1
2
2
3
1
2
-1
2
2
2
2
2
2
-1
3
2
2
2
2
3
2
1
-1
2
<217609 bytes omitted>

Your output

2
3
2
2
2
2
-1
1
2
2
2
2
-1
2
2
2
-1
2
2
2
2
2
3
-1
2
2
3
1
2
-1
2
2
2
2
2
2
-1
3
2
2
2
2
3
2
1
-1
2
2
2
2
1
2
2
2
2
-1
2
1
2
-1
<217581 bytes omitted>

System message

Exited with return code 0
Test case #14
Accepted
Score: 100
Time: 288 ms
Memory: 16300 KiB

Input file

70828 65903
cedfca
ooxooo
abbfba
oxxoxx
fddfad
xxxoox
bcbcbb
ooxoxx
ebcdce
oxoxox
fbeeff
xxxooo
aebf
<1761814 bytes omitted>

Output file

6
1
5
5
4
3
3
4
4
4
4
3
-1
4
4
-1
4
4
6
-1
5
3
2
-1
3
1
4
-1
1
4
5
5
3
2
3
4
4
3
4
3
-1
-1
2
4
5
3
3
<140089 bytes omitted>

Your output

6
1
5
5
4
3
3
4
4
4
4
3
-1
4
4
-1
4
4
6
-1
5
3
2
-1
3
1
4
-1
1
4
5
5
3
2
3
4
4
3
4
3
-1
-1
2
4
5
3
3
2
3
1
4
1
3
-1
3
-1
4
4
3
-
<140061 bytes omitted>

System message

Exited with return code 0
Test case #15
Accepted
Score: 100
Time: 176 ms
Memory: 16108 KiB

Input file

69624 31167
cafeab
ooxoxo
afabfa
oxxoxx
baefbe
oooxxo
dfacfe
xxooxo
cfaaca
oxoxxo
cbddad
xoxxox
dabb
<1338647 bytes omitted>

Output file

3
-1
5
4
6
4
5
-1
4
3
4
5
4
3
5
4
4
2
5
3
4
-1
4
2
4
4
1
3
4
3
6
-1
3
4
5
6
2
4
6
4
4
4
-1
5
5
3
4
3
<66198 bytes omitted>

Your output

3
-1
5
4
6
4
5
-1
4
3
4
5
4
3
5
4
4
2
5
3
4
-1
4
2
4
4
1
3
4
3
6
-1
3
4
5
6
2
4
6
4
4
4
-1
5
5
3
4
3
2
4
-1
-1
5
4
4
3
2
6
3
3
-
<66170 bytes omitted>

System message

Exited with return code 0
Test case #16
Accepted
Score: 100
Time: 497 ms
Memory: 17648 KiB

Input file

99998 99999
cbeacb
oxxoox
deceaa
oxoxoo
ecaeef
xooxxo
bafafd
xoxooo
fdbbfd
xxxxoo
cccece
oxxxox
ccdc
<2577321 bytes omitted>

Output file

3
4
2
5
-1
4
5
5
4
3
4
6
3
3
2
1
6
6
-1
-1
4
3
3
2
-1
4
-1
4
4
3
6
5
6
-1
-1
6
4
5
-1
3
-1
5
-1
4
3

<212373 bytes omitted>

Your output

3
4
2
5
-1
4
5
5
4
3
4
6
3
3
2
1
6
6
-1
-1
4
3
3
2
-1
4
-1
4
4
3
6
5
6
-1
-1
6
4
5
-1
3
-1
5
-1
4
3
5
3
4
-1
4
-1
3
-1
4
3
-1
-1
<212345 bytes omitted>

System message

Exited with return code 0
Test case #17
Accepted
Score: 100
Time: 451 ms
Memory: 17548 KiB

Input file

99999 99997
cbbebc
oxxxxo
babfee
xoxxox
feabdc
xxxxoo
caaded
ooooxx
facada
xooooo
baeafd
xoxoxo
efea
<2577655 bytes omitted>

Output file

5
3
3
1
2
1
3
6
5
4
-1
3
5
3
3
3
2
3
3
2
2
3
1
-1
3
3
3
6
-1
-1
4
1
2
2
2
4
2
2
3
3
3
4
3
3
-1
-1
4

<212453 bytes omitted>

Your output

5
3
3
1
2
1
3
6
5
4
-1
3
5
3
3
3
2
3
3
2
2
3
1
-1
3
3
3
6
-1
-1
4
1
2
2
2
4
2
2
3
3
3
4
3
3
-1
-1
4
3
6
3
3
-1
6
3
-1
2
3
4
4
3

<212425 bytes omitted>

System message

Exited with return code 0
Test case #18
Accepted
Score: 100
Time: 536 ms
Memory: 17904 KiB

Input file

99994 99994
fddbbd
ooxoxo
ffbced
xxoooo
afbcfb
xoxoxo
dffffc
oxxoxo
fdeceb
ooooxo
dfccff
ooxoxx
bdab
<2577440 bytes omitted>

Output file

4
5
5
2
5
5
6
-1
4
3
2
4
2
4
3
3
4
6
3
5
4
3
2
-1
5
-1
-1
5
4
5
3
4
4
5
5
6
4
5
6
5
4
5
3
-1
5
5
4
5
<213092 bytes omitted>

Your output

4
5
5
2
5
5
6
-1
4
3
2
4
2
4
3
3
4
6
3
5
4
3
2
-1
5
-1
-1
5
4
5
3
4
4
5
5
6
4
5
6
5
4
5
3
-1
5
5
4
5
6
6
5
6
2
3
3
5
4
5
3
4
4
3
<213064 bytes omitted>

System message

Exited with return code 0
Test case #19
Accepted
Score: 100
Time: 527 ms
Memory: 17616 KiB

Input file

99999 99991
ffeafe
xxxoox
ddfccc
oxoxxo
becbbe
oxooox
cabbeb
ooxoxo
ccfabb
oxooox
bdbdbc
ooxxoo
ceba
<2577761 bytes omitted>

Output file

1
6
4
2
3
4
5
2
3
5
3
5
4
4
5
4
6
3
6
4
5
5
5
3
5
4
-1
5
3
-1
5
4
-1
6
6
3
4
5
2
-1
6
4
4
6
6
5
4
3

<213061 bytes omitted>

Your output

1
6
4
2
3
4
5
2
3
5
3
5
4
4
5
4
6
3
6
4
5
5
5
3
5
4
-1
5
3
-1
5
4
-1
6
6
3
4
5
2
-1
6
4
4
6
6
5
4
3
5
4
4
-1
5
5
2
5
4
4
3
4
6
3
<213033 bytes omitted>

System message

Exited with return code 0
Test case #20
Accepted
Score: 100
Time: 150 ms
Memory: 8788 KiB

Input file

42234 34548
baaaac
ooxxxx
abcbca
xoxoxo
acbcaa
xxoxxo
bacccc
ooxxxx
bccaba
oxxxoo
bcaaac
oxoxxx
abbc
<987843 bytes omitted>

Output file

-1
3
-1
3
3
3
3
-1
3
3
3
3
3
3
-1
3
-1
-1
3
-1
3
3
-1
3
3
3
3
3
3
-1
3
3
3
3
3
-1
3
3
-1
3
3
3
3
-1

<82054 bytes omitted>

Your output

-1
3
-1
3
3
3
3
-1
3
3
3
3
3
3
-1
3
-1
-1
3
-1
3
3
-1
3
3
3
3
3
3
-1
3
3
3
3
3
-1
3
3
-1
3
3
3
3
-1
3
3
3
-1
3
3
3
-1
3
3
-1
2
3
<82026 bytes omitted>

System message

Exited with return code 0
Test case #21
Accepted
Score: 100
Time: 86 ms
Memory: 17008 KiB

Input file

90012 9353
bbbbcc
xxxxoo
bbcbcb
xxoxox
abbaba
oxxxxo
bcbbac
xoxxoo
ccbacb
ooxoxx
babccc
xoxxoo
cccbc
<1369973 bytes omitted>

Output file

-1
4
-1
4
4
4
-1
-1
4
4
-1
-1
4
4
3
-1
4
4
4
4
-1
4
4
4
4
-1
4
4
4
-1
4
4
4
4
4
-1
-1
-1
4
-1
4
4
4

<22008 bytes omitted>

Your output

-1
4
-1
4
4
4
-1
-1
4
4
-1
-1
4
4
3
-1
4
4
4
4
-1
4
4
4
4
-1
4
4
4
-1
4
4
4
4
4
-1
-1
-1
4
-1
4
4
4
4
4
4
4
-1
4
-1
-1
-1
4
-1
4
<21980 bytes omitted>

System message

Exited with return code 0
Test case #22
Accepted
Score: 100
Time: 423 ms
Memory: 17484 KiB

Input file

99995 99992
bbbccc
xxxooo
acbcbc
ooxoxo
cbabca
oxoxoo
abcbca
oxoxoo
aaaabc
xxooxo
bbccbb
xxooxx
abca
<2577796 bytes omitted>

Output file

5
5
5
-1
-1
5
5
5
5
4
-1
-1
-1
5
5
-1
5
-1
5
5
5
-1
-1
4
5
5
5
5
-1
5
5
-1
-1
5
5
5
-1
5
5
-1
5
5
-1
<239463 bytes omitted>

Your output

5
5
5
-1
-1
5
5
5
5
4
-1
-1
-1
5
5
-1
5
-1
5
5
5
-1
-1
4
5
5
5
5
-1
5
5
-1
-1
5
5
5
-1
5
5
-1
5
5
-1
5
5
-1
5
5
5
5
-1
-1
-1
-1

<239435 bytes omitted>

System message

Exited with return code 0
Test case #23
Accepted
Score: 100
Time: 495 ms
Memory: 16720 KiB

Input file

73896 69983
caccbc
xoxoox
aabaaa
xoooxo
ccbaaa
xooooo
bacaab
xooooo
acbbac
oooxox
cbccab
xooxox
cbca
<1839239 bytes omitted>

Output file

5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5

<139866 bytes omitted>

Your output

5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5

<139838 bytes omitted>

System message

Exited with return code 0
Test case #24
Accepted
Score: 100
Time: 468 ms
Memory: 9308 KiB

Input file

56804 97814
aacaca
oooooo
bcaacb
xoooox
cacbcc
xooxxo
bccaac
xoxooo
acbbbc
ooxxxo
acccba
oxooxo
bcba
<1910183 bytes omitted>

Output file

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<195528 bytes omitted>

Your output

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<195500 bytes omitted>

System message

Exited with return code 0
Test case #25
Accepted
Score: 100
Time: 715 ms
Memory: 17388 KiB

Input file

99999 99994
baaabb
xxxoxx
ccbaca
ooxxoo
abcaba
xxoxxo
abcbba
oxoxxx
abcaab
xxooxx
aaaaac
xoxxxo
aaab
<2559863 bytes omitted>

Output file

4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4

<199888 bytes omitted>

Your output

4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4

<199860 bytes omitted>

System message

Exited with return code 0
Test case #26
Accepted
Score: 100
Time: 752 ms
Memory: 17764 KiB

Input file

99992 99995
caabba
oxxoxo
cccaab
oooxoo
bacbac
xoooxo
cbccbb
oxooox
acacab
xoxooo
cababb
oxxoxo
aaca
<2559852 bytes omitted>

Output file

5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5

<199890 bytes omitted>

Your output

5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5

<199862 bytes omitted>

System message

Exited with return code 0
Test case #27
Accepted
Score: 100
Time: 96 ms
Memory: 17008 KiB

Input file

91025 9592
edefaa
ooooox
ccdcfb
xxoxox
fbeeba
oxooxo
acbacd
xxxoxo
bcedde
xxoxoo
fbdccd
oxxxxo
ccddd
<1387111 bytes omitted>

Output file

6
6
6
-1
6
6
-1
6
-1
6
6
6
6
-1
6
6
-1
-1
-1
6
6
6
6
-1
-1
6
6
-1
6
6
6
6
6
6
-1
6
6
4
-1
6
6
6
-1
6
<22717 bytes omitted>

Your output

6
6
6
-1
6
6
-1
6
-1
6
6
6
6
-1
6
6
-1
-1
-1
6
6
6
6
-1
-1
6
6
-1
6
6
6
6
6
6
-1
6
6
4
-1
6
6
6
-1
6
-1
6
6
-1
6
6
6
6
6
6
6
-1

<22689 bytes omitted>

System message

Exited with return code 0
Test case #28
Accepted
Score: 100
Time: 349 ms
Memory: 8548 KiB

Input file

38802 92909
fadfbf
oxoxxo
adebca
xooxxx
adbedb
xxxoox
cbbdfc
xxxoox
eadcba
oxoxxx
dedbce
ooxxxo
fbaf
<1605521 bytes omitted>

Output file

-1
-1
-1
5
6
6
6
-1
-1
-1
6
6
6
-1
5
-1
6
6
6
4
6
6
-1
-1
1
2
6
-1
4
6
-1
-1
-1
6
-1
6
6
4
6
6
-1
6

<220162 bytes omitted>

Your output

-1
-1
-1
5
6
6
6
-1
-1
-1
6
6
6
-1
5
-1
6
6
6
4
6
6
-1
-1
1
2
6
-1
4
6
-1
-1
-1
6
-1
6
6
4
6
6
-1
6
6
-1
3
6
2
6
-1
-1
6
6
6
-1

<220134 bytes omitted>

System message

Exited with return code 0
Test case #29
Accepted
Score: 100
Time: 504 ms
Memory: 17516 KiB

Input file

99999 99992
ffffba
xxxoxx
dfbcdf
oxxoxo
edeceb
xoooox
eaddef
oxoxoo
cbeabb
oxoxxx
ceabca
ooxxox
cbba
<2577947 bytes omitted>

Output file

-1
6
6
-1
6
6
-1
-1
-1
6
-1
6
6
6
6
6
6
4
-1
-1
-1
6
-1
-1
6
6
-1
6
6
6
6
6
4
6
6
6
-1
6
-1
6
6
-1
4
<237903 bytes omitted>

Your output

-1
6
6
-1
6
6
-1
-1
-1
6
-1
6
6
6
6
6
6
4
-1
-1
-1
6
-1
-1
6
6
-1
6
6
6
6
6
4
6
6
6
-1
6
-1
6
6
-1
4
6
-1
-1
-1
-1
-1
6
6
6
-1
3
<237875 bytes omitted>

System message

Exited with return code 0
Test case #30
Accepted
Score: 100
Time: 171 ms
Memory: 4848 KiB

Input file

26338 39260
aefadc
xooxxo
edefef
oxxoxo
dcecce
xoxooo
dffeff
xxooxo
bedaed
xoxxxx
cadbfc
oxxxoo
fdaa
<799668 bytes omitted>

Output file

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<78420 bytes omitted>

Your output

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<78392 bytes omitted>

System message

Exited with return code 0
Test case #31
Accepted
Score: 100
Time: 333 ms
Memory: 9064 KiB

Input file

52350 67092
effaad
oxooox
cddbcf
xxxooo
eeffdd
oxxoxx
abaeda
ooooxx
acfbae
oooooo
acefcc
ooooxx
cebc
<1495122 bytes omitted>

Output file

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<134084 bytes omitted>

Your output

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<134056 bytes omitted>

System message

Exited with return code 0
Test case #32
Accepted
Score: 100
Time: 695 ms
Memory: 17388 KiB

Input file

99993 99992
becdca
ooooxo
ebaebf
xoooxo
bbfefa
xoooxo
abdeea
xooxoo
deaddc
xooxoo
cdafad
oxooxo
acef
<2559531 bytes omitted>

Output file

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<199884 bytes omitted>

Your output

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<199856 bytes omitted>

System message

Exited with return code 0
Test case #33
Accepted
Score: 100
Time: 611 ms
Memory: 17512 KiB

Input file

99993 99993
ffbadd
ooxxxo
cbbacf
xxxxxo
dabbde
oxxxxo
edcded
oxxxoo
fcceda
oxxoox
bdcdcb
xoxxxx
defb
<2559890 bytes omitted>

Output file

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<199886 bytes omitted>

Your output

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6

<199858 bytes omitted>

System message

Exited with return code 0
Test case #34
Accepted
Score: 100
Time: 7 ms
Memory: 624 KiB

Input file

4 4
abcdee
xxxxox
abcdee
oxxxxx
abcdee
xxxxxx
aabcde
oxxxxx
1 1
2 2
3 3
4 4

Output file

6
1
6
6

Your output

6
1
6
6

System message

Exited with return code 0
Test case #35
Accepted
Score: 100
Time: 7 ms
Memory: 488 KiB

Input file

14 7
aaaaaa
oooooo
aabbcc
ooxxxx
aaaaaa
ooooox
aabbbb
ooxxox
aabbcc
oxoxoo
bbbbcc
xoxoxo
aabbcc
oooo
<134 bytes omitted>

Output file

6
6
-1
4
-1
-1
-1

Your output

6
6
-1
4
-1
-1
-1

System message

Exited with return code 0
Test case #36
Accepted
Score: 100
Time: 6 ms
Memory: 492 KiB

Input file

8 4
aaaaaa
ooooox
bcdeaa
xxxxoo
aaabbb
oooxxx
ccddee
xxxxxx
aaaaab
ooooox
ccddee
xxxxxx
aaaaab
ooooo
<32 bytes omitted>

Output file

6
3
5
6

Your output

6
3
5
6

System message

Exited with return code 0
Test case #37
Accepted
Score: 100
Time: 5 ms
Memory: 508 KiB

Input file

2 1
abcdef
oooooo
abcdee
oooooo
1 2

Output file

-1

Your output

-1

System message

Exited with return code 0
Test case #38
Accepted
Score: 100
Time: 7 ms
Memory: 500 KiB

Input file

1 1
abcdef
xxxxxx
1 1

Output file

-1

Your output

-1

System message

Exited with return code 0
Test case #39
Accepted
Score: 100
Time: 8 ms
Memory: 492 KiB

Input file

2 1
abcdef
xxxxxx
abcdef
xxxxxx
1 2

Output file

-1

Your output

-1

System message

Exited with return code 0