#P12097. Tiling the Damaged Parquet

    ID: 14202 Type: Default 1000ms 256MiB

Tiling the Damaged Parquet

Tiling the Damaged Parquet

Archimedes discovered that after a mishap with water, only parts of his 2×n parquet floor were damaged. The remaining undamaged pieces are fixed and cannot be replaced. You have an unlimited supply of 1×2 domino pieces that can be placed either vertically or horizontally. Your task is to fill exactly the damaged cells (denoted by a dot '.') while never covering the undamaged cells (denoted by a '#' symbol) and without overlapping domino pieces. According to Archimedes, there should be exactly one way to repair the floor. However, if his calculations are wrong, determine whether there exist multiple tilings or if it is impossible to tile the damaged region.

More formally, you are given a grid of 2 rows and n columns. Each cell is either damaged ('.') or intact ('#'). A domino covers two adjacent cells (sharing a side) that are both damaged. You must tile all damaged cells with domino pieces such that no domino covers an intact cell and dominoes do not overlap.

Output Unique if there is exactly one tiling, Ambiguous if there are multiple tilings, and Impossible if there is no valid tiling.

The grid dimensions include a \(2 \times n\) board and domino pieces of size \(1 \times 2\).

inputFormat

The input begins with a single integer n (1 ≤ n ≤ 100) representing the number of columns. The following 2 lines each contain a string of length n. The characters in the strings are either '.' (a damaged cell that must be tiled) or '#' (an undamaged cell that must not be covered).

Example:

2
.#
..

outputFormat

Print a single word: Unique if there is exactly one way to tile the damaged cells, Ambiguous if there are more than one tiling, and Impossible if no valid tiling exists.

sample

2
..
..
Ambiguous

</p>