Under construction

Still being built. Things may change

Japanese Crossword

Time limit2sMemory limit1024 MB

Summary
Given a black and white picture, the task is to print the run lengths of black cells for each row and each column.
Level

Easy2 of 10

Topics
Implementation, Simulation
Solved
No attempts yet

Statement

Phineas and Ferb decided to print their own newspaper. It is almost finished, and only one puzzle is left to add at the end. They chose a Japanese crossword.

A Japanese crossword (nonogram) is a puzzle where the goal is to produce a black and white picture of size n×mn \times m. The puzzle starts with an empty n×mn \times m grid, and some cells must be colored black. To the left of each row, a sequence of numbers is written. These numbers are the lengths of the runs of black cells in that row, listed from left to right. Similarly, above each column, a sequence of numbers is written for the runs of black cells in that column, listed from top to bottom.

(a) The puzzle(b) The solved puzzle

Phineas and Ferb picked the picture that the solved puzzle should show. Help them find the number sequences to write beside the rows and above the columns.

Input

The first line contains two integers nn and mm, the size of the picture (1≤n,m≤1001 \le n, m \le 100). The next nn lines each contain mm characters describing the picture. A white cell is shown by ., and a black cell is shown by #.

Output

Print nn lines describing the rows of the crossword from top to bottom. Each line starts with the number of values in that row, followed by the values themselves. Then print mm lines describing the columns from left to right, in the same format. You may print extra newlines for readability.

Examples1

  1. Example 1

    Input
    11 8
    ........
    .####...
    .######.
    .##..##.
    .##..##.
    .######.
    .####...
    .##.....
    .##.....
    .##.....
    ........
    
    Expected output
    0
    1 4
    1 6
    2 2 2
    2 2 2
    1 6
    1 4
    1 2
    1 2
    1 2
    0
    
    0
    1 9
    1 9
    2 2 2
    2 2 2
    1 4
    1 4
    0