func_code_string: #include <bits/stdc++.h>   using namespace std;   int dir4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   int dir8[8][2] = {{-1, 0}, {1, 0},  {0, 1}, {0, -1},                     {-1, 1}, {1, -1}, {1, 1}, {-1, -1}};   int dir8h[8][2] = {{2, 1}, {-2, -1}, {-1, 2}, {1, -2},                      {1, 2}, {-2, 1},  {2, -1}, {-1, -2}};   long double eps = 1e-7;   const int N = 52;   long long dp[N][N];   vector<string> v[N];   int main() {     ios_base::sync_with_stdio(false);     int n;     string s;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> s;       v[i].push_back(s);       for (long long j = 1; j <= s.size() - 1; j++) {         string s1;         for (long long k = 1; k <= s.size() - 1; k++) s1 += s[k];         s1 += s[0];         v[i].push_back(s1);         s = s1;       }     }     for (long long i = 0; i < n; i++)       for (long long j = 0; j < v[0].size(); j++) dp[i][j] = 1e9;     for (long long i = 0; i < v[0].size(); i++) dp[0][i] = i;     for (long long i = 1; i <= n - 1; i++) {       for (long long j = 0; j < v[i].size(); j++) {         for (long long k = 0; k < v[i - 1].size(); k++)           if (v[i][j] == v[i - 1][k]) dp[i][j] = min(dp[i][j], j + dp[i - 1][k]);       }     }     long long mn = 1e9;     for (long long i = 0; i < v[n - 1].size(); i++) mn = min(mn, dp[n - 1][i]);     if (mn == 1e9)       cout << -1;     else       cout << mn;   }   