P26352 [AtCoder] FU
提高
题目描述

Problem Description

X and Y are playing a game called FU.

This game is played on a board divided into $n \times n$ squares, with a piece called FU. X places one of their FU pieces facing down on each square of the top row, and Y places one of their FU pieces facing up on each square of the bottom row.

Players take turns moving one of their FU pieces according to the following rules:

  • X's FU can only move to a square adjacent below the current square.
  • Y's FU can only move to a square adjacent above the current square.
  • A player captures an opponent's FU by moving their FU to the same square.

Players cannot pass their turn or move their FU twice in a row. The player who captures all of the opponent's FU pieces wins.

Nimakun, who started watching the game midway, does not know who started first, as X and Y are too focused on the game to answer. Fortunately, the game is just beginning, and neither has captured any of the opponent's FU pieces, so it might be possible to determine who started first from the current state of the board.

Create a program that takes the current state of the board as input and determines who started first.

Input Format

The input is given in the following format:

$ n $ $B_{1,1}B_{1,2}...B_{1,\ n}$ $B_{2,1}B_{2,2}...B_{2,\ n}$ $ ... $ $B_{n,1}B_{n,2}...B_{n,\ n}$

  • The first line contains an integer $ n $ ($2 \leq n \leq 100$), representing the size of one side of the board.
  • The following $ n $ lines provide the information of each row of the board from the top row to the bottom row.
  • Each element $ B $ represents the state of a square and is one of the characters ., X, or Y.
  • . means the square is empty, while X and Y indicate that X's or Y's FU piece is on that square, respectively.
  • In each column, there is exactly one X and one Y, and X is always positioned above Y.
  • The provided board state is guaranteed to be consistent with the game rules.

Output Format

Output X if X started first, Y if Y started first, or Impossible if it cannot be determined who started first.

End with a newline and do not include any extra characters or blank lines.

Sample Input and Output

Sample Input #1

4
X..X
.XX.
.YYY
Y...

Sample Output #1

Y

Sample Input #2

3
XXX
...
YYY

Sample Output #2

Impossible

Notes/Hints

None

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 X..X .XX. .YYY Y...
样例输出
Y