Keep it covered

Decide whether a grid of dots and empty cells can be tiled by four line-piece types so that lines match across shared sides and never touch the border.

Hard8GraphDFSBacktrackingCombinatoricsNo attempts yetTime limit1sMemory limit1024 MB

Problem

Eve loves puzzles. The one she bought recently has turned out to be hard. The puzzle is a rectangular grid with RR rows and CC columns. Some cells carry a dot and the rest are empty. Four types of pieces come with the puzzle, and there are R×CR \times C units of each type.

Every piece carries a line drawing. A type 1 piece has a dot inside the cell, and a line runs from that dot to the midpoint of one side. A type 2 piece is a straight line joining the midpoints of two opposite sides. A type 3 piece is a bent line joining the midpoints of two adjacent sides. A type 4 piece leaves one side, loops around inside the cell and returns to the same side, so its line meets that side at two points. Those two points are not the midpoint of the side; they sit apart from each other on either side of it.

The objective is to use some of the pieces to fill the grid completely, so that every cell is covered by one piece. A piece may be rotated by 90, 180 or 270 degrees. Three constraints must be respected:

  1. A type 1 piece can only be placed on a cell marked with a dot, and the other types can only be placed on empty cells.
  2. For any two cells sharing a side, the lines of the two pieces must meet that side at exactly the same points.
  3. No line may touch the border of the grid.

Eve suspects the puzzle was built sloppily and has no solution at all. Decide whether the puzzle can be solved.

Input

The first line contains two integers RR and CC (1R,C201 \le R, C \le 20), the number of rows and the number of columns of the puzzle. Each of the next RR lines contains a string of CC characters describing one row of the grid. The lowercase letter o marks a cell with a dot, and the hyphen - marks an empty cell. At most 15 cells carry a dot.

Output

Print a single line with the uppercase letter Y if the puzzle can be solved as described, and the uppercase letter N otherwise.