#K8866. Most Frequent Word

    ID: 37358 Type: Default 1000ms 256MiB

Most Frequent Word

Most Frequent Word

Given a list of words, you are required to find the word that appears the maximum number of times. In case there is a tie, choose the word that comes first in lexicographical order.

This can be formulated as follows: Given a list \(S = [w_1, w_2, \dots, w_n]\), find a word \(w\) such that its frequency \(f(w)\) is maximized. If there are multiple words with the same maximum frequency, output the lexicographically smallest one.

Note: The input is guaranteed to contain at least one word.

inputFormat

The first line contains one integer (n) ((1 \le n \le 10^5)), representing the number of words. The second line contains (n) words separated by spaces.

outputFormat

Output a single word which appears most frequently. If multiple words tie for the maximum frequency, output the one that is lexicographically smallest.## sample

1
apple
apple

</p>