Олимпиадный тренинг

Задача 38596. drunk game


In the game of drunkard, the deck of cards is dealt equally to two players. Next, they reveal one top card at a time, and the one whose card is higher takes both of the revealed cards for himself, which are placed under the bottom of his deck. The one who remains without cards – loses.

For simplicity, we will assume that all cards are different in face value, and also that the lowest card defeats the highest card (“six takes ace”).

The player who takes the cards for himself first places the card of the first player under the bottom of his deck, then the card of the second player (that is, the card of the second player is at the bottom of the deck).

Write a program that simulates a game of drunkard and determines who wins. The game involves 10 cards with values ​​from 0 to 9, the big card beats the smaller one, the card with a value of 0 beats the card 9.

Input
The program receives two lines as input: the first line contains 5 numbers separated by spaces — card numbers of the first player, the second – similarly 5 cards of the second player. Cards are listed from top to bottom, meaning each line starts with the card that will be revealed first.

Imprint
The program should determine who wins the given hand, and output the word first or second, and then print the number of moves made before winning. If the game does not end within 106 moves, the program should output the word botva.
Examples
# Input Output
1 1 3 5 7 9
2 4 6 8 0
second 5