func_code_string: #include <bits/stdc++.h>   using namespace std;   int en[100004];   long long int dp[100004][3];   string x[100004];   int n;   long long int sol(int i, int ck) {     if (i > n) return 0;     if (dp[i][ck] != -1) return dp[i][ck];     string org = x[i];     long long int ans = 0;     long long int ans1 = 0;     if (!ck) {       string p = x[i - 1];       if (org >= p) {         ans = sol(i + 1, 0);       } else {         ans = 10000000000000000;       }       reverse(org.begin(), org.end());       if (org >= p) {         ans1 = min(ans, sol(i + 1, 1)) + en[i];       } else {         ans1 = 10000000000000000;       }       return dp[i][ck] = min(ans1, ans);     } else {       string p = x[i - 1];       reverse(p.begin(), p.end());       if (org >= p) {         ans = sol(i + 1, 0);       } else {         ans = 10000000000000000;       }       reverse(org.begin(), org.end());       if (org >= p) {         ans1 = min(ans, sol(i + 1, 1) + en[i]);       } else {         ans1 = 10000000000000000;       }       return dp[i][ck] = min(ans, ans1);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &en[i]);     for (int i = 1; i <= n; i++) cin >> x[i];     memset(dp, -1, sizeof dp);     long long int ans = sol(2, 0);     ans = min(ans, en[1] + sol(2, 1));     if (ans == 10000000000000000) ans = -1;     cout << ans << endl;   }   