The Leaf's Predicted Class
Ashby Mutual also writes pet cover, and the same rule-book machinery sorts those claims by which animal they concern. The end of every path through a rule-book is a leaf — a group of claims that will not be broken up any further. When a new claim follows the rules down to a leaf, the leaf has to answer with one animal, and that answer is settled when the rule-book is built: it is whichever animal the past claims resting in that leaf most often concerned. Leaves are often small, so ties are common enough to need a rule agreed in advance.
Task: Print the animal this leaf will predict.
Input
The first line holds n, the number of animals recorded at this leaf. Each of the next n lines holds an animal's name followed by how many of the leaf's claims concerned it, separated by a space. A name contains no spaces and appears on only one line.
Output
One line holding the predicted animal, spelled exactly as it appeared. If two or more animals are tied on the highest count, print whichever comes first alphabetically.
Example:
Input:
3
cat 30
dog 10
bird 5
Output:
cat
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