#K39797. Most Frequent Word

    ID: 26500 Type: Default 1000ms 256MiB

Most Frequent Word

Most Frequent Word

You are given a list of (n) words. Your task is to determine the word that appears most frequently in the list. In the event of a tie (i.e. multiple words have the same maximum frequency), choose the one which comes first in lexicographical order. Formally, let (f(w)) be the frequency of a word (w) in the list. You need to find a word (w) such that (f(w) = \max_{x} f(x)) and if there exists another word (w') with (f(w') = f(w)), then (w \leq w') (in lexicographical order).

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer (n) ((1 \leq n \leq 10^5)), representing the number of words.
  • The following (n) lines each contain a single word consisting of lowercase letters.

outputFormat

The output is written to standard output (stdout). Output a single line containing the most frequent word. If there is a tie, output the lexicographically smallest word among those with the highest frequency.## sample

1
apple
apple

</p>