#P7977. Stone Piles Game

    ID: 21161 Type: Default 1000ms 256MiB

Stone Piles Game

Stone Piles Game

Vinsta and Stella have n piles of stones. The i-th pile contains s_i stones. They play a game taking turns, with Vinsta starting first.

On each turn, the current player selects between 1 and k piles (inclusive). For each chosen pile i, the player must choose two real numbers \(a\) and \(b\) satisfying the following conditions:

  • \(a \times b = s_i\), and
  • \(a + b = c\) where \(c\) is an integer with \(1 \le c \le s_i\).

After choosing such \(a\) and \(b\), exactly \(c\) stones are removed from pile i (i.e. \(s_i \leftarrow s_i - c\)). A player who cannot make any move loses.

Observation: Notice that if \(s_i \ge 4\), one may always choose \(c = s_i\) because \(s_i^2 - 4s_i \ge 0\) for \(s_i \ge 4\). In this way, any pile with at least 4 stones can be completely removed in a single move. Let \(M\) be the number of piles with \(s_i \ge 4\). Under optimal play, each move will typically remove one moveable pile (by setting it to 0). Thus, the game reduces to a take-away game with \(M\) objects, where on each turn a player may remove between 1 and \(k\) objects.

It is well known that in such a take-away game, the first player has a winning strategy if and only if \(M \bmod (k+1) \neq 0\). Your task is to determine whether Vinsta (the first player) has a winning strategy.

inputFormat

The first line contains two integers \(n\) and \(k\) (1 ≤ \(n, k\) ≤ 105).

The second line contains \(n\) integers \(s_1, s_2, \ldots, s_n\) (1 ≤ \(s_i\) ≤ 109), representing the number of stones in each pile.

outputFormat

Output YES if Vinsta has a winning strategy, or NO otherwise.

sample

3 1
1 4 2
YES

</p>