#C12632. Most Frequent Word

    ID: 42081 Type: Default 1000ms 256MiB

Most Frequent Word

Most Frequent Word

You are given a text containing a paragraph of words. Your task is to find the word that appears most frequently. The comparison should be case-insensitive and punctuation should be ignored. In other words, you need to perform the following operations:

  • Convert the text to lowercase.
  • Remove all punctuation. (A character is considered punctuation if it does not match the regex $[^\w\s]$.)
  • Split the text into words by whitespace.
  • Determine the word with the highest frequency. In the case of a tie, you can output any one of them.

The solution should compute and output the most frequent word along with its frequency, separated by a space. The problem can be mathematically interpreted as follows:

Let \( W = \{w_1, w_2, \dots, w_n\} \) be the list of words obtained after preprocessing. You need to find \( w^* \) such that \[ \text{count}(w^*) = \max_{w \in W} \text{count}(w). \]

inputFormat

The input is read from standard input (stdin) and consists of one or more lines, which together form the text to be analyzed.

outputFormat

Output to standard output (stdout) the most frequent word followed by a space and then its frequency.

## sample
Hello world! Hello everyone. This is a test. Hello test world.
hello 3