410318: GYM104009 B AGaMe

Memory Limit:1024 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. AGaMetime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard output

Since the beginning of the AGM contest, the members of the committee have had a favourite game which we always play before the contest for good luck.

The game is played between $$$3$$$ players using $$$N$$$ cards. The game has perfect information, all the players know all the cards in the game. Each player has $$$N/3$$$ cards of the following types:

  • $$$7$$$ - used to attack a turn
  • $$$8$$$
  • $$$9$$$
  • $$$10$$$ - equals to a point
  • $$$A$$$ - equals to a point
  • $$$J$$$
  • $$$Q$$$
  • $$$K$$$

The game is played in turns. At the end of a turn, the starting player for the next turn is determined and the process repeats until all the players have no cards left. The rules for a turn are the following:

  1. Each of the players will put exactly one card down in clockwise order beginning from the starting player of the turn (so player $$$(currentPlayer + 1) \% 3$$$ is after player $$$currentPlayer$$$).
  2. A player can attack a turn by putting a $$$7$$$ or a card equal to the first card of the turn placed by the starting player.
  3. At the end of a turn (after all 3 players have put a card down), if the starting player was not attacked by either of the other two players, he will be the winner of the turn.
  4. If the starting player was attacked, he can decide to either give up and let the last player that attacked him be the winner, or decide to contest by putting a $$$7$$$ or a card equal to the first card of the turn. If the player contests, the turn will continue and the other 2 players will have to each put a card down again and the process repeats until a winner is determined.
  5. The winner of a turn takes all the points of the turn (equal to the number of $$$10$$$ and $$$A$$$ cards from the table) and will be the starting player of the next turn.
  6. At the end of a turn, all the cards from the table are burned.

At the end of the game (when all the players have no cards left), the winner of the game is the player that has more points than each of the other two players (in the case there are more players with the maximum number of points, there are no winners).

In this game, you are the player $$$0$$$ (note: player $$$0$$$ is not always the starting player of the first turn). Your objective is to win the game. The other two players have no interest in winning, but they will do the optimal strategy in order to not let you win (classic sportsmanship).

If everyone plays the optimal strategy, we want you to determine if you can win the game or not.

Input

The first line of the input contains the integers $$$N$$$ ($$$3 \leq N \leq 15$$$, N multiple of 3) and $$$P$$$ ($$$0 \leq P \leq 2$$$), denoting the total number of cards and the player who starts the game. The next $$$3$$$ lines have $$$N/3$$$ cards separated by spaces (a card can be $$$7$$$, $$$8$$$, $$$9$$$, $$$10$$$, $$$A$$$, $$$J$$$, $$$Q$$$ or $$$K$$$), denoting the cards of player $$$0$$$, $$$1$$$, and $$$2$$$, respectively.

Output

Print $$$YEE!$$$ if there is an optimal strategy in order to win or $$$OOH...$$$ otherwise.

ExamplesInput
3 1
7
A
A
Output
YEE!
Input
6 2
8 A
7 7
9 Q
Output
OOH...
Input
15 0
Q A 10 10 7
10 J A A 9
8 9 J 8 Q
Output
YEE!
Note

In the first example, player $$$1$$$ starts the game with $$$A$$$, player $$$2$$$ puts another $$$A$$$ and player $$$0$$$ puts a $$$7$$$. Because player $$$1$$$ cannot contest now (has no cards left), player $$$0$$$ is the one that attacked last (even if player $$$2$$$ attacked before him by putting a $$$A$$$), thus winning the $$$2$$$ points in the turn and winning the game.

In the second example, any strategy player $$$0$$$ chooses, player $$$1$$$ and player $$$2$$$ will always succeed in making him lose.

加入题单

算法标签: