#D1058. Code

Code

题面翻译

Lucy 正在学习算法,但是她学的不是很好。

她根据所学的内容,给长度为 nn 的字符集构造了一个编码表。

比如,当 n=3n=3 时,她构造了这样的一个编码表:a:0,b:1,c:01a:0,b:1,c:01

然后,她会用这个表去压缩数据。

比如:ab:01,abc:0101,acb:0011ab:01,abc:0101,acb:0011

但是在某些例子中,她的编码是有歧义的。比如 0101 既可以解码为 "ab",又可以解码为 "c"。

她的体育老师找到了这个问题,并且告诉了她。但是她不这么认为。

现在请帮他的体育老师找到一个最短的 0101 串,使得至少包含两种解码方法。

输入格式

第一行包括一个正整数 n(1n100)n(1\leq n \leq 100),即字符集的大小。

接下来 nn 行,第 ii 行包括一个 0101sis_i,代表第 ii 个字符。

所有 si|s_i| 之和不超过 50005000,对于每一对 i,j(i<j)i,j(i\lt j)sisjs_i\neq s_j

输出格式

如果答案存在,输出答案。否则输出 1-1

题目描述

Lucy is studying coding algorithm , but she doesn't study well .

According to what she learned, she constructed a coding table for the character set with length nn .

For example , n=3n=3 , she constructed the coding table like this : a:0,b:1,c:01a:0,b:1,c:01 .

Then , she used the table to compress data . For example : ab:01,abc:0101,acb:0011ab:01,abc:0101,acb:0011 .

But in some cases, her code will be ambiguous . Such as 0101 can decoding as both ''ab'' or ''c'' .

Her physical education teacher found this problem and told her , but she didn't think so .

Now please help her physical education teacher find the minimum length of 0101 string , which has at least two decoding methods .

输入格式

The first line contains one integer n(1n100)n(1\leq n \leq 100) , indicates the size of character set .

Then nn lines , the ithi-th line contains a 0101 string sis_i, represents the code of the ithi-th character .

The sum of si|s_i| will not exceed 50005000 , for every pair i,j(i<j)i,j(i<j) , sisjs_i\neq s_j.

输出格式

If the answer exists , print the answer , otherwise print 1-1 instead .

样例 #1

样例输入 #1

3
0
1
01

样例输出 #1

2

样例 #2

样例输入 #2

4
00
01
11
10

样例输出 #2

-1