#P7467. Game of Stones

    ID: 20662 Type: Default 1000ms 256MiB

Game of Stones

Game of Stones

This is a two‐player game translated from CERC2018. Two players, Petyr and Varys, are playing a game with N piles of stones. The players move alternately; at the start of the game Petyr makes the first move. In each move, the current player must choose one pile which contains at least one stone and remove some stones from it – at least 1 stone must be removed. However, the two players have different move limits. Petyr can remove at most \(A\) stones in his move, while Varys can remove at most \(B\) stones in his move. The player who removes the last stone wins.

Your task is to determine whether Petyr can force a win under optimal play.

Note: It is guaranteed that the total numbers are small (N ≤ 10 and the number of stones in each pile ≤ 20), so that a state-space search using recursion with memoization is feasible.

inputFormat

The first line contains three integers: N, A, and B, where

  • N is the number of piles.
  • A is the maximum number of stones Petyr can remove in his turn.
  • B is the maximum number of stones Varys can remove in his turn.

The second line contains N integers, where the i-th integer represents the number of stones in the i-th pile.

All values are separated by spaces.

outputFormat

Output a single line containing either Petyr if Petyr can force a win under optimal play, or Varys otherwise.

sample

1 3 2
4
Petyr

</p>