{"raw_statement":[{"iden":"statement","content":"Pirate John Silver has found a map depicting exactly one island in a sea. The map is a piece of cloth divided into cells: n cells in height and m cells in width. John Silver knows that every cell denotes either land or water, but some of the cells are erased, and now it's absolutely impossible to say what these cells represent.\n\nHelp John Silver to restore the map of the island. An island is a non-empty set of land cells connected in four directions (up, down, left and right).\n\nThe first line contains two integers n and m (1 ≤ n,  m ≤ 50) — the sizes of the map.\n\nEach of the next n lines contains m characters and describes the map. A character is equal to «_#_» if this cell is a water cell, «_._» if it's a land cell, and «_?_» if this cell is erased.\n\nIt's guaranteed that the input contains at least one character «_._» and at least one character «_?_».\n\nIf it's not possible to restore the map so that it would depict exactly one island, output «_Impossible_».\n\nIf the map can be restored in a unique way, output n lines of m characters in the same format as they are in the input, but replacing «_?_» with «_._» or «_#_».\n\nAnd if there are several correct ways to restore the map, output «_Ambiguous_».\n\n"},{"iden":"input","content":"The first line contains two integers n and m (1 ≤ n,  m ≤ 50) — the sizes of the map.Each of the next n lines contains m characters and describes the map. A character is equal to «_#_» if this cell is a water cell, «_._» if it's a land cell, and «_?_» if this cell is erased.It's guaranteed that the input contains at least one character «_._» and at least one character «_?_»."},{"iden":"output","content":"If it's not possible to restore the map so that it would depict exactly one island, output «_Impossible_».If the map can be restored in a unique way, output n lines of m characters in the same format as they are in the input, but replacing «_?_» with «_._» or «_#_».And if there are several correct ways to restore the map, output «_Ambiguous_»."},{"iden":"examples","content":"Input5 7########..#..##..?..##..#..########Output########..#..##.....##..#..########Input5 7########...#.##.?.?.##.#...########OutputAmbiguousInput5 7########.#.#.##.#?#.##.#.#.########OutputImpossible"}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ with $ 1 \\leq n, m \\leq 50 $.  \nLet $ M \\in \\{ \\texttt{\\#}, \\texttt{.}, \\texttt{?} \\}^{n \\times m} $ be the input grid, where:  \n- $ \\texttt{\\#} $ denotes *water* (fixed),  \n- $ \\texttt{.} $ denotes *land* (fixed),  \n- $ \\texttt{?} $ denotes *erased* (unknown).  \n\nLet $ L = \\{ (i,j) \\mid M[i][j] = \\texttt{.} \\} $ be the set of fixed land cells.  \nLet $ E = \\{ (i,j) \\mid M[i][j] = \\texttt{?} \\} $ be the set of erased cells.  \n\nAn *island* is a non-empty, 4-connected component of land cells.  \n\n**Constraints**  \n1. $ L \\neq \\emptyset $ and $ E \\neq \\emptyset $ (guaranteed).  \n2. Each erased cell $ (i,j) \\in E $ must be assigned either $ \\texttt{.} $ (land) or $ \\texttt{\\#} $ (water).  \n3. The resulting grid must contain **exactly one** connected island (i.e., exactly one 4-connected component of land cells, and all other cells are water).  \n4. All fixed land cells $ L $ must belong to this single island.  \n\n**Objective**  \nDetermine the number of valid assignments $ f: E \\to \\{ \\texttt{.}, \\texttt{\\#} \\} $ such that:  \n- The set $ L \\cup f^{-1}(\\texttt{.}) $ forms a single 4-connected component.  \n- All other cells (i.e., $ \\texttt{\\#} $ and $ f^{-1}(\\texttt{\\#}) $) are not part of any land component.  \n\nThen:  \n- If **zero** such assignments exist → output `\"Impossible\"`.  \n- If **exactly one** such assignment exists → output the grid with `?` replaced by the assigned value.  \n- If **two or more** such assignments exist → output `\"Ambiguous\"`.","simple_statement":"You are given a grid of size n×m with cells marked as:  \n- '#' = water  \n- '.' = land  \n- '?' = unknown  \n\nYou must replace all '?' with either '.' or '#' so that:  \n- There is exactly **one** connected island (group of '.' connected up/down/left/right)  \n- The island must be **non-empty**  \n- All other cells must be '#'  \n\nIf:  \n- No valid way → output \"Impossible\"  \n- Exactly one valid way → output the grid with '?' replaced  \n- More than one valid way → output \"Ambiguous\"  \n\nGuaranteed: at least one '.' and one '?' in input.","has_page_source":false}