eolymp
bolt
Try our new interface for solving problems
Problems

Amin’s Research

Amin’s Research

\includegraphics{https://eolympusercontent.com/images/0agv7ebr91003eavpvjc86ddqc.gif} Amin is employed at KAIST’s network security laboratory, focusing on researching the security of the university’s network. The network has $n$ strings, denoted as $s_1, s_2, ..., s_n$, each composed of lowercase English letters. Amin can perform a single move by selecting a string $s_i$, removing its first character, and appending it to the end. For example, transforming “$iddacup$” to “$ddacupi$” in one move. The security level of the network is determined by the minimum number of moves required to make all strings identical. Amin possesses the necessary data. Your task is to assist him by writing a program to compute the security level of the network. \InputFile The first line contains integer $n~(1 \le n \le 50)$ --- the number of strings. This is followed by $n$ lines each containing a string. The $i$-th of these lines corresponds to the string $s_i$. Lengths of strings are equal. The length of each string is positive and doesn’t exceed $50$. \OutputFile Print the security level of the network --- the minimum number of moves Amin needs in order to make all the strings equal or $-1$ if it is not possible. \Scoring In this task, points are awarded for each correct test. The maximum score is $100$.
Time limit 1 second
Memory limit 128 MiB
Input example #1
4
xzzwo
zwoxz
zzwox
xzzwo
Output example #1
5
Input example #2
2
iddacup
ddacupc
Output example #2
-1
Input example #3
3
iddacup
ddacupi
dacupid
Output example #3
3
Source 2024, IDDA Cup, March 31, Problem B