#K71842. Organize People by Age

    ID: 33621 Type: Default 1000ms 256MiB

Organize People by Age

Organize People by Age

You are given a list of people, where each person is described by a name and an age. Your task is to sort the people first by ascending age and then by name in lexicographical order if the ages are the same. The output should print each person on a new line in the format Name: Age. If the list is empty, print nothing.

More formally, if we denote each person as a tuple \((name, age)\), you need to sort the list so that for any two people \(p\) and \(q\),

[ p < q \quad \text{if and only if} \quad (p.\text{age} < q.\text{age}) \quad \text{or} \quad (p.\text{age} = q.\text{age} \text{ and } p.\text{name} < q.\text{name}). ]

Note: The lexicographical order is the natural order used by strings. For example, "Alice" comes before "Bob".

inputFormat

The input is read from stdin and has the following format:

  1. The first line contains a single integer n indicating the number of people.
  2. The following n lines each contain a person's information with two fields: a string name and an integer age, separated by a space.

If n is 0, it means the list is empty.

outputFormat

The output is written to stdout and should contain the sorted list, one person per line in the format "Name: Age". There should be no extra spaces or blank lines. If the list is empty, output nothing.

## sample
4
Alice 30
Bob 25
Charlie 30
Dora 25
Bob: 25

Dora: 25 Alice: 30 Charlie: 30

</p>