QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#833856#8114. Labirintxiaowuc170 ✓6ms4872kbC++174.5kb2024-12-27 03:58:452024-12-27 03:58:50

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 11
Accepted

Test #1:

score: 11
Accepted
time: 1ms
memory: 3644kb

input:

1 100
NPPPZNNPCPCNZNZNZPZZPPPNPCPNPZCPCPCNNCZZPPCPPZPNPNCZCPZNZNPPZNPPZZNPPNCNPZZPZPZZNPCPNNZNNPCNCPZPCNN
100
1 55 1 37
1 52 1 64
1 36 1 4
1 68 1 66
1 50 1 80
1 84 1 77
1 99 1 68
1 84 1 56
1 5 1 95
1 38 1 68
1 82 1 3
1 64 1 36
1 61 1 21
1 1 1 4
1 2 1 46
1 55 1 100
1 4 1 83
1 53 1 96
1 76 1 43
1 21 1...

output:

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

result:

ok 100 lines

Test #2:

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

input:

1 100
NPNPZPCZZPPCCNCZNPPCCZNNPPPZCCCCPZZPCZPZPPPPNCPCZPCPZZZPCCZZCPPCCNPNCZCNZPCNZNCCPZZZZZZCNZCNNPNPZCC
100
1 36 1 54
1 36 1 56
1 35 1 3
1 21 1 96
1 18 1 37
1 55 1 86
1 90 1 91
1 90 1 99
1 17 1 42
1 53 1 72
1 5 1 61
1 91 1 29
1 69 1 62
1 78 1 53
1 36 1 47
1 37 1 16
1 90 1 14
1 83 1 15
1 7 1 48
1 4...

output:

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

result:

ok 100 lines

Test #3:

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

input:

1 100
CCPCPPZNNNZPZNCCCPPZNCCCPPPPCNNPZZCCCZCNPZNCNPZCNPNPNNCNPCZPNNCZZZPCNZNPCPZCPNZZZPNCNNZNNNNPNNZCNPN
100
1 81 1 78
1 80 1 50
1 32 1 94
1 100 1 50
1 27 1 25
1 47 1 94
1 52 1 20
1 21 1 72
1 38 1 28
1 3 1 33
1 20 1 33
1 60 1 78
1 62 1 34
1 48 1 49
1 91 1 36
1 94 1 36
1 15 1 55
1 20 1 98
1 81 1 97
...

output:

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

result:

ok 100 lines

Test #4:

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

input:

1 100
NNPNNCCZPPCNCCPCCPZCCPZZCZZCPNNNNCNPCNCNCCPCCZPZPPZZPZCPZPZCCCZNCZCNZCCCZCNCCZPPPPCZNNCPNZNZNNCCNPZ
100
1 99 1 21
1 71 1 64
1 13 1 25
1 20 1 94
1 84 1 20
1 29 1 22
1 79 1 34
1 28 1 46
1 87 1 59
1 3 1 64
1 54 1 69
1 63 1 47
1 33 1 59
1 94 1 100
1 99 1 18
1 88 1 30
1 21 1 56
1 30 1 26
1 49 1 92
...

output:

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

result:

ok 100 lines

Test #5:

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

input:

1 100
ZCNPNPNCZPPNZZNPNNCPNZNPPPZNNZZPNNPCZNNNNNPZZPPZNCNCNPPZCNNPNPCPNCNCCNNZPZNCPPZCCPCZCCNPPCCPCZZCZZZ
100
1 9 1 55
1 80 1 51
1 97 1 85
1 74 1 92
1 68 1 24
1 73 1 97
1 2 1 82
1 18 1 94
1 70 1 94
1 74 1 8
1 11 1 91
1 9 1 8
1 58 1 85
1 55 1 74
1 28 1 75
1 74 1 63
1 35 1 67
1 77 1 59
1 97 1 32
1 63 ...

output:

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

result:

ok 100 lines

Test #6:

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

input:

1 100
PCPNNNPNCPZNNZCPZZPCCNZPPCNZNPZPPPCZPNCZPCNPCCZPZCNCZCNCNZPNCZCNPZPPNCNCZNPCNZNNZCPNCZNNNPZNZPCPPCC
100
1 11 1 34
1 70 1 64
1 1 1 82
1 95 1 96
1 42 1 85
1 27 1 18
1 87 1 48
1 59 1 9
1 30 1 26
1 22 1 58
1 43 1 72
1 33 1 29
1 89 1 60
1 99 1 89
1 55 1 24
1 18 1 9
1 26 1 54
1 57 1 18
1 30 1 37
1 6...

