Prefixes

Consider a collection of words. Sometimes, it is possible to identify each word uniquely from its prefix. For instance, if the collection is {𝚕𝚘𝚟𝚎,𝚑𝚎𝚛𝚘,𝚑𝚎𝚛𝚎,𝚑𝚊𝚕𝚏,𝚢𝚎𝚝}\{ \texttt{love}, \texttt{hero}, \texttt{here}, \texttt{half}, \texttt{yet} \}, a word that starts with l must be love. In the same way, if we know that a word starts with y, it must be yet. However, to identify the word half we need the prefix ha, to identify the word hero as well as here we need to write the whole words.

Your program must print the words in increasing order according to the lenght of the shortest prefix that identifies them. In a event of a tie, it must print the words in lexicographical order.

Input

The input consists of various cases. Each case starts with its number of words n2n \ge 2. nn words follow, each one contains between 1 and 20 lowercase letters. All the words of a collection will be indentifiable with some of its prefixes (eventually, the whole word). That is, no given word will not be prefix of other word of the same case.

Output

For each case, your program must print the prefixes (with the words that they indentify to) in increasing order by length and, in a event of a tie, in lexicographical order. it must separate the output of different cases with a line with 10 dashes.

Scoring

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:56:36.396Z

© Jutge.org, 2006–2026.
https://jutge.org