#C8420. Resident Sorting

    ID: 52401 Type: Default 1000ms 256MiB

Resident Sorting

Resident Sorting

You are given a list of residents, where each resident is described by an integer indicating their age and a string representing their name. Your task is to sort the list of residents primarily by age (in increasing order) and secondarily by name (in lexicographical order).

The sorting criteria can be mathematically defined as follows:

For two residents a and b with ages \(a_{age}\) and \(b_{age}\) and names \(a_{name}\) and \(b_{name}\), resident a comes before resident b if either:

  • \(a_{age} < b_{age}\), or
  • \(a_{age} = b_{age}\) and \(a_{name} < b_{name}\) (in lexicographical order).

After sorting, output each resident on a new line in the format age name.

inputFormat

The first line contains an integer n representing the number of residents.

This is followed by n lines, each containing an integer and a string separated by a space, representing the resident's age and name respectively.

Input Example:

5
30 Alice
22 Bob
30 Charlie
22 Alice
20 David

outputFormat

Output n lines, each containing the age and name of a resident as sorted by the given criteria.

Output Example:

20 David
22 Alice
22 Bob
30 Alice
30 Charlie
## sample
5
30 Alice
22 Bob
30 Charlie
22 Alice
20 David
20 David

22 Alice 22 Bob 30 Alice 30 Charlie

</p>