#C2049. Task Queue Processing

    ID: 45322 Type: Default 1000ms 256MiB

Task Queue Processing

Task Queue Processing

You are given a list of tasks along with their priorities. Your task is to sort the tasks in descending order according to their priority. If two or more tasks have the same priority, they should remain in the same order as they were given in the input (i.e. stable sorting).

The input will start with an integer n representing the number of tasks. Each of the following n lines contains a task description (a single word) and its associated priority (an integer). Your program should output the tasks in order after sorting, where each line contains the task description and its priority, separated by a space.

The mathematical formulation is as follows: Given tasks \(\{(s_i, p_i)\}_{i=1}^{n}\), output them ordered such that for any two tasks \(i\) and \(j\) where \(p_i > p_j\) or \(p_i = p_j\) and \(i < j\), task \(i\) comes before task \(j\).

inputFormat

The first line contains an integer n (\(1 \le n \le 10^5\)) representing the number of tasks. Each of the next n lines contains a string (the task description, which does not contain spaces) and an integer representing the priority, separated by a space.

outputFormat

Output exactly n lines. Each line should contain the task description followed by its priority, separated by a space. The tasks must be in descending order of priority. For tasks with equal priority, maintain the original input order.

## sample
5
task1 2
task2 5
task3 3
task4 1
task5 5
task2 5

task5 5 task3 3 task1 2 task4 1

</p>