Hide

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:

  1. A card is represented by a single integer. Two cards i, j are considered “similar” if and only if i/2=j/2. A deck consisting of 2N cards is used for each game. More specifically, a deck of 2N cards contains exactly one copy of card i for all 0i<2N.

  2. 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.

  3. 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.

  4. 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 [0,,2N1]. For example, let σ0, a permutation of [0,,2N1] be the “random” choices of Anthony. When Anthony is to choose an unknown card, he will choose the smallest i such that σ0(i) is not revealed, and reveal σ0(i).

Similarly, let σ1 be the choices of Matthew.

Having knowledge of σ0 and σ1, we should be able to perfectly determine the winner (and win lots of money by betting on that player), and it is your job to do exactly that!

Input

The first line of input contains one integer 1N106.

The second line contains 2N integers, with the i-th integer being σ0(i). This line defines σ0.

The third line contains 2N integers, with the i-th integer being σ1(i). This line defines σ1.

Output

Output a single line with 0 if Anthony wins, 1 if Matthew wins, or 1 if the game ties.

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
Hide

Please log in to submit a solution to this problem

Log in