|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||512 MB||22||18||18||81.818%|
A friend of yours is designing an encoding scheme of a set of characters into a set of variable length bit sequences. You are asked to check whether the encoding is ambiguous or not. In an encoding scheme, characters are given distinct bit sequences of possibly different lengths as their codes. A character sequence is encoded into a bit sequence which is the concatenation of the codes of the characters in the string in the order of their appearances. An encoding scheme is said to be ambiguous if there exist two different character sequences encoded into exactly the same bit sequence. Such a bit sequence is called an “ambiguous binary sequence”.
For example, encoding characters “A”, “B”, and “C” to 0, 01 and 10, respectively, is ambiguous. This scheme encodes two different character strings “AC” and “BA” into the same bit sequence 010.
The input consists of a single test case of the following format.
n w1 . . . wn
Here, n is the size of the set of characters to encode (1 ≤ n ≤ 1000). The i-th line of the following n lines, wi, gives the bit sequence for the i-th character as a non-empty sequence of at most 16 binary digits, 0 or 1. Note that different characters are given different codes, that is, wi ≠ wj for i ≠ j.
If the given encoding is ambiguous, print in a line the number of bits in the shortest ambiguous binary sequence. Output zero, otherwise.
3 0 01 10
3 00 01 1
3 00 10 1
10 1001 1011 01000 00011 01011 1010 00100 10011 11110 0110
3 1101 1 10