Birthday Boy

Interview

Time limit1sMemory limit512 MB

Summary
Given colleagues' birthdays on a non-leap calendar, pick a date not used by anyone that maximizes the gap just before it, breaking ties toward the earliest date after October 27.
Level

Medium6 of 10

Topics
Array, Sorting, Implementation, Brute force
Solved
No attempts yet

Problem

Bobby has just joined a new company, and human resources has asked him to note his birthday on the office calendar. Bobby the Birthday Boy wants to feel special! Also, Bobby the Birthday Boy does not mind lying for attention.

He notices that the longer people have not celebrated a birthday or eaten cake, the more they like it when a new one comes around. So he wants to pick his birthday in such a way that the longest period of time without a birthday possible has just passed. Of course he does not want to share his birthday with any colleague, either.

Can you help him make up a fake birthday to make him feel as special as possible? Bobby does not care about leap years: you can assume every year is not a leap year, and that no one has a birthday on the 29th of February. In case of a tie, Bobby decides to fill in the date that is soonest (strictly) after the current date, the 27th of October, because that means he will get to celebrate his birthday as soon as possible.

Figure 1: Sample case 2. Calendar is from http://printablecalendarholidays.com.

Input

  • One line with a number 1 ≤ n ≤ 100, the number of colleagues Bobby has in his new office.
  • Then follow n lines, each line corresponding to one coworker. Each line gives the name of the colleague (using at most 20 upper or lower case letters) separated from their birthday date by a space. The date is in format mm-dd.

Output

Print the fake birthday date (format: mm-dd) chosen by Bobby.

Examples4

  1. Example 1

    Input
    3
    Henk 01-09
    Roos 09-20
    Pietje 11-11
    
    Expected output
    09-19
    
  2. Example 2

    Input
    16
    Henk 01-09
    Luc 12-31
    Jan 03-22
    Roos 09-20
    Pietje 11-11
    Anne 02-28
    Pierre 09-25
    Dan 12-15
    Lieze 11-17
    Charlotte 05-01
    Lenny 08-02
    Marc 04-25
    Martha 06-12
    John 03-26
    Matthew 01-20
    John 01-20
    
    Expected output
    08-01
    
  3. Example 3

    Input
    3
    JohnIII 04-29
    JohnVI 10-28
    JohnIIX 04-28
    
    Expected output
    04-27
    
  4. Example 4

    Input
    3
    CharlesII 04-30
    CharlesV 10-29
    CharlesVII 04-29
    
    Expected output
    10-28