#C441. Top K Frequent Words

    ID: 47945 Type: Default 1000ms 256MiB

Top K Frequent Words

Top K Frequent Words

You are given a list of n words and an integer k. Your task is to find the k most frequent words among the list. In the case of ties (i.e. words with the same frequency), the words should be output in lexicographical (i.e., dictionary) order.

Input Example: For input 5 3 in the first line and apple banana apple orange banana in the second line, the output should be apple banana orange.

Note: The solution must read from the standard input (stdin) and produce the output to the standard output (stdout).

inputFormat

The first line of input contains two space-separated integers, n and k, where n is the number of words and k is the number of most frequent words to find. The second line contains n words separated by spaces.

outputFormat

Output the k most frequent words, separated by a space, following the required ordering.

## sample
6 2
book pen book pencil pen notebook
book pen