#t550. 病人排队

病人排队

Patient Queue

Problem Description

Write a program that orders registered patients for seeing the doctor according to the following rules:

  1. Elderly patients (age ≥60\ge 60) are seen before non-elderly patients.
  2. Among the elderly, order by age descending; patients with the same age are ordered by their registration order.
  3. Non-elderly patients are ordered by their registration order.

Input Format

The first line contains a positive integer nn (n<100n < 100), the number of patients.

Then, in registration order, each line contains one patient's information: a string of length less than 1010 as the patient's ID (each patient's ID is distinct and consists only of digits and letters), and an integer as the patient's age, separated by a single space.

Output Format

Output the patients' IDs in the arranged order, one per line.

Sample Input

5
021075 40
004003 15
010158 67
021033 75
102012 30

Sample Output

021033
010158
021075
004003
102012

Sample Explanation

There are 55 patients in the sample. Elderly means age not less than 6060, so the patient with age 6767 (ID 010158) and the patient with age 7575 (ID 021033) are elderly. The elderly are ordered by age descending: ID 021033 (age 7575) comes before ID 010158 (age 6767). The non-elderly are ordered by registration order: ID 021075 (age 4040), ID 004003 (age 1515), ID 102012 (age 3030). Merging the elderly and non-elderly by the rules gives the order: ID 021033, ID 010158, ID 021075, ID 004003, ID 102012. Hence the output above.

Constraints

  • 1≤n<1001 \le n < 100, where nn is the number of patients.
  • Each patient's ID has length less than 1010, consists only of digits and letters, and all patients' IDs are distinct.
  • Each patient's age is an integer.