#P4658. Forced Win Strategy on a Board Game

    ID: 17904 Type: Default 1000ms 256MiB

Forced Win Strategy on a Board Game

Forced Win Strategy on a Board Game

Two players, A and B, play a game on an \(n \times n\) square board. Each cell on the board is either white or black, and the game is played only on the white cells (black cells are forbidden).

Initially, each player places a piece on his starting cell; the starting positions are guaranteed to be different. Players take turns moving, with player A moving first. In each move, a player moves his piece to an adjacent (up, down, left, or right) white cell.

If a player moves his piece into the cell currently occupied by the opponent, he is allowed a bonus move: immediately after landing, he may make one more move from that cell to an adjacent white cell; the direction of this bonus move may be different from that of the first move.

The objective is to be the first to have one’s piece reach the opponent's starting cell. In particular, if a player reaches the opponent's starting cell by a single move, he wins immediately. Moreover, in a move that includes a bonus step, if the opponent is located at his starting cell, then even if the piece does not end its bonus move exactly on that cell (i.e. merely by "jumping over" it), the moving player wins.

Your task is: given the board layout and the two players' starting positions, determine which player has a forced win strategy (i.e. no matter how the opponent moves, that player can guarantee a win).

inputFormat

The first line contains a positive integer \(n\) (the size of the board). The next \(n\) lines each contain a string of length \(n\) consisting of characters . (white cell) or # (black cell). The following line contains two integers \(r_a\) and \(c_a\), the 1-indexed row and column of player A's starting position. The last line contains two integers \(r_b\) and \(c_b\), the 1-indexed row and column of player B's starting position.

outputFormat

Output a single character: A if player A has a forced win strategy; otherwise, output B.

sample

3
...
...
...
1 1
3 3
A