output:

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

result:

ok 100 lines

Subtask #2:

score: 13
Accepted

Test #7:

score: 13
Accepted
time: 2ms
memory: 4532kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
2
2
1
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #8:

score: 13
Accepted
time: 2ms
memory: 4740kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #9:

score: 13
Accepted
time: 2ms
memory: 4728kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #10:

score: 13
Accepted
time: 0ms
memory: 4660kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #11:

score: 13
Accepted
time: 0ms
memory: 4708kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #12:

score: 13
Accepted
time: 2ms
memory: 4872kb

input:

100 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...

output:

2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #13:

score: 13
Accepted
time: 0ms
memory: 3540kb

input:

100 2
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
CC
C...

output:

1
1
1
1
1
2
1
1
1
2
1
1
2
1
1
1
2
1
1
2
2
2
1
2
2
2
2
2
2
1
2
2
1
1
2
2
1
1
1
2
1
2
1
2
1
2
1
2
2
2
2
1
1
1
1
1
1
1
1
2
1
1
1
2
2
2
1
2
1
1
1
1
2
1
1
1
2
1
1
1
1
1
2
1
1
2
1
1
2
1
2
2
2
2
1
1
1
2
2
1

result:

ok 100 lines

Test #14:

score: 13
Accepted
time: 1ms
memory: 3736kb

input:

10 100
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP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
2
2
2
1
1
2
2
2
2
1
2
2
2
1
2
1
2
2
2
2
1
2
2
1
2
1
2

result:

ok 100 lines

Test #18:

score: 24
Accepted
time: 4ms
memory: 4648kb

input:

100 100
PPPPPPCPCCPPCCCPPCCCPCPPCCCPPPPPCPCPCCCPCCCPPPCPCPPPCPPPCCPPCCPCPCPCCPCPCCPPPCPPCCCPCPPCCCCCPCPPPCC
PCCPCPCPPCCCCPCPPCCCCCCCCCCPPPCPCCCPCPCCCCPPCCCCCCPPPCPCCCPCPPPPPPCPCCPPCPCCCPPCPCCCPPPPCPCPCCPPCCC
PCCPCCCPCCPPCPCCCPCPCPPCCCPCCPPCPPPCCCCCCCPPPPPCCCCPPCPPCPPPCCCCCPPPCPCCPPCCCCCPCPPCPCCPPPCC...

output:

2
1
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
1
2
2
2
2
1
1
1
2
2
2
2
2
2
1
2
2
2
2
1
1
1
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #19:

score: 24
Accepted
time: 4ms
memory: 4748kb

input:

100 100
PCCCCPPPPPPPPPPCCPPPCCPCPPPPPPPCPPCPPCCCPCPCPPPCPPPPCPPCPCPPPCCPPPCPPPPCPCPPPPPPPCCPPCCPPCCCPPPPCCC
PCCPCPPCPCCCCPCCCCCPCPPCPPCPCPPPCPPCPCPCPPCCCPCCPPPCPPCCCPPCCPCPPCPCCPPCCPCCPPCCPPCCPPCPCPCPPPCPCCC
CCPCCPCCPCPCCPPPPCPCCPCCPPCPCCCCPCPPPPCPCCPPCPCCCCPPPCCPPPCCPCPCCPCPPPCPCPCPCCPPPPCPPCCPPCPP...

output:

2
2
2
2
2
2
1
2
2
2
2
2
2
2
1
2
1
2
2
2
2
2
1
2
1
2
2
1
1
2
2
2
2
2
2
1
1
1
1
2
1
1
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
1
1
2
2
2
2
2
1
2
2
2
2
2
1
2
2
2
2
2
2
1
1
2
1
1
2
1
1
2
2
2
2
2
1
2
2
1
1
2
1
2
2
2

result:

ok 100 lines

Test #20:

score: 24
Accepted
time: 4ms
memory: 4660kb

input:

100 100
CCCCPPCPPPPPCCCCPCCCPCPPCPCPPPCPCPCCCCCCPPCPCPPCPPCCCPPPPCCCCPCPPPCCCCPPPPCPPPCCPCPPPCCPPPPPPPPCPCP
CPPPCPPCCCPPPPPCCPCCCCCCCPCCPPPCCCCPPCPPCCCPPCPCCCPPCPPCCPCCCCCPPCCCPCPPCPCPCCPPCCCPCCCPCCPPCCCPPPP
CCPCPCCCCPPPCPPPCPCCPPCPCPPCCCPPPPCCCCPPCCPCPPPPPCCCPCCCCPPPPPCCPCPPCPPCPPCCPCCCCCPCCPPPCCPP...

