Suffixes of one row
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 256 megabytes
You are given a collection of strings: s[1], s[2], ..., s[n].
Your task is to find a string t
such that at least one of the given strings is a suffix of t
.
Input
The first line contains an integer n
(1 ≤ n ≤ 10^5
), representing the number of strings in the collection. Each of the next n
lines contains one string, where the i
-th line contains the non-empty string s[i].
All strings are composed solely of lowercase Latin letters. The combined length of all strings does not exceed 10^5
.
Output
If such a string t
exists, print it. If there are multiple possible strings t
, print the one with the shortest length.
If no such string t
can be found, print -1
.
Examples
Input #1
Answer #1
Submissions 140
Acceptance rate 25%