Mobile coding works. A laptop is faster for long sessions.

Problem

Read from standard input a non-negative integer n, followed by n pairs each consisting of a word (no spaces, letters only) and a non-negative integer representing the frequency of that word. Print the n pairs in decreasing order of frequency. For equal frequencies, use lexicographically increasing order of the words.

Data is read from standard input (in the format described), not from a file.

Input format

Input input.txt

The first line contains `n`. Each of the following `n` lines contains a word (at most `30` characters) and its frequency, separated by a space. - `1 <= n <= 100` - frequency is between `1` and `1000000` - words are unique and consist of lowercase or uppercase letters

Output format

Output output.txt

The program prints `n` lines, each containing the word and its frequency separated by a space, in the required order.

Example

input
4
mar 2
para 5
cais 5
prun 1
output
cais 5
para 5
mar 2
prun 1

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output