Martian language - MarisaOJ: Marisa Online Judge

Martian language

Time limit: 1000 ms
Memory limit: 256 MB
The Martian alphabet consists of the same 26 letters as the English alphabet, but they may be arranged in a different order. Recently, scientists discovered a stone on which $n$ Martian strings were carved. These strings are known to follow the lexicographical order according to the Martian alphabet. Based on the given strings, the scientists need to determine a possible order of the Martian alphabet. _Lexicographic order is an ordering of strings or words based on the alphabetical order of their individual characters. It compares characters from left to right and the first character that differs between two strings determines their order in the lexicographic order._ ### Input - The first line contains an integer $n$. - The next $n$ lines, each line contains a string consisting of lowercase letters. ### Output - Print a string consisting of 26 lowercase characters, the alphabet, or print `-1` if there is no satisfied alphabet. If there are multiple satisfied alphabets, print any. ### Constraints - $1 \le n \le 200$. - String length does not exceed $200$. ### Example Input: ``` 3 bc ba ab ``` Output: ``` bcadefghijklmnopqrstuvwxyz ```