#K83812. Most Frequent Word
Most Frequent Word
Most Frequent Word
Given a string S consisting of lowercase letters and spaces, your task is to determine the word that appears most frequently in S. In the event that multiple words share the same maximum frequency, output the lexicographically smallest word.
The solution should read input from stdin
and write the answer to stdout
.
It is guaranteed that the input string contains at least one word.
Note: All words are composed of lowercase English letters.
Mathematically, if we denote by \( f(w) \) the frequency of the word \( w \) in \( S \), then if \( f(w_1) = f(w_2) = \max_{w \in S}{f(w)} \), the answer is \( \min\{w_1, w_2\} \) under lexicographical order.
inputFormat
The input consists of a single line containing the string S
. The string is made up of lowercase letters and spaces.
outputFormat
Print the most frequent word from the input string. If there are multiple words with the same highest frequency, print the lexicographically smallest one.
## samplehello
hello