#C3444. Most Frequent Words

    ID: 46872 Type: Default 1000ms 256MiB

Most Frequent Words

Most Frequent Words

You are given a sequence of words provided on standard input. The sequence is terminated by a special token # (this token is not part of the input words). Your task is to count the frequency of each word and output the word or words that appear most frequently. If there are multiple words with the same maximum frequency, output all of them in alphabetical order, separated by a single space.

If no valid words are provided (i.e. the input is empty or only contains the termination token), output an empty line.

Note: If a formula is needed, consider the maximum frequency as \(\max_{w}\{frequency(w)\}\).

inputFormat

The input is given on standard input (stdin) as a sequence of words separated by spaces. The input is terminated by a '#' token which should not be considered as part of the data.

outputFormat

Output the most frequent word(s) in a single line, sorted in alphabetical order and separated by a single space. If no valid word is supplied, output an empty line.

## sample
apple #
apple