Vladimir is the loneliest child in the neighbourhood. No other kid likes to play with him. His parents decided to cheer him up so they bought him a card game called The Game. This card game is for up to 5 players, but it can also be played in the solo (i.e. single-player) mode.
The package contains 98 regular playing cards that are labeled by integers 2,3,…,99. In addition to these, there are 4 special direction cards. Two of them are labeled with the number 1 (followed by an up arrow) and the other two are labeled with 100 (followed by a down arrow).
In the initial phase of the game, the pile of regular cards is shuffled and placed face down on the table – this will be the draw pile. The four direction cards are placed in a column; the two cards labeled 1 have to be at the top. There should also be enough space on the right-hand side of each direction card – this is where regular cards will be laid during the play. The card labeled 1 initiates an ascending row, while a card labeled 100 initiates a descending row. In the solo mode, the player draws the top 8 cards from the draw pile, one by one, and puts them in his hand.
After the initial phase the game starts. On each turn the player has to play two cards from his hand according to the following rules:
After playing two cards from the hand, the player should draw two new cards from the draw pile, one by one. This concludes his turn. If the draw pile is empty, he continues playing in the same way without drawing new cards. The game ends when the player has no cards left in his hand (in that case the player beats the game) or if he cannot play any of the remaining cards in his hand (in that case the player has lost the game).
Example: Suppose that the player's initial hand (i.e. the first 8 cards which he has drawn) is:
69, 17, 59, 32, 31, 77, 87, 89
He may decide to play the card 89 (putting it in the first descending row) and the card 17 (putting it in the second ascending row). The state of all four rows after the move is:
1 -> 1 -> 17 100 <- 89 100 <-
Then he has to pick up two more cards from the draw pile – suppose these two cards are 84 and 3 – and his hand becomes:
69, 59, 32, 31, 77, 87, 84, 3
In the second turn he might want to play the card 3 (in the first ascending row) and card 87 (in the first descending row, after card 89). The state of all four rows after the move:
1 -> 3 1 -> 17 100 <- 89, 87 100 <-
Vladimir played the game for a few times and he could not always beat the game. Since he hates losing the game, you should write a computer program that will inspect the draw pile and predict the outcome of the game. This will help Vladimir to decide whether he wants to play it or not.
You should also know that Vladimir is a very logical and predictable person. He plays according to the following rules.
When he draws a card, he places it in his hand on the far-right side.
He will always play a card from his hand according to his list of priorities:
Your program should find the final state of the game.
The first (and only) line of the input contains 98 space-separated integers, i.e. some permutation of the set 2,3,…,99 that represents the initial draw pile. The cards are listed in order from top to bottom of the draw pile.
The output contains six lines. The first four lines describe the four rows of cards on the table. The fifth line lists the cards that remained in the player's hand (if any) while the last line lists the cards that remained in the draw pile (if any). Print an empty line in case of an empty list. Cards in the four rows and in the hand should be ordered from left to right, while the cards in the last line, which represents the remainder of the draw pile, should be ordered from top to bottom as in the input data. See also the sample outputs.