#Z17105. 病人排队

病人排队

Description

Patients register for medical consultation. Write a program to prioritize the order of consultation for registered patients based on the following principles:

  1. Elderly patients (age >= 60) take precedence over non-elderly patients.
  2. Among elderly patients, priority is given to those with higher ages. If ages are the same, the order of registration determines priority.
  3. Non-elderly patients are prioritized based on their order of registration.

Input Format

  • Line 1: Input a positive integer less than 100, representing the number of patients.
  • Subsequent lines: Input patient information in the order of registration. Each line includes:
    • A string of length less than 10 representing the patient's ID (each ID is unique and contains only numbers and letters).
    • An integer representing the patient's age.
    • Separate the ID and age with a single space.

Output Format

Output the patient IDs in the determined consultation order, one per line.

5
021075 40
004003 15
010158 67
021033 75
102012 30


021033
010158
021075
004003
102012