The City’s Favorite Car
A research analyst is studying last year’s car purchases to see which car brands are most popular in different cities. Each purchase record tells which city the car was bought in and which brand it was.
Your task is to build a simple report: for each city, find the most frequently purchased brand.

The first line of the input contains a single integer n
- the number of purchase records from last year.
The next n
lines each contain two space-separated words: a city
and a brand
(the words don't contain spaces).
The program should print one line per city: the city name, followed by a space, followed by the most popular brand in that city.
If there is a tie in a city (two or more brands with the same highest count), print the alphabetically smallest brand for that city.
Print the cities in alphabetical order.
Input | Output |
---|---|
8 | Ogdenville Ford |
6 | A Alfa |
5 | Metropolis Audi |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB