Avoiding three-in-a-row

Given an n×mn \times m board with some cells already marked, fill it with ‘O’ and ‘X’ in all the possible ways, but avoiding any horizontal or vertical three-in-a-row. The diagonal three-in-a-row are allowed.

Input

Input consists of several cases. Every case begins with nn and mm, followed by nn rows with mm characters each. If the cell is already marked, there is an ‘O’ or an ‘X’. Otherweise, we have a period. You can assume that nmn \cdot m is between 1 and 20, and that there is no three-in-a-row initially.

Output

For every case, print in lexicographical order (from top to bottom, and inside each row, from left to right) all the ways to fill the board without any forbidden three-in-a-row. Print a line with 10 dashes at the end of each board, and a line with 20 asterisks at the end of each case.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:04:53.866Z

© Jutge.org, 2006–2026.
https://jutge.org