Submission ID Problem Status Score Time Memory Code / Answer files User Submit time
#18389 #59. 猜字母王 Hexguesser Accepted 100 20473 ms 17956 K C++ 17 / 3.3 K HKSCF2023-050 2023-07-15 15:44:42
Show orginal code
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second

struct node {
    int lc, rc;
    int know[6];
    int less[6];
    bool nomore[6];
};

struct info {
    int know[6];
    int less[6];
    bool nomore[6];
};

const int MaxN = 1e5 + 10;  // CHANGE THIS BEFORE SUBMISSION
int cnid = 0;
pair<string, string> dataa[MaxN];
node segtree[4 * MaxN];  // wtf why am i writing segtree lmao

int build(int l, int r) {
    int id = cnid;
    cnid++;
    if (l == r) {
        for (int i = 0; i < 6; i++) {
            if (dataa[l].ss[i] == 'o') {
                segtree[id].know[dataa[l].ff[i] - 'a']++;
            } else {
                segtree[id].nomore[dataa[l].ff[i] - 'a'] = 1;
            }
        }
        for (int i = 0; i < 6; i++) {
            if (segtree[id].nomore[i])
                segtree[id].less[i] = segtree[id].know[i];
            else
                segtree[id].less[i] = 10;
        }
        return id;
    }
    segtree[id].lc = build(l, (l + r) / 2);
    segtree[id].rc = build((l + r) / 2 + 1, r);
    for (int i = 0; i < 6; i++) {
        segtree[id].know[i] = max(segtree[segtree[id].lc].know[i], segtree[segtree[id].rc].know[i]);
        segtree[id].nomore[i] = (segtree[segtree[id].lc].nomore[i] | segtree[segtree[id].rc].nomore[i]);
        segtree[id].less[i] = min(segtree[segtree[id].lc].less[i], segtree[segtree[id].rc].less[i]);
    }
    return id;
}

