Description
There is one very popular card game for little children – “Voina”. Most of us played this game before and it is well known for being pretty easy. So, in this task you will implement a slightly different version of the game.
There are two players. Each of them have cards in their hands. Cards consist of a number and an English letter – something like “11f”, “53g”, “55g”, “3k”, “66666p”.
Every turn of the game, each of the players puts his top (longest been in deck) card on the field. The player with the bigger card (higher number) gets both cards and puts them in the bottom of his deck.
It is easy when there is a clear winner, but what happens when the cards’ numbers are equal. Then every player has to put 3 more cards on the field. Again check for winner, but this time you need to check for the bigger sum of letters at the end of the cards. Each letter represents their position in the English alphabet a -> 1, b -> 2, c -> 3 etc. The player with the biggest sum of these 3 cards collects all cards from the field and put them in his deck. If there is a draw, the players put 3 new cards from their decks.
When you find the result, end the turn and all cards from the field go to the winner hand. Cards are added in descending order:
Hand <- “111f”, “111a”, “99p”, “77a”, “55a”, “8p”
The game ends under two conditions – if any of the players loses all his cards, he loses the game. After 1000000 turns, if both players still have cards, the player with more cards wins the game.
Input
On the first line you will receive the first players’ cards separated with a space.
On the second line you will receive the second players’ cards separated with a space.
Output
You need to print a single line with the winner or draw: “{Result} after {turns} turns”
Constraints
• Each player will have N cards, where 1 < N < 1000
• Each number will contain an integer with a single letter at the end
• Time limit: 0.3 sec. Memory limit: 16 MB.
Examples
Input Output
20y 28j 45s 21i 81i
26z 9f 80a 68g 67z First player wins after 25 turns
Input Output
111j 33k 88k 99p 77k 5p 111j 33k 88k 99p 77k 5p 111j 33k 88k 99p 77k 5p 6p
111j 33k 88k 99p 77k 5p 111j 33k 88k 99p 77k 5p 111j 33k 88k 99p 77k 5p 6p Draw after 1 turns
Input Output
111j 33k 88k 99p 77k 5p 111j 33k 88k 99p 77k 5p 111j 33k 88k 99p 77k 5p 6p
111j 33k 88k 99p 77k 5p 111j 33k 88k 99p 77k 5p 111j 33k 88k 99p 77k 5p 6a
First player wins after 1 turns




Reviews
There are no reviews yet.