Birthday
InterviewTime limit2sMemory limit512 MB
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 (), the number of possible dates posted by Vanya on his page.
Each of the next 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.