A No-Win Situation

Time limit1sMemory limit128 MB

Problem

Consider a simple variation of the card game Blackjack. In this game, a single player plays against the dealer. The game uses a standard deck of cards, where the numbered cards 2 through 10 are worth the number of points shown on the card, the face cards (King, Queen, and Jack) are worth 10 points, and Aces are worth either 1 or 11 points.

The dealer deals the first card in the deck to the player, the second to the dealer, the third to the player, and the fourth to the dealer. The player may then keep drawing cards until they decide the total is as close to 21 as possible and stop voluntarily, or until they go over 21. If the player goes over 21, the player loses. The dealer must then draw cards until reaching 17 or more points (with Aces counting as 11 when possible). If the dealer goes over 21, the dealer loses. If neither goes over 21, the winner is whoever comes closest to 21. If the player and the dealer have the same total, the player wins.

For example, suppose the first cards in the deck are Queen, 6, 4, 9, and 10. On the initial deal the player receives Queen and 4 (a total of 14) and the dealer receives 6 and 9 (a total of 15). If the player draws no card, the dealer must draw (its total is below 17) and draws the 10, going over, so the player wins. But if the player draws a card (the 10), the player's total becomes 24, so the player loses.

In some situations it is impossible for the player to win. Consider the deck: 10, 3, 4, King, 3, 5. The player is dealt 10 and 4; the dealer has 3 and King. The table below shows what happens for each number of cards the player might draw:

Cards drawnPlayer's hand (points)Dealer's hand (points)
010, 4 (14)3, King, 3, 5 (21)
110, 4, 3 (17)3, King, 5 (18)
210, 4, 3, 5 (22)3, King (13)

No matter how many cards the player draws, the player cannot win.

In this problem you will analyze decks to determine whether they lead to a situation in which the player cannot win.

Input

The input is one or more decks. Each deck is represented by a string on its own line. Each deck consists of at least 4 cards, where a card is either an integer $d$ $(2 \le d \le 9)$ representing a numbered card, or one of the letters A, K, Q, J, or T, representing Ace, King, Queen, Jack, or Ten, respectively. The letters are uppercase. There are no other characters on a line; in particular, there are no spaces. There will always be enough cards to try all valid draws. The end of input is indicated by the word JOKER, alone on a line.

Output

Print a response for each input deck, one per line. Print the word Yes if there is some number of cards the player can draw and win, and No if there is no way for the player to win. Print these words exactly as shown. Do not print any blank lines between outputs.