Hide

Problem B
Flop Strategy

Your friends Alice, Bob, Charlie, and David are playing a variant of a popular card game called “Flip-7”, which they call “Flop-7”. The game is played with a deck consisting of one $1$ point card, two $2$ point cards, three $3$ point cards, up to twelve $12$ point cards as well as one $0$ point card and one “Second Chance” card for a total of $80$ cards.

In this game players take turns either “hitting” or “banking”.

If a player chooses to bank, they add up all the points in their current hand, add that sum to their cumulative score, and sit out for the rest of the round. The Second Chance is not worth any points.

If a player chooses to hit, then they will draw a card from the draw pile. If the drawn card doesn’t match any cards in their hand, they add it to their hand. If the drawn card does match a card already in their hand and the player does not have a Second Chance card, then they “bust” and have to sit out for the rest of the round without counting their points. If the player does have a Second Chance card, instead of busting they discard the Second Chance card and drawn card and remain in the current round.

After a player has hit or banked, it becomes the next players turn. If the next player has already banked or busted then their turn will be skipped. After the last player’s turn, it becomes the first player’s turn again. This turn cycle repeats until every player has either banked or busted, after which the round is considered finished.

Usually another round would start after the current round has finished but since Alice, Bob, Charlie, and David are all very impatient, they will just play one round and move on with their lives. Most points wins.

While all players will always hit if they have a Second Chance card, as there is no risk, each player has developed their own unique strategy for when they don’t have one.

  • Alice will always hit until she has $3$ cards after which she will bank

  • Bob will always hit until he has $5$ cards after which he will bank

  • Charlie will always hit until the value of his hand is $20$ or greater; and

  • David will always hit until the value of his hand is $30$ or greater

As a spectator, your friends let you look at the deck before they start playing. Because they are so predictable you realize that you can figure out who will win before they even start playing.However, this would take you a while to figure out so you decide to record the order of the cards in the deck, and write a program to take that list and determine the winner for you.

Input

The first line contains four strings $p_1$, $p_2$, $p_3$, and $p_4$ ($p_1, p_2, p_3, p_4\in \{ \texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}\} $) indicating the order the players are sitting in. For example A C B D indicates that the turn order will be: Alice, Charlie, Bob, David.

The second line contains a single integer $N (8 \le N \le 32)$. The third line contains $N$ integers representing the cards’ order. Where the left most integer is the card at the top of the deck and the right most integer is card at the bottom of the deck. A value of $-1$ represents the Second Chance card and $0$ through $12$ represent the zero point through twelve point cards respectively.

It is guaranteed that the deck will contain at most one $0$ point card, at most one Second Chance card and for each $x \in \{ 1, 2, \dots , 12\} $, at most $x$ cards with value $x$.

It is guaranteed that the players will draw all $N$ cards, and after $N$ draws, each player will either have banked or busted.

Output

Print one of A, B, C, or D. A if Alice will win, B if Bob will win, C if Charlie will win, or D if David will win. It is guaranteed that there will not be a tie.

Sample Input 1 Sample Output 1
A B C D
9
12 12 12 12 11 12 12 12 10
A
Sample Input 2 Sample Output 2
B C D A
11
12 12 12 12 11 12 12 12 10 9 8
B
Sample Input 3 Sample Output 3
C D A B
8
12 12 12 12 11 12 12 12
C
Sample Input 4 Sample Output 4
D A B C
9
12 12 12 12 11 12 12 12 10
D
Sample Input 5 Sample Output 5
A B C D
10
12 12 12 12 -1 12 12 12 12 10
A

Please log in to submit a solution to this problem

Log in