The Unfair Game
Limits: 2 sec., 256 MiB
John and Brus are playing the unfair game on \(H \times W\) board. John has a single checker which is initially located at \((R_J,~C_J)\). And Brus has a single checker which is initially located at \((R_B,~C_B)\). All coordinates are 1-based. The two players alternate turns . When it is John’s turn, he chooses one of four directions (up, down, left or right) and moves his checker one cell in the chosen direction. When it is Brus’s turn, he also chooses one of those four directions and moves his checker any positive number of cells in the chosen direction. A player wins the game when his move puts his checker in the cell occupied by his opponent’s checker.
John: Brus, do you really think it’s fair?
Brus: Sure, just go on!
Both players use an optimal game strategy. If the player can win, he will follow the strategy that minimizes the number of moves in the game. If the player can’t win, he will follow the strategy that maximizes the number of moves in the game. You have to determine the game outcome.
Input
A test case starts with a line containing two integers \(H\) and \(W\). The following line contains four integers \(R_J\), \(C_J\), \(R_B\) and \(C_B\), in this very order. All the integers in a single line are separated by single spaces. The next line contains the name of the player (either John or Brus) who will start the game.
Output
Print a single line containing the name of the winner and the total number of moves in the game separated by a single space.
Constraints
\(2 \le H, W \le 10^9\),
\(1 \le R_J, R_B \le H\),
\(1 \le C_J, C_B \le W\),
\((R_J, C_J)\) and \((R_B, C_B)\) will be different.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 4 7 1 1 2 7 John | Brus 6 |
| Input (stdin) | Output (stdout) |
|---|---|
| 2 2 1 2 2 1 Brus | John 2 |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|