#P1247. 取火柴游戏

取火柴游戏

Description

Given kk and kk integers n1,n2,,nkn_1, n_2, \cdots, n_k, there are kk piles of matchsticks, where the ii-th pile contains nin_i 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: k=2k = 2, n1=n2=2n_1 = n_2 = 2. Let A denote you, and P denote the computer. If A moves first:

  • A: (2,2)(1,2)(2, 2) \rightarrow (1, 2), that is, take one from the first pile.
  • P: (1,2)(1,1)(1, 2) \rightarrow (1, 1), that is, take one from the second pile.
  • A: (1,1)(1,0)(1, 1) \rightarrow (1, 0).
  • P: (1,0)(0,0)(1, 0) \rightarrow (0, 0). P wins.

If A moves second:

  • P: (2,2)(2,0)(2, 2) \rightarrow (2, 0).
  • A: (2,0)(0,0)(2, 0) \rightarrow (0, 0). A wins.

Another example: k=3k = 3, n1=1n_1 = 1, n2=2n_2 = 2, n3=3n_3 = 3, and A moves second:

  • P: (1,2,3)(0,2,3)(1, 2, 3) \rightarrow (0, 2, 3).
  • A: (0,2,3)(0,2,2)(0, 2, 3) \rightarrow (0, 2, 2).
  • A has reduced the game to the (2,2)(2, 2) 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 kk.

The second line contains kk integers n1,n2,,nkn_1, n_2, \cdots, n_k.

Output Format

If the first player has a forced win, output two integers a,ba, b on the first line, meaning that on the first move you take aa matchsticks from pile bb. 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 b,a\langle b, a \rangle (that is, with the smallest bb, and under that, the smallest aa).

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, k500000k \le 500000, ni109n_i \le 10^9.

Translated by ChatGPT 5