#K53092. Sort Meal Kits by Timestamps

    ID: 29454 Type: Default 1000ms 256MiB

Sort Meal Kits by Timestamps

Sort Meal Kits by Timestamps

You are given multiple datasets representing meal kit orders. Each dataset begins with an integer \(n\) which indicates the number of meal kits, followed by \(n\) lines each containing a meal kit ID and a timestamp in the format YYYY-MM-DD separated by a space. The dataset is terminated by a line containing a single '-' character. Your task is to sort the meal kits in each dataset by their timestamps from oldest to newest and output the meal kit IDs in order. The output should combine the sorted results from all datasets, preserving the dataset order.

Example: Given the input:

3
A124 2022-01-15
B567 2022-01-10
C890 2022-01-12
-
2
D345 2022-05-20
E678 2022-04-15
-

The correct output is:

B567
C890
A124
E678
D345

Note: All dates are valid and in the format YYYY-MM-DD. Sorting by date is equivalent to sorting lexicographically.

inputFormat

The input consists of one or more datasets. Each dataset begins with a line containing an integer \(n\) representing the number of meal kits. This is followed by \(n\) lines, each containing a meal kit ID and a timestamp (in YYYY-MM-DD format) separated by a space. The dataset is terminated by a line containing a single '-' character. All datasets are concatenated together.

outputFormat

Print the meal kit IDs sorted by their timestamps from oldest to newest, each on a new line. The outputs of all datasets should be printed in sequence.

## sample
3
A124 2022-01-15
B567 2022-01-10
C890 2022-01-12
-
2
D345 2022-05-20
E678 2022-04-15
-
B567

C890 A124 E678 D345

</p>