#P4279. Misère Nim Game

    ID: 17525 Type: Default 1000ms 256MiB

Misère Nim Game

Misère Nim Game

John often plays an interesting game with his older brother. There are \( n \) piles of stones on the table. John and his brother take turns removing stones. During his turn, a player may choose any pile and remove at least one stone from that pile. However, the player who removes the last stone loses the game.

John is quite stubborn and always insists on moving first, believing that this gives him a huge advantage, while his brother plays flawlessly. Your task is to determine the winner of the game if both play optimally. Output "John" if the first player wins and "Brother" otherwise.

This game is a variant of Misère Nim. Recall that:

  • If all piles have exactly one stone, then the first player wins if and only if \( n \) is even.
  • If there is at least one pile with more than one stone, compute the nim-sum (i.e. the bitwise XOR of all pile sizes). In this case, the first player wins if and only if the nim-sum is nonzero.

inputFormat

The first line contains a single integer \( n \) (\( 1 \leq n \leq 10^5 \)) representing the number of piles.

The second line contains \( n \) integers \( a_1, a_2, \dots, a_n \) (\( 1 \leq a_i \leq 10^9 \)), where \( a_i \) denotes the number of stones in the \( i \)-th pile.

outputFormat

Output a single line containing either "John" if the first player wins under optimal play or "Brother" if otherwise.

sample

1
1
Brother

</p>