O-Flowers
Milica can not wear her old woolen cap to keep hair in one place so she decide to buy some hairpins in shape of flowers. On nearby market Milica saw on one stand lot off hairpins, but then she realized that her pockets are not deep enough for this purchase. Seller offer one opportunity to Milica: he will give her couple of hairpins if she can solve next task.
On rectangular plate MxN divided in squares 1x1, colored with various colors, are "hidden" flowers. Seller expect from Milica to answer how many flowers of every of three types are on plate?
When You consider flower of any type only thing that matter is: all parts of flower same colored on prototype must be same colored on plate as well. This can be any color. White parts of prototype can be any color. Milica is keen to replace boring cap but she is color blind and ask You for help.
Input:
5 5
XXXXX
XXXXX
XXXXX
XXXXX
XXXXXOutput:
1
1
1Input:
5 5
OXOXO
XXZXX
OZOZO
XXZXX
OXOXOOutput:
1
1
0Input:
5 7
ABCDEAQ
FGHIJWE
KLNMORT
PQRSTZT
UVWXZYLOutput:
0
0
0NOTICE: if you put in example 2 on position (3,3) some other color then 'O' flower of type 2 will not be correct.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.