info get(int l, int r, int lb, int rb, int cur) {
    info rtn;
    if (lb == rb) {
        for (int i = 0; i < 6; i++) {
            rtn.know[i] = segtree[cur].know[i];
            rtn.nomore[i] = segtree[cur].nomore[i];
            rtn.less[i] = segtree[cur].less[i];
        }
        return rtn;
    } else if (l == lb && r == rb) {
        for (int i = 0; i < 6; i++) {
            rtn.know[i] = segtree[cur].know[i];
            rtn.nomore[i] = segtree[cur].nomore[i];
            rtn.less[i] = segtree[cur].less[i];
        }
        return rtn;
    } else {
        bool left = 0, right = 0;
        info li, ri;
        if (l <= (lb + rb) / 2) {
            left = 1;
            li = get(l, min(r, (lb + rb) / 2), lb, (lb + rb) / 2, segtree[cur].lc);
        }
        if (r > (lb + rb) / 2) {
            right = 1;
            ri = get(max(l, (lb + rb) / 2 + 1), r, (lb + rb) / 2 + 1, rb, segtree[cur].rc);
        }
        if (left && right) {
            for (int i = 0; i < 6; i++) {
                rtn.know[i] = max(li.know[i], ri.know[i]);
                rtn.less[i] = min(li.less[i], ri.less[i]);
                rtn.nomore[i] = (li.nomore[i] | ri.nomore[i]);
            }
            return rtn;
        } else if (left)
            return li;
        else if (right)
            return ri;
        else
            cout << "shit\n";
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        cin >> dataa[i].ff >> dataa[i].ss;
    }
    build(0, n - 1);
    int l, r;
    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        info rtn = get(l - 1, r - 1, 0, n - 1, 0);
        int known = 0, rem = 6;
        bool makesSense = 1;
        for (int j = 0; j < 6; j++) {
            known += rtn.know[j];
            rem -= rtn.nomore[j];
            if (rtn.nomore[j] && (rtn.less[j] < rtn.know[j]))
                makesSense = 0;
        }
        if (!makesSense)
            cout << "-1\n";
        else if (known > 6)
            cout << "-1\n";
        else if (known == 6)
            cout << "6\n";
        else if (rem == 0)
            cout << "-1\n";
        else if (rem == 1)
            cout << "6\n";
        else
            cout << known << endl;
    }
}
Subtask #1
Accepted
Score: 8
Test case #1
Accepted
Score: 100
Time: 139 ms
Memory: 15700 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: 72 ms
Memory: 15688 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: 123 ms
Memory: 15344 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: 252 ms
Memory: 17512 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: 270 ms
Memory: 17740 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: 139 ms
Memory: 15700 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: 72 ms
Memory: 15688 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: 252 ms
Memory: 17512 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: 270 ms
Memory: 17740 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: 215 ms
Memory: 9824 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: 74 ms
Memory: 9576 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: 247 ms
Memory: 16232 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: 261 ms
Memory: 17776 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: 289 ms
Memory: 17632 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: 10 ms
Memory: 5100 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: 14 ms
Memory: 4968 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: 139 ms
Memory: 15700 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: 72 ms
Memory: 15688 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: 252 ms
Memory: 17512 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: 270 ms
Memory: 17740 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: 215 ms
Memory: 9824 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: 45 ms
Memory: 7276 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: 248 ms
Memory: 17616 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: 247 ms
Memory: 17632 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: 13 ms
Memory: 4980 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: 11 ms
Memory: 4980 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: 139 ms
Memory: 15700 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: 72 ms
Memory: 15688 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: 252 ms
Memory: 17512 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: 270 ms
Memory: 17740 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: 215 ms
Memory: 9824 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: 74 ms
Memory: 9576 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: 247 ms
Memory: 16232 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: 261 ms
Memory: 17776 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: 289 ms
Memory: 17632 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: 45 ms
Memory: 7276 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: 248 ms
Memory: 17616 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: 247 ms
Memory: 17632 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: 203 ms
Memory: 14212 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: 108 ms
Memory: 13800 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: 278 ms
Memory: 17876 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: 284 ms
Memory: 17956 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: 274 ms
Memory: 17768 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: 275 ms
Memory: 17864 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: 10 ms
Memory: 5100 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: 13 ms
Memory: 4980 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: 15 ms
Memory: 5348 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: 14 ms
Memory: 5400 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: 14 ms
Memory: 4968 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: 14 ms
Memory: 5180 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: 11 ms
Memory: 4980 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: 139 ms
Memory: 15700 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: 72 ms
Memory: 15688 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: 252 ms
Memory: 17512 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: 270 ms
Memory: 17740 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: 215 ms
Memory: 9824 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: 74 ms
Memory: 9576 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: 247 ms
Memory: 16232 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: 261 ms
Memory: 17776 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: 289 ms
Memory: 17632 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: 45 ms
Memory: 7276 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: 248 ms
Memory: 17616 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: 247 ms
Memory: 17632 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: 203 ms
Memory: 14212 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: 108 ms
Memory: 13800 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: 278 ms
Memory: 17876 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: 284 ms
Memory: 17956 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: 274 ms
Memory: 17768 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: 275 ms
Memory: 17864 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: 107 ms
Memory: 10480 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: 81 ms
Memory: 16336 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: 305 ms
Memory: 17644 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: 219 ms
Memory: 14440 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: 255 ms
Memory: 12140 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: 305 ms
Memory: 17516 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: 324 ms
Memory: 17648 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: 10 ms
Memory: 5100 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: 13 ms
Memory: 4980 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: 15 ms
Memory: 5348 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: 14 ms
Memory: 5400 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: 14 ms
Memory: 4968 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: 14 ms
Memory: 5180 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: 11 ms
Memory: 4980 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: 139 ms
Memory: 15700 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: 72 ms
Memory: 15688 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: 252 ms
Memory: 17512 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: 270 ms
Memory: 17740 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: 215 ms
Memory: 9824 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: 74 ms
Memory: 9576 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: 247 ms
Memory: 16232 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: 261 ms
Memory: 17776 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: 289 ms
Memory: 17632 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: 45 ms
Memory: 7276 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: 248 ms
Memory: 17616 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: 247 ms
Memory: 17632 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: 203 ms
Memory: 14212 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: 108 ms
Memory: 13800 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: 278 ms
Memory: 17876 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: 284 ms
Memory: 17956 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: 274 ms
Memory: 17768 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: 275 ms
Memory: 17864 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: 107 ms
Memory: 10480 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: 81 ms
Memory: 16336 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: 305 ms
Memory: 17644 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: 219 ms
Memory: 14440 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: 255 ms
Memory: 12140 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: 305 ms
Memory: 17516 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: 324 ms
Memory: 17648 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: 93 ms
Memory: 16484 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: 198 ms
Memory: 9964 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: 276 ms
Memory: 17644 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: 109 ms
Memory: 8428 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: 174 ms
Memory: 11496 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: 292 ms
Memory: 17516 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: 323 ms
Memory: 17644 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: 10 ms
Memory: 5100 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: 13 ms
Memory: 4980 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: 15 ms
Memory: 5348 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: 14 ms
Memory: 5400 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: 14 ms
Memory: 4968 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: 14 ms
Memory: 5180 KiB

Input file

2 1
abcdef
xxxxxx
abcdef
xxxxxx
1 2

Output file

-1

Your output

-1

System message

Exited with return code 0