All problems

Ranking Cities by Population, Sorted

mediumPythonMatplotlibBar Chart

A regional briefing at Harbourview Consulting charts population by city. In the order the cities happen to arrive in the file, the chart forces the reader to hunt across the bars for the biggest one, so the briefing ranks them instead: the tallest bar on the left, falling away to the right. Under the chart the same cities are listed in that same ranked order, and it is that list, not the picture, that is checked here. Two cities of exactly equal population keep the order they had in the file.

Task: Print the cities from largest population to smallest.

Input

The first line holds an integer n, the number of cities. Each of the next n lines holds a city name and its population, separated by a single space. A name contains no spaces.

Output

n lines, one city name per line, in decreasing order of population.

Example:

Input:
3
Austin 50
Reno 20
Boise 35

Output:
Austin
Boise
Reno

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…