output:

2
2
1
2
2
2
1
2
1
2
1
1
2
1
1
2
1
2
2
2
2
2
1
2
1
1
2
2
2
1
1
2
1
2
2
2
2
1
2
2
1
1
2
2
2
1
2
1
2
1
2
1
1
2
1
2
1
2
1
1
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
1
1
2
2
1
2
2
2
2
1
1
2
2
1
2
2
2
2
1
2
2
1
1
2
2

result:

ok 100 lines

Test #21:

score: 24
Accepted
time: 2ms
memory: 4692kb

input:

100 100
PCCCPCPCPCPCCPPPPCCPPCPPPPPCPPCPPPPPCCCCCPPPPCCCCPCCCPCCPCPPCCCPPPPCPCCCPCCCCPCCCPCCCPCPPCPCCPPCPPP
PPCPCPCCCCCPPCCCPCPPPCPPCPCCCPCCPCPPCCPPCPCCCCCPCCPCPPCCCCPPCCCPPCPCCCCCPPPCPCCCCPPCCCCPCPPCPPCPCCP
PCPCCCCCPCCPCCCCPPPCPCCPCCCCCPPCPCPPPPPPPPCPCPPCCPCCCPPPCPPCCCPCPPCPCPPPPCPPCPPPPCPPPCCCPCCC...

output:

2
1
1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CCPCCPPCP
CPCPPPPCP
PPPCPPPCC
CPPPCCPPC
PCCCPPCCP
CPCPPPPCP
CCC...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
1
2
2
2
2
2
1
2
2
2
2
1
2
2
1
2
2
2
1
2
2
2
1
2
2
1
2
2
1
2
2
2
2
1
2
1
1
2
2
2
2
2
1
2
2
1
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 100 lines

Test #24:

score: 24
Accepted
time: 1ms
memory: 3704kb

input:

10 100
PCPCCCCPCPPCCCCPCPPCCCPPCPPCPPPPPCCPPCPCPCPPPCPPPCCCPCPPPPCPPPCPCCCPCCPPCPPCCPCPCCCCPCPCPCCCCCCPPPP
PPPCPPCPPCPCPPPCPPPPPPPPPCCCPPPCCCCPCCCCPPCPPPCCCPPPCPCCCPCPPPPCPCCCCPPPPCCCCPPCCCCCPPPPPPCPCPPPPPC
CCCCPCPCPPPCCCPCPPCPCPPPCPCCCPCPCCPPCCPCPCCCPCCCPPPCCPCPCPPCCCPCCPCPPCPCPCPPCPCPCPCPCCCPCCPCC...

output:

2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
1
2
2
2
2
2
2
1
1
2
2
1
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
1
2
2
2
2
2
1
2
2
2
2
2
2
1
2
2
2
2
2
2
2
1
2
1
1
2
2
2
1
2
2
2
2
2
2
2

result:

ok 100 lines

Subtask #4:

score: 22
Accepted

Test #25:

score: 22
Accepted
time: 2ms
memory: 4724kb

input:

100 100
PZCZZZNPZPZPCCCCPNPZCCZZPPPPNCPZNPZPPNZNCPCNPCNCZZNCCZPZPPPZZZCZCZNPZPNZZZPPZPPZZPCPCZPNNCZZCPCNNNZ
NCZZPPCZNZNNNNNNPPNNCPZCZNNPNCCPZZZCZNPZZZNCCNNZPPCPZNPCPCZCZPZCCPPPCZPZCCPNNNNZZZZCZZNZNZPPZPCNZPC
PCCNZCCZZPZPPNZZNPCCNNZPCNPPZZNCPZNZPCZZPPCCCCNNZZCCNPPZNZNZZZNNNNZZNCNCCCNZPCZCPPZPCPCPZNPP...

output:

3
2
3
3
3
2
2
3
2
2
2
3
2
3
2
2
2
2
3
3
3
3
2
3
2
3
2
3
2
2
2
3
2
3
2
2
2
2
2
2
3
2
2
2
2
2
3
2
2
2
2
3
2
2
2
3
2
2
2
3
3
2
2
2
2
2
2
2
3
2
3
2
2
2
2
2
2
3
2
2
3
3
3
2
2
3
2
2
2
3
2
2
2
2
2
2
2
2
3
3

result:

ok 100 lines

Test #26:

score: 22
Accepted
time: 6ms
memory: 4724kb

input:

100 100
CCPNZPZCNNCNPCZPCPNCNNCZZCNPNCCZCCCPZCCPPNPCPZZPPZNNCPZPPZZPZCZNNPZCNPNPZPCCZCNZNCCCZZPZCZNPCCCZNPP
CZCPZZNCZZPNNCNZZCZZNNNNNZNCZZPCNNPNCPCZCZCCZPPCNPNPPNCPZZCNPZCZZCZZZNPZPCPCCCZPNPCCNNPCNPNNPPZCCPN
CCCCZPPNPNNCNPZCZCPPNCCNZPPNCNZNZNNPNZZPZCNZPZCNNPPZPNZPNZZCCPZCCZZZPPCZZZCZZCZNZCZCNCNPZPZC...

output:

3
2
2
2
3
2
2
2
3
2
2
2
2
2
3
2
3
2
2
2
3
3
2
2
3
3
2
2
2
2
3
3
2
2
2
2
2
2
2
3
2
2
2
2
2
3
2
2
2
2
3
3
2
2
3
2
2
2
2
3
2
2
2
3
3
2
2
3
2
2
2
3
3
2
3
3
3
2
2
2
2
2
3
3
2
2
2
2
2
2
2
2
2
3
3
2
2
2
2
3

result:

ok 100 lines

Test #27:

score: 22
Accepted
time: 2ms
memory: 4684kb

input:

100 100
PCCCPNPZCCNNCPPNNCCNPPNCCZPNZCPZCZNZCNNZNZZZZZPCZCNPZNPPPZPZNZZCNZZPN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
3
2
3
2
2
2
2
2
3
2
3
3
3
2

result:

ok 100 lines

Test #31:

score: 22
Accepted
time: 6ms
memory: 4720kb

input:

100 100
CCCCPPCPNCCZCZNPPPNCZPNNCPZPNCCPPZCPNPZPCNPPCPPZNNPCPCZPCCPZPZZZZCPNCZNNPZCCNCZPCZZPNZNCPZPZPZNNPNZ
ZPZZCCCNZPPCZCPNCCNCPPCZCNZCNPCCNZCPPNZNZCZZZNCCCPZCZPPZNPZNZNPNNPZNCPNNZCZPCZCZPCCNPCNCNNNZPCNZZCC
CPNZCPNPNPPCCZPNZNNCNNZNZPNCZCZPNCNZCCCNPNNZNNCPNNPCZPNPCNPPCNCNZNZZNCNCNPNPCCPZCNPCCCCNPNPC...

output:

2
2
2
2
2
3
2
3
2
3
3
2
3
2
2
2
2
2
2
2
2
2
3
2
2
2
2
3
2
2
2
3
2
3
3
3
3
3
2
2
2
3
3
2
3
2
3
2
2
2
2
3
2
2
2
2
2
3
3
2
3
2
2
3
2
2
3
2
3
3
3
2
3
2
3
2
2
3
3
2
2
2
2
2
3
2
3
3
2
2
3
3
2
3
2
2
2
3
3
3

result:

ok 100 lines

Test #32:

score: 22
Accepted
time: 6ms
memory: 4824kb

input:

100 100
CZPNPZPZNPPCZPZPNPCNZPZPPPPCCNNCCPCZCZNNZNPPNNNZCNNPCNNZNCCZNNNNZZCPNPNPNNZNZZZNZZCPZPZZCZNCCCPNNCZ
CPPCNNCNCNCNPCCNNCPNZCZZZCNPCZPCCPPZCPPPNNNPNNNCNCZCCCCCPNZPPCCNZNNPPNCPZCCNCZPNNPZZCCNZPPNNZZPZCCP
NCNNCNNPCNZPNPCZPZZPZPNZPNPZNPNZPZPPCCCPCZCNCZCZCNNCCPZPZNCPCZPNPPZPZPNCCCZCNPPPPCNPZZNZZPPC...

output:

2
3
3
2
3
3
2
2
3
2
2
2
3
2
3
2
3
2
3
2
2
2
2
2
3
3
2
3
3
2
2
3
2
2
3
2
2
3
2
2
2
2
2
2
2
2
2
3
3
3
3
2
3
3
2
2
2
2
2
2
2
2
2
3
3
2
3
3
3
2
2
3
3
3
3
2
2
2
2
3
3
2
2
3
3
3
2
3
2
2
3
2
2
3
2
2
3
2
3
2

result:

ok 100 lines

Test #33:

score: 22
Accepted
time: 5ms
memory: 4704kb

input:

100 100
NCCPPNCCNNPCPNPPZZNNCPNPCZNPCZPNPNPZCPPCPNCZNZZPNZZCZCCNPZZZNNZNCNZNZPNCNZCNCNZPNPZZNNPPPNNCPNNPNPZ
NPNZCNNZPZPPPZNZPZPNPCCCNZCZCCCPPPCNCNNPPZZPNNCCNZCZPPCCNCPZNNZPZCPPCPNPZNPCCCPPPCZNCNNZNZCCNPZCNZN
NCPCZPCNCCZPCCNNCCPPCPPZPNZCNNPZCNNZNCZCZNPPZNZNNCCPPPCPCNZPNNZNNCPZCPPCCZZPPPNZPPCPCCCNCNPZ...

output:

2
3
3
2
2
2
2
2
2
2
3
2
3
2
2
3
2
2
3
2
2
2
2
3
2
2
2
3
2
2
2
3
2
2
2
2
3
2
2
3
2
2
3
2
2
3
3
2
2
2
2
2
2
3
2
2
2
2
3
2
3
3
3
3
3
2
2
2
2
2
3
3
2
2
2
2
2
3
3
2
2
2
2
2
2
2
2
3
2
2
2
2
2
3
2
3
2
3
2
3

result:

ok 100 lines

Test #34:

score: 22
Accepted
time: 2ms
memory: 4664kb

input:

100 100
CZCNPZPPPPCPCCCPNZZZPCZCZPCNCCNCNNCCNZCPCNCNCNCPNPCPZPNCZPCPNCZCCPZNCZZCPNCZCNCNPZZNZPPPPZPZCNPZNPC
CZZPZPPZCNZNCPPNNNPCCCNCNPNCCCZZZCNCCZCZZZPPNNCZZPCZPNNNCCNNPCPPNPZCZCNPPNPCPZCNPPPCZCPNCPZZCCZZZZP
CNPNZZCNCPNCCNNPCCPZNCNZPPZPPPNCNNZNPNZPZNPPCZCPCNNNZZZNZPNPCZCNZPZZZCZZPPNNNNZNCNZZZCZZPPZN...

output:

3
3
2
2
2
3
2
3
3
3
3
2
2
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PPZPZZCCNZNPCNPNPPCCNZZPCNCCCNNCCZZPCPNZNCZN...

output:

3
2
3
2
3
3
3
3
3
2
3
3
2
3
2
3
2
3
2
2
3
2
2
2
2
2
3
2
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
3
2
3
2
2
2
3
2
3
3
2
2
3
3
2
2
2
3
3
2
2
2
2
2
3
2
2
3
3
2
2
2
3
2
2
3
3
2
2
2
2
2
2
2
3
2
3
3
3
3
2
3
2
2
2
3
3

result:

ok 100 lines

Test #37:

score: 22
Accepted
time: 2ms
memory: 3796kb

input:

30 100
NZCNPNNZZCCZPPPNNNCPCZCNCCCZPNPNNPPPPZCPNCZCZNZPCZCNZPNPCCCZPCZCPPNZNCCNZNZPZZNCPPZNCCPZPNPNNNPCCCP
NPPCPPZPZNNNPCPNZZZNPNPNNZZCZCCNCNNCZNZZZCNPNPNNZNNNCNZCCPCZCZCZNPPZNNCPNZZNNNCPZZCPNPNZCNZZZZNPNPP
NNCPZPNZCZZPZPNZCPZZZPZNPPNNNCZNZNNCCCZZZPCPCZPPPCCCCZNPNCCPNCZPPPNPPCPPZNCZCZZZCPNCCZCPZPNCZ...

output:

2
2
2
2
2
3
2
3
2
2
2
2
3
2
3
3
3
2
2
2
2
2
2
2
2
3
2
2
2
2
2
3
2
3
3
2
3
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
3
2
2
3
2
3
2
3
2
2
3
2
3
1
2
2
2
3
2
2
2
2
2
3
2
2
2
2
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
3

result:

ok 100 lines

Test #38:

score: 22
Accepted
time: 2ms
memory: 3736kb

input:

40 100
NZZCNPPPCNCNPCZCZCPCNZPNCCNCCZNZNPNPZNPPZZNCNCPCZCZZPZPCNZPPCCZCZZCCCCNPZZPZNNNPCNZPPPNZPZPPCCNNZPP
CNPCNZZNCNZPPPPCPZPNPNCNZPNZNPZCNNNZNCZNNCNPZPNZPNCCCCNNPPCPCCNCCCPZPPZNPPZP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