Under construction

Still being built. Things may change

String Parsing

Time limit2sMemory limit256 MB

Summary
Given a dictionary of words, decide whether greedy longest-prefix splitting always works, and if not, output the shortest string it fails on.
Level

Medium7 of 10

Topics
String, String matching, BFS
Solved
No attempts yet

Problem

Algorithms for search systems often depend on a parsing step that splits expressions. Many algorithms exist for this task, and they differ in running time, implementation difficulty, and resource use.

Consider checking whether a string is made of words from a dictionary. The simplest method is a greedy algorithm. At each step, it removes the longest prefix of the string that is a dictionary word on its own. For most strings that are concatenations of dictionary words, this succeeds and splits the string into words. The algorithm is also very easy to implement. However, some strings produce a wrong result. For example, with a dictionary of all English words, "workingrass" is not recognized correctly. The prefix "working" is removed first, and the remainder "rass" cannot be split into words. Yet the string is the concatenation of "work", "in", and "grass".

Not every dictionary is English. For some dictionaries, the greedy algorithm correctly splits every string that is a concatenation of dictionary words. Check whether the given dictionary has this property. If it does not, give an example string that can be split into dictionary words but that the greedy algorithm fails to split. If several such strings exist, output a shortest one, meaning one whose length is not greater than the length of any other. If several shortest ones exist, output any of them.

Input

The first line contains one integer nn (1≤n≤2501 \le n \le 250), the number of words in the dictionary. Each of the next nn lines contains one word. Each word is non-empty and consists only of lowercase Latin letters. The length of each word does not exceed 500 characters.

Output

If such strings exist, print any one of them whose length is not greater than the length of the others. The printed string must contain only lowercase Latin letters. Otherwise, print "Good vocabulary!".

Examples1

  1. Example 1

    Input
    3
    ab
    cd
    abcd
    
    Expected output
    Good vocabulary!