Counting Tetris Figures

Count occurrences of each of five tetromino shapes (rotations allowed, no flips) in a grid colored so adjacent figures differ.

Medium6ImplementationGraphBFSBrute forceNo attempts yetTime limit1sMemory limit64 MB

Problem

Ivica is writing a computer game. The part he has finished places five kinds of Tetris figures in a grid. Before a figure goes into the grid it can be rotated by 90 degrees any number of times and it can be coloured. There is no flipping. A figure cannot be placed if it would leave the grid or overlap a figure that is already there.

The five figures are these.

Figure 1Figure 2Figure 3Figure 4Figure 5

The same five figures written with characters, where # is a cell the figure occupies:

Fig 1  Fig 2   Fig 3  Fig 4  Fig 5
##     ####    .##    ##.    .#.
##             ##.    .##    ###

Figure 3 and figure 4 are mirror images of each other, so no rotation turns one into the other and they count separately.

While Ivica was at school, his sister Marica started the game and placed figures in the grid, rotating and colouring them as she liked. Two adjacent figures always have different colours. Two figures count as adjacent when they share a side or when they touch only at a corner.

Ivica came back and found his sister's figures still in the grid. Count how many of each figure the grid holds.

Input

The first line contains the number of rows NN and the number of columns MM of the grid (1N,M101 \le N, M \le 10). Each of the next NN lines contains one row of the grid as MM characters.

Each character is either ., which is an empty cell, or a lowercase English letter, which is part of a figure. Different letters are different colours, and the four cells of one figure all carry the same letter.

Output

Print exactly five lines. Line ii contains how many times figure ii appears in the grid.

Note

The picture below shows the grid of the third example.