#P436. 【例76.1】 病人排队

【例76.1】 病人排队

Description

When patients register for medical appointments, write a program to arrange them in the following order:
Elderly patients (age ≥ 6060) are prioritized over non-elderly patients.
Among elderly patients, they are sorted by age in descending order; if ages are the same, they are sorted by registration order.
Non-elderly patients are sorted by registration order.

Input Format

The first line contains a positive integer less than 100100, representing the number of patients.
Following that, each line contains a patient's information in the order of registration, including: a string of length less than 1010 representing the patient's ID (each patient's ID is unique and contains only digits and letters), and an integer representing the patient's age (not exceeding 100100), separated by a single space.

Output Format

Output the patient IDs in the arranged order, one per line.

Sample

5
021075 40
004003 15
010158 67
021033 75
102012 30
021033
010158
021075
004003
102012