#P2953. [USACO09OPEN] Cow Digit Game S

[USACO09OPEN] Cow Digit Game S

Description

Bessie is playing a number game against Farmer John, and she wants you to help her win.

Game ii starts with an integer NiN_i (1Ni1,000,0001 \le N_i \le 1{,}000{,}000). Bessie goes first, and then the two players alternate turns. On each turn, a player can subtract from the current number either its largest digit or its smallest nonzero digit to obtain a new number. For example, from 30143014 we may subtract either 11 or 44 to obtain either 30133013 or 30103010, respectively. The game continues until the number becomes 00, at which point the last player to have taken a turn is the winner.

Bessie and FJ play GG (1G1001 \le G \le 100) games. Determine, for each game, whether Bessie or FJ will win, assuming both play optimally (that is, on each turn, if the current player has a move that guarantees a win, they will take it).

Consider a sample game where Ni=13N_i = 13. Bessie goes first and takes 33, leaving 1010. FJ is forced to take 11, leaving 99. Bessie takes the remainder and wins the game.

Input Format

  • Line 1: A single integer GG.
  • Lines 2..G+1G+1: Line i+1i+1 contains the single integer NiN_i.

Output Format

  • Lines 1..GG: Line ii contains 'YES' if Bessie can win game ii, and 'NO' otherwise.
2 
9 
10 

YES 
NO 

Hint

For the first game, Bessie simply takes the number 99 and wins. For the second game, Bessie must take 11 (since she cannot take 00), and then FJ can win by taking 99.

Translated by ChatGPT 5