This page is still under construction.

Parts of this page are still being built. What you see may change.

Birthday

Interview

Time limit2sMemory limit512 MB

Summary
Given a list of candidate dates and a three-line dialogue between the day-knower and month-knower, determine the unique birthday consistent with all statements.
Level

Medium5 of 10

Topics
Implementation, Simulation, Hash map, Math
Solved
No attempts yet

Problem

Vanya is unsure whether he wants to celebrate his birthday. He decided to tell his friends partial information about the date of his birth, and if they work out the exact date, so be it: the party will happen.

He sent his friend Anya the day of the month in a private message on a social network, and told his friend Borya the month of his birth. Then he posted on his page a list of days of the year, one of which is his birthday, along with a note that Anya knows the day but not the month, and Borya knows the month but not the day.

Then the following dialogue took place in the comments:

Anya: I do not know Vanya's exact birth date, but I am sure that Borya does not know it either.

Borya: At first I did not know Vanya's birth date, but now, after your comment, I know it for sure!

Anya: Wow! Now I know the exact date too!

So when is Vanya's birthday?

Input

The first line contains an integer nn (1≤n≤3661 \le n \le 366), the number of possible dates posted by Vanya on his page.

Each of the next nn lines describes one date: the day and the month number. Months are numbered from 1 to 12.

The dates are given in chronological order within the year.

The situation is guaranteed to be consistent, and there is exactly one possible birth date of Vanya that leads to the described dialogue.

Output

Print Vanya's birth date in the same format: first the day, then the month.

Hint

Recall the number of days in each month. Since Vanya could have been born in a leap year, assume February has 29 days.

Month number123456789101112
Days312931303130313130313031

Examples1

  1. Example 1

    Input
    11
    29 2
    5 5
    16 5
    31 5
    17 6
    18 6
    14 7
    16 7
    5 12
    14 12
    17 12
    
    Expected output
    17 6