first commit

This commit is contained in:
Nyagami
2022-12-15 23:51:04 +07:00
commit 87d51fb251
292 changed files with 12623 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import java.util.*;
public class non {
static int turn(String a, String b){
if(a.length() != b.length()) return -1;
String s = a;
for(int i=0;i<=a.length();i++){
if(s.compareTo(b) == 0) return i;
s = s.substring(1) + s.charAt(0);
}
return -1;
}
static void solve(String[] a){
int ans = 1000000;
for(String i: a){
int cnt = 0;
for(String j:a){
int x = turn(j, i);
if(x==-1){
System.out.println(-1);
return;
}
cnt+=x;
}
ans=Math.min(ans, cnt);
}
System.out.println(ans);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String[] a = new String[n];
for(int i=0;i<a.length;i++) a[i] = sc.next();
solve(a);
}
}