eolymp
bolt
Try our new interface for solving problems
Problems

Concatenation

Concatenation

Consider two strings \textbf{α} and \textbf{β}. Their concatenation is a string, the resulting attribution to the string \textbf{α} then string \textbf{β}. This string is denoted by \textbf{αβ}. For example, string concatenation '\textbf{ab}' and '\textbf{ac}' is the string '\textbf{abac}'. It is obvious that this definition naturally extends to the concatenation of any number of rows. Thus, the concatenation of zero rows will be empty, and the concatenation of one string to itself. Consider a set \textbf{W}, consisting of string. We call it the closure of the set \textbf{W^\{*\}}, consisting of those and only those strings that can be obtained by concatenating zero or more strings from the set \textbf{W}. Thus, the set \textbf{W^\{*\}} is an empty string, and if the string \textbf{α} belongs to \textbf{W^\{*\}}, and the string \textbf{β} belongs to \textbf{W}, the string \textbf{αβ} belongs to \textbf{W^\{*\}}. Moreover, all the elements of \textbf{W^\{*\}} can be represented in such a way that is, \textbf{W^\{*\}} is the intersection of all sets with the above properties. For example, if \textbf{W=\{a,ab\}}, then \textbf{W^\{*\}} consists of all strings in which the front of each letter '\textbf{b}' is at least one letter '\textbf{a}'. Given a set of strings \textbf{W}. Required to find a set \textbf{X}, such that \textbf{W^\{*\}=X^\{*\}} and \textbf{X} has the minimum possible number of elements. If several such sets, fits any of them. For example, if \textbf{W=\{a,aabb,ab,ac,b,bac\}}, then the only set satisfying the conditions of the problem will be set \textbf{\{a,ac,b\}}. \InputFile The input file consists of a set of strings, each of which is an element of \textbf{W}. Each string of the set \textbf{W} is found in the input file at least once. The total length of all strings in the input file does not exceed \textbf{10^4}. The number of rows in the input file does not exceed \textbf{10^4}. After each string of \textbf{W} in the input file is a line (a pair of characters with ASCII codes \textbf{13} and \textbf{10}). The lines are composed of characters with ASCII codes from \textbf{33} to \textbf{126} inclusive. \OutputFile Derive the output file elements lexicographically minimal set X, satisfying the conditions of the problem. Each row of X must be printed only once. The lines must go to the lexicographic order (the lexicographic ordering used in dictionaries, in that order string '\textbf{ab}\textit{'} lower string '\textbf{aba}\textit{'} and string '\textbf{ab}\textit{'} lower string '\textbf{ac}\textit{'}).
Time limit 1 second
Memory limit 64 MiB
Input example #1
a
aabb
ab
ac
b
bac
Output example #1
a
ac
b