#K91187. Most Frequent Word

    ID: 37920 Type: Default 1000ms 256MiB

Most Frequent Word

Most Frequent Word

You are given a list of words. Your task is to find the word that occurs the most number of times in the list when compared in a case-insensitive manner. In other words, treat 'Apple' and 'apple' as the same word. In case two or more words have the same highest frequency, choose the word which appears first in the original input order.

Detailed Explanation:

Assume you have n words. You first convert each word to lowercase. Then count the frequency of each word. Let \(f(w)\) be the frequency of word \(w\). Let \(F = \max\{f(w)\}\). Your answer should be the word \(w\) (in lowercase) such that \(f(w) = F\) and which appears first in the input.

Input Format:

  • The first line contains an integer \(n\) denoting the number of words.
  • The second line contains \(n\) words separated by spaces.

Output Format:

  • Output a single word in lowercase that is the most frequent word. If there is a tie, output the one that appears first.

inputFormat

The input is provided from standard input (stdin) and is structured as follows:

  • The first line contains a single integer \(n\) (\(1 \leq n \leq 10^5\)), the number of words.
  • The second line contains \(n\) words separated by spaces. Each word consists of alphabetical characters.

outputFormat

Print a single word to standard output (stdout) — the word (in lowercase) that occurs most frequently. If more than one word has the maximum frequency, print the one that appears first in the input order.

## sample
1
apple
apple