#P1247. 取火柴游戏
取火柴游戏
Description
Given and integers , there are piles of matchsticks, where the -th pile contains sticks. You will then play a matchstick-taking game against the computer. The rules are as follows: on each turn, you may take any positive number of matchsticks from exactly one pile, possibly taking the entire pile, but you may not take from multiple piles in a single move, and you may not pass.
Whoever takes the last matchstick wins.
For example: , . Let A denote you, and P denote the computer. If A moves first:
- A: , that is, take one from the first pile.
- P: , that is, take one from the second pile.
- A: .
- P: . P wins.
If A moves second:
- P: .
- A: . A wins.
Another example: , , , , and A moves second:
- P: .
- A: .
- A has reduced the game to the case; no matter how P moves, A will surely win.
Write a program that, given the initial state, determines whether the first player has a forced win or a forced loss. If the first player has a forced win, output how to make the first move. If the first player has a forced loss, output lose.
Input Format
The first line contains a positive integer .
The second line contains integers .
Output Format
If the first player has a forced win, output two integers on the first line, meaning that on the first move you take matchsticks from pile . The second line should be the state after the first move.
If there are multiple valid answers, output the lexicographically smallest answer by the pair (that is, with the smallest , and under that, the smallest ).
If the first player has a forced loss, output lose.
3
3 6 9
4 3
3 6 5
4
15 22 19 10
lose
Hint
Constraints
For all testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号