A nonogram (數織) is a puzzle on an grid. Each cell is either filled (#) or empty (.).
A block is a single filled cell, or several filled cells next to each other, in the same row or the same column. Every row and every column has a clue: a list of numbers that gives the lengths of its blocks.
The picture below shows a puzzle (left) and its answer (right). The blue numbers on the left are the clues for the rows. The orange numbers at the top are the clues for the columns.
Rules
The numbers in a row's clue are given in order from left to right. The numbers in a column's clue are given in order from top to bottom.
Two blocks in the same row or column must have at least one empty cell between them.
A clue of 0 means that the whole row or column is empty.
For example, if a row has cells and its clue is 2 1, the row has a block of filled cells, and then a block of filled cell to the right of it. So the row can be ##.#., ##..#, or .##.#.
Given the clues for all rows and columns, find which cells are filled. It is guaranteed that there is exactly one answer.
Input
The first line contains two space-separated integers and — the number of rows and the number of columns.
Each of the next lines contains the clue for one row, from the top row to the bottom row.
Each of the next lines contains the clue for one column, from the leftmost column to the rightmost column.
Each clue is either a single 0 or one or more space-separated positive integers.
For example, Sample Input 1 describes the puzzle below, and its answer is Sample Output 1.
Constraints
The puzzle has exactly one answer.
Subtasks
Subtask 1 (Testcase 1-6):
Subtask 2 (Testcase 7-10): No additional constraints.
Output
Output lines. Each line contains exactly characters with no spaces: # for a filled cell and . for an empty cell.
Hints
First, write a recursive function that lists all the ways to fill one line of cells for a given clue. Decide where the first block starts. Then the rest of the line is the same problem, but with fewer cells and fewer numbers.
Next, use recursion to fill the grid one row at a time: for the current row, try each way to fill it that you found in step 1, and then move on to the next row.
For Subtask 2, check the columns after placing each row. If a column can no longer match its clue, do not go deeper. Go back and try the next way to fill the current row (this is called backtracking).