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

Задача 38350. Determine the winner


Vasya and Petya are playing the following game. They take a deck of 36 cards. Each card has a number from 1 to 9 written on it and each card is colored in one of 4 colors so that there are exactly 9 cards of each color and they are numbered from 1 to 9. The cards are shuffled and 18 cards are dealt to the players.

Then the players take turns making moves. In one move, a player can put one card on the table according to the following rules. The card with the number 5 can be laid out on the table at any time. A card with a different number can be laid out only if a card of the same color has already been laid out on the table, on which a number is written 1 more or 1 less than on this card (it does not matter whether this card was laid out by you or your opponent, and whether it was placed on the previous move or earlier). If a player can lay out at least some card, he must make a move. If a player cannot lay out a single card, he skips a turn.

The first person to put all their cards on the table wins.

Write a program that, based on information about who got what cards, determines who will win if both players play optimally.

Input
The input file contains 18 pairs of numbers describing the cards that the first player got. Each card is described by two numbers — color number (from 1 to 4) and the number that is written on the card (from 1 to 9). The second player, respectively, got all the other cards.

Imprint
In the output file print a single number (1 or 2) — the number of the player who will win if both players play optimally.
 
Examples
# Input Output
1 1 1
1 2
1 3
14
15
16
17
18
19
2 1
2 2
23
24
25
26
27
28
29
1