Problem B
Concentration
Concentration is a not so popular 2 player card game of both skill and luck. The standard Concentration game is played with one or two 52-card decks, however, for the sake of the problem, we will look at a variation of Concentration.
The rules are as follows:
-
A card is represented by a single integer. Two cards
, are considered “similar” if and only if . A deck consisting of cards is used for each game. More specifically, a deck of cards contains exactly one copy of card for all . -
All cards are initially facing down on a table in random positions, i.e. neither players know what any cards are. Players take turns making moves. Player 0 goes first, then player 1 goes, then player 0 goes, and so on.
-
During each turn, a player chooses two cards and reveals them. If the two cards are “similar”, then they are removed from the table and the player gets to keep them, the player is then granted another turn; this can happen infinitely as long as the player always finds two “similar” cards. If the cards are different, the player’s turn ends.
-
When there are no more cards on the table, the player with more cards wins the game.
Anthony and Matthew like to play this boring game and share an identical play style: whenever they are to choose a card to reveal, if they have knowledge of two “similar” cards, they will pick one of the two “similar” cards; otherwise they will pick a random unknown card to reveal.
Anthony and Matthew are both extremely intelligent and have perfect memories, i.e. they remember every card that has been revealed.
Before the game starts, both Anthony and Matthew make up their minds about in which order they will choose random cards to reveal, in case when they do not have knowledge of two “similar” cards.
Each player’s choices of revelation can be represented by a
permutation of numbers
Similarly, let
Having knowledge of
Input
The first line of input contains one integer
The second line contains
The third line contains
Output
Output a single line with
Sample Input 1 | Sample Output 1 |
---|---|
2 0 1 2 3 0 1 2 3 |
0 |
Sample Input 2 | Sample Output 2 |
---|---|
2 0 2 1 3 0 2 1 3 |
1 |
Sample Input 3 | Sample Output 3 |
---|---|
4 0 1 2 3 4 6 5 7 0 1 2 3 4 6 5 7 |
-1 |