Most frequent words P12284


Statement
 

pdf   zip

Write a program that reads a sequence of nn words and prints the kk most frequent (in case of a tie, the smallest in alphabetical order).

Input

Input consists of several cases. Every case starts with nn and kk, followed by nn words made up of only lowercase letters. You can assume that kk is between 1 and the number of different words.

Output

For every case, print the kk most frequent words in order. Print first the most frequent words, and in case of a tie, the smallest words in lexicographical order. Print a line with 10 dashes at the end of each case.

Public test cases
  • Input

    5 1
    hola adeu adeu bye hola
    5 2
    hola adeu adeu bye hola
    5 3
    hola adeu adeu bye hola
    

    Output

    adeu
    ----------
    adeu
    hola
    ----------
    adeu
    hola
    bye
    ----------
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Python
    User solutions
    C++ Haskell Python