#C6970. Most Frequent Words

    ID: 50789 Type: Default 1000ms 256MiB

Most Frequent Words

Most Frequent Words

Given an integer k and a text string, your task is to identify the k most frequently occurring words in the text.

The text may contain punctuation and mixed case letters. You should ignore punctuation and treat words in a case-insensitive manner. In case of ties in the frequency, sort the words in alphabetical order.

Note: Words are defined as sequences of alphanumeric characters (matching the regex \w+).

Example:
For k = 3 and text "hello world! hello code. code, hello.", the answer is: hello code world.

inputFormat

The input is given via standard input (stdin) in the following format:

  1. The first line contains an integer k, the number of most frequent words to output.
  2. The second line contains the text string from which words are to be extracted.

outputFormat

Print the k most frequent words on a single line, separated by a single space.

## sample
3
hello world! hello code. code, hello.
hello code world