All problems

The Majority Vote

easyPythonK-Nearest Neighbors

When Marlow Utilities logs a new fault, the system first pulls out the handful of past faults that most resemble it. Each of those past faults carries the repair category it eventually turned out to need, and those categories are what arrives here — the resemblance work is already done. The dispatcher wants one category booked against the new job, and the shortlists are short enough that two categories tie surprisingly often, so the tie rule has to be fixed in advance rather than left to chance.

Task: Print the category named by the most of the shortlisted past faults.

Input

Two lines. The first holds n, the number of shortlisted faults. The second holds n category names separated by single spaces. A name contains no spaces and may repeat.

Output

One line holding the winning category name, spelled exactly as it appeared. If two or more names are named the same number of times, print whichever comes first alphabetically — names are compared as plain text, so capitals sort ahead of lowercase.

Example:

Input:
3
A A B

Output:
A

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…