#P2148. E&D Game

    ID: 15429 Type: Default 1000ms 256MiB

E&D Game

E&D Game

Two players, E and W, play a game called E&D. The game is played on a table with \(2n\) piles of stones labeled \(1\) to \(2n\). For convenience, piles \(2k-1\) and \(2k\) (for \(1 \le k \le n\)) form a group. The \(i\)-th pile has a positive number \(S_i\) stones.

A splitting operation is defined as follows: a player chooses any pile and removes it from the table. Then, from its partner in the same group, the player splits that partner pile by taking some positive number of stones (at least \(1\), but strictly less than the total in that pile) and placing them on the removed pile’s position, thus forming a new pile. After the operation, every pile must contain at least one stone. (Note that the partner pile from which stones are taken must have at least \(2\) stones to allow a split.)

The two players take turns performing splitting operations. If on a player’s turn every pile on the table contains exactly \(1\) stone (that is, no valid move exists), then that player loses the game.

Player E moves first. Given the initial configuration of the \(2n\) piles, determine whether there exists a winning strategy for player E (i.e. a strategy that guarantees victory regardless of how player W responds). For example, consider the case where \(n=2\) and the piles contain \(1,2,3,1\) stones respectively. Player E can choose to remove the 1-st pile and then split pile 2 (which has 2 stones) by taking 1 stone (the only possibility). Then player W is forced to remove the 4-th pile and split pile 3 (with 3 stones) into two piles of sizes 1 and 2. Finally, player E can remove the pile with 1 stone and split the remaining pile, leaving all piles with 1 stone for player W, thus ensuring a win for player E.

Note: The game in each group is independent. A move in a group is possible if and only if at least one of the two piles in the group has at least \(2\) stones. In a move, if a player removes one pile from a group then they must split the other pile (which has at least \(2\) stones) into two nonempty piles. This naturally leads to a composite impartial game where the overall position is the disjunctive sum of the groups. Player E has a winning strategy if and only if the nim-sum of the Grundy values of all groups is nonzero.

Your task is to decide, for a given initial configuration, whether player E can guarantee a win. Print Yes if a winning strategy exists, and No otherwise.

inputFormat

The first line contains a single integer \(n\) (the number of groups). The second line contains \(2n\) positive integers: \(S_1, S_2, \ldots, S_{2n}\), where \(S_i\) denotes the number of stones in the \(i\)-th pile.

outputFormat

Print a single line containing either Yes if player E has a winning strategy, or No otherwise.

sample

1
1 1
No