Graduation Photo
InterviewTime limit1sMemory limit512 MB
Deduplicate submissions by name, then find the (place, time) pair with the most people, breaking ties by lexicographically smallest place and earliest time.
- Level
Medium5 of 10
- Topics
- Hash map, Sorting, Implementation, String
- Solved
- No attempts yet
Problem
Korea Aerospace University has a large airplane that arrived this year.

The A300 model next to the main building of Korea Aerospace University
Everyone attending this year's graduation ceremony wants a photo with the airplane in view, but the ceremony lasts only one day, so not everyone can shoot at the place and time they want.
So the school decided to collect desired places and time slots the day before the ceremony and announce the expected crowded place and time slot, so that as many people as possible can shoot.
A submission has the following values.
- Student name (name): the name of the student who submitted. It is a single word of at most 10 lowercase English letters with no spaces. If a student submits more than once, every submission except the first is ignored.
- Place (place): the place where the student wants to shoot. It is a single word of at most 20 lowercase English letters with no spaces.
- Time slot (time): the time slot in which the student wants to shoot. It is given as two times separated by a space, and each time is a positive integer at most . The first time is the shooting start time and the second time is the shooting end time. The end time is always greater than the start time.
Using the list of submitted places and time slots, the school announces the crowded place and time slot as follows.
- Choose the (place, time slot) pair submitted by the most people.
- If more than one slot qualifies in step 1, choose the place that comes first in lexicographic order. Lexicographic order follows ASCII order. For example, sorting the array ['ab', 'a', 'aa', ba'] gives ['a', 'aa', 'ab', 'ba'].
- If the place chosen in step 2 has more than one most-submitted time slot, choose the earliest time slot.
Input
The first line gives the number of submissions . ( )
The next lines give one submission each, with its information name, place, time. The empty string is never given as input.
The number of distinct places (place) in the input is at most .
Output
On the first line, print the crowded (place, time slot) pair that the school is expected to announce, separated by a space. The time slot means the longest one satisfying the condition.