In the card game Wolf (a variant of the famous card games
War and Svälta räv), two players both have a
pile of cards, which together form a normal deck of playing
cards. Such a deck contains $52$ cards, with each card being a
unique combination of one of $4$ suits and $13$ ranks.
During a turn, each player picks the topmost card from their
piles, and shows it. This process is repeated until the two
cards have the same suit. Then, the player whose card had the
highest rank receives all the cards that have been shown by the
players during the turn (including the two that had the same
suit), and these cards are shuffled into that player’s pile.
The turn then ends. The turn also ends if any player, when they
are supposed to pick a card from their pile, has an empty pile.
A player wins if, after the end of a turn, she has cards
remaining in her pile but the opposing player has no cards
remaining in their pile. This means that the game is tied if
neither player has cards in their pile after the end of a
Your opponent is currently taking a bathroom break, so you
have the opportunity to reshuffle your piles. You cannot
exchange any cards, since your opponent knows the set of cards
in their pile. Is it possible to reshuffle each of the two
piles, so that you have won the game after the next turn?
The first line of input contains the number of cards in your
hand ($0 \leq n \leq 52$).
Each of the next $n$ lines
contains a card specified by a number from $1$ to $13$ and one of the letters
separated by a space.
The letter of a card specifies its suit (either clubs,
diamonds, hearts or spades, respectively). The number of a card
specifies the rank of the card. For simplicity, aces are
represented as a $1$, and
jacks, queens and kings are represented as the numbers
$11$, $12$ and $13$. For the purpose of this problem,
we consider a rank $a$ to
be lower than a rank $b$
if the number of rank $a$
is lower than the number of rank $b$ (meaning aces are of the lowest
Output “possible” if it is
possible to reshuffle the decks, and “impossible” if it is not.
|Sample Input 1
||Sample Output 1
|Sample Input 2
||Sample Output 2