#K6851. Word Frequency Analysis

    ID: 32880 Type: Default 1000ms 256MiB

Word Frequency Analysis

Word Frequency Analysis

Given a document as a string, count the frequency of each word after removing all punctuation and converting all letters to lowercase. Then, output each unique word along with its frequency. The output must be sorted primarily by the frequency in descending order, and by lexicographical (alphabetical) order in ascending order for words with the same frequency. Specifically, if a word appears \( f \) times, it should be output as:

\( \text{word} \ f \)

Ensure your solution reads from standard input (stdin) and prints the result to standard output (stdout) exactly as specified.

inputFormat

The input consists of a single document string read from standard input. The document may include letters, numbers, whitespace, and punctuation.

outputFormat

For each unique word in the document, output a line containing the word and its frequency separated by a space. The words must be sorted by descending frequency. If two words have the same frequency, they should be ordered in ascending lexicographical order.

## sample
Hello, world! World is great. Hello again, world.
world 3

hello 2 again 1 great 1 is 1

</p>