#P6438. Counting the States of Venetian Blinds

    ID: 19652 Type: Default 1000ms 256MiB

Counting the States of Venetian Blinds

Counting the States of Venetian Blinds

We represent each venetian blind as a 4×4 matrix. Each row of the matrix is either completely filled with the character * or completely with the character .. It is guaranteed that each blind is in one of five possible states. These five states are defined by the number of consecutive rows (starting from the top) that are *:

  • State 1: 0 rows of * (all rows are ....).
  • State 2: 1 row of * (first row ****, remaining three rows ....).
  • State 3: 2 consecutive rows of * (first two rows ****, last two rows ....).
  • State 4: 3 consecutive rows of * (first three rows ****, last row ....).
  • State 5: 4 rows of * (all rows ****).

The building in front has n floors and m windows on each floor. The state of each window is given as a part of a larger grid containing 4n rows and 4m columns. Each contiguous 4×4 block in the grid represents one window.

Your task is to count how many windows in the building are in each of the five states. Output the five counts in order from State 1 to State 5, separated by spaces.

Note: It is guaranteed that each 4×4 block corresponds to one of the five valid states.

inputFormat

The input begins with a line containing two integers n and m (1 ≤ n, m ≤ 100), representing the number of floors and the number of windows per floor.

Then follow 4n lines, each containing 4m characters. These 4n lines represent the building. Each contiguous 4×4 block in the grid is a window.

outputFormat

Output a single line containing five integers separated by spaces. The i-th integer (1 ≤ i ≤ 5) denotes the number of windows in State i.

sample

1 1
****
****
....
....
0 0 1 0 0