#C2201. Trending Words Extraction

    ID: 45492 Type: Default 1000ms 256MiB

Trending Words Extraction

You are given a text string and an integer k. Your task is to extract the top k trending words from the text. A word is defined as a contiguous sequence of alphanumeric characters or a hashtag (which starts with '#' followed by alphanumeric characters). The extraction should be performed in a case-insensitive manner. Common English stop words (such as the, is, at, which, on, and, a, an, in, of, to, with, for, by, from, as, it, that, this, these, those, are, were, was, be, been, will, do, did, does) must be ignored.

The words are ranked primarily by their frequency in the text (in descending order) and secondarily by their order of first appearance in the text if frequencies are tied. Formally, if f(w) denotes the frequency of a word w and pos(w) its first position, you must sort words by:

$$\text{Sort order: } w_1 \prec w_2 \text{ if } f(w_1) > f(w_2) \quad \text{or} \quad \big(f(w_1)=f(w_2) \text{ and } pos(w_1) < pos(w_2)\big). $$

Output the top k words separated by a single space in one line. If no valid word is found, output an empty line.

inputFormat

Input Format:

  • The first line contains an integer k.
  • The second line contains a text string.

You should read input from stdin.

outputFormat

Output Format:

Output a single line with the top k trending words separated by a single space. If there are no valid words, output an empty line. Write the output to stdout.

## sample
3
The quick brown fox jumps over the lazy dog. The dog, in turn, barked at the fox. The fox didn't care.
fox dog quick