Cow Checkers
Time limit1sMemory limit128 MB
For each starting square on a large board, decide the winner of a two-player game with three kinds of leftward or downward moves.
- Level
Medium7 of 10
- Topics
- Game theory, Math
- Solved
- No attempts yet
Problem
One day Bessie decides to challenge Farmer John to a game of "Cow Checkers". The game is played on an checkerboard (, ) that initially contains a single checker piece at coordinates (, ). The bottom-left square of the board has coordinates , and the top-right square has coordinates . Bessie always moves first, and then the two players alternate turns.
On each turn a player makes one of the following three moves:
- Move the piece to any square in the same row that lies to the left of its current position.
- Move the piece to any square in the same column that lies below its current position.
- Move the piece to the square that is squares down and squares to the left of its current square, where is any positive integer for which the destination square is still on the board.
The first player who is unable to move (i.e., because the piece is at ) loses. Given that Bessie always goes first and both players play optimally, determine who wins.
For games (), read a new starting position for each game and decide the winner.
Input
- Line 1: Two space-separated integers and
- Line 2: A single integer
- Lines 3 through : Two space-separated integers and on each line
Output
For each game print one line containing either Farmer John or Bessie, depending on who wins that game. Print lines in total.
Hint
Consider one game on a checkerboard with the piece initially at (the center of the board).
Bessie can initially move the piece only to , , or . Bessie can win immediately by moving the piece to .