Under construction

Still being built. Things may change

Graduation Photo

Interview

Time limit1sMemory limit512 MB

Summary
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 50,00050,000. 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.

  1. Choose the (place, time slot) pair submitted by the most people.
  2. 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'].
  3. 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 NN. (1≤1 \le NN ≤100 \le 100)

The next NN 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 1010.

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.

Examples3

  1. Example 1

    Input
    8
    suhwan cockpit 1 4
    koosaga wing 3 5
    youngjin elevator 4 7
    suhwan aileron 1 10
    minjae cockpit 2 6
    dohun wing 2 5
    range aileron 2 5
    minchodan aileron 5 7
    
    Expected output
    cockpit 2 4
    
  2. Example 2

    Input
    4
    korea ab 1 6
    aero a 1 2
    space aa 1 4
    univ ba 1 8
    
    Expected output
    a 1 2
    
  3. Example 3

    Input
    9
    best dp 24409 28052
    friend gop 14993 35460
    strong gp 2790 21051
    friend gop 35482 44328
    strong dp 39442 40134
    soldier gop 10825 40544
    soldier dp 12059 13537
    strong gp 48778 49362
    udt gp 37117 40201
    
    Expected output
    gop 14993 35460