#P7979. Stone Pile Game

    ID: 21163 Type: Default 1000ms 256MiB

Stone Pile Game

Stone Pile Game

Vinsta and Stella have n piles of stones. The i-th pile has si stones. They play a turn‐based game starting with Vinsta. In each turn, the current player must choose at least 1 and at most k piles to operate on. For each chosen pile with s stones (with s = si), the player must select two real numbers a and b satisfying

\(a\times b = s\)

and

\(a+b = c, \quad c\in [1,s]\cap \mathbb{Z}\)

Then the player removes exactly c stones from that pile, i.e. updates si \leftarrow si - c. A move is legal only if it is possible to find such a pair (a,b) for each selected pile. Note that for a pile with fewer than 4 stones no such move exists (since for s < 4, one cannot have an integer c in the interval \([1,s]\) satisfying \(c^2 \ge 4s\)).

It is always possible, for any pile with s ≥ 4, to choose c = s (because \(s \ge \lceil2\sqrt{s}\rceil\) when s ≥ 4), which completely removes that pile from further play. Thus, an optimal strategy is to finish (remove) any pile that can be acted upon. Let m be the number of piles with si \ge 4 (i.e. the number of piles on which a move is possible) and note that in one turn a player may remove (finish) between 1 and k piles. Therefore the game essentially reduces to a take-away game with m stones where each move removes between 1 and k stones. It is well known that in such a game the first player has a winning strategy if and only if

\( m \mod (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 ≤ 105, 1 ≤ k ≤ n), where n is the number of piles and k is the maximum number of piles that can be chosen in one move.

The second line contains n space‐separated integers s1, s2, ..., sn (1 ≤ si ≤ 109), where si denotes the number of stones in the i-th pile.

outputFormat

Print a single line with Yes if Vinsta has a winning strategy, and No otherwise.

sample

3 1
4 1 6
No