This page is still under construction.

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

Birthday

Interview

Time limit1sMemory limit128 MB

Summary
Given each student's name and birthday, print the name of the youngest student, then the oldest.
Level

Easy2 of 10

Topics
Implementation, Sorting, Array
Solved
No attempts yet

Problem

Given the birthdays of the students in a class, write a program that finds the youngest student and the oldest student.

Input

The first line contains the number of students nn in the class. (1≤n≤1001 \le n \le 100)

Each of the next nn lines contains a student's name and birthday in the format "name dd mm yyyy". The name is that student's name, consisting of at most 15 characters. dd, mm, and yyyy are the day, month, and year of the birthday. (1990≤yyyy≤20101990 \le yyyy \le 2010, 1≤mm≤121 \le mm \le 12, 1≤dd≤311 \le dd \le 31) Every given birthday is a valid date, and the year, month, and day do not have leading zeros.

No two students share the same name or the same birthday.

Output

Print the name of the youngest student on the first line, and the name of the oldest student on the second line.

Examples1

  1. Example 1

    Input
    5
    Mickey 1 10 1991
    Alice 30 12 1990
    Tom 15 8 1993
    Jerry 18 9 1990
    Garfield 20 9 1990
    
    Expected output
    Tom
    Jerry