#C13616. Sorting Tuples by the Second Element

    ID: 43174 Type: Default 1000ms 256MiB

Sorting Tuples by the Second Element

Sorting Tuples by the Second Element

You are given a list of tuples, where each tuple contains two integers. Your task is to sort these tuples in ascending order based solely on the second element of each tuple. Formally, given a list \(T = [t_1, t_2, \dots, t_n]\) where \(t_i = (a_i, b_i)\), you must produce a list \(T'\) such that for any two tuples \(t_i\) and \(t_j\), if \(b_i < b_j\) then \(t_i\) appears before \(t_j)\) in \(T'\). In cases where the second elements are equal, maintain the original order of appearance (i.e., use a stable sort).

Note that the list can be empty, it can contain a single tuple, or multiple tuples with negative values as well.

inputFormat

The first line of input contains a single integer \(N\), the number of tuples. Each of the following \(N\) lines contains two space-separated integers representing the first and second element of a tuple. All input is read from standard input (stdin).

outputFormat

Output the sorted tuples, one per line, with the two integers separated by a space. The output should be directed to standard output (stdout).

## sample
0