#P1247. Nim Game Winning Move
Nim Game Winning Move
Nim Game Winning Move
Given \(k\) piles of matchsticks with counts \(n_1, n_2, \dots, n_k\), two players take turns removing one or more matchsticks from a single pile. In each move, a player must remove at least one matchstick and may remove any positive number of matchsticks from exactly one pile (even removing the entire pile is allowed). The winner is the player who removes the last matchstick.
This game is based on the classic Nim game theory. The outcome of the game is determined by the \(\text{Nim}\)-sum, defined as \[ n_1 \oplus n_2 \oplus \cdots \oplus n_k, \] where \(\oplus\) denotes the bitwise XOR operation. If the \(\text{Nim}\)-sum is non-zero, the first player has a winning strategy. Otherwise, the first player is in a losing position.
Your task is: Given the initial configuration, determine whether the first player can force a win. If yes, output the first move (i.e. the 1-indexed pile number and the number of matchsticks to remove) to make the \(\text{Nim}\)-sum zero. If the first player is in a losing position, output lose
.
inputFormat
The input consists of a single line containing an integer \(k\) (the number of piles), followed by \(k\) space-separated integers representing \(n_1, n_2, \dots, n_k\), the number of matchsticks in each pile.
outputFormat
If the first player has a winning strategy, output two integers separated by a space: the 1-indexed pile number and the number of matchsticks to remove in the first move. Otherwise, output lose
.
sample
2
2 2
lose