func_code_string: #include <bits/stdc++.h>   const long long INF64 = 1e18;   using namespace std;   const long long N = 2e5 + 6;   using namespace std;   vector<pair<long long, long long>> pf;   int main() {     long long n, ans = INF64;     cin >> n;     vector<long long> cost(n, 0);     vector<string> s;     for (int i = 0; i < n; i++) cin >> cost[i];     for (int i = 0; i < n; i++) {       string st;       cin >> st;       s.push_back(st);     }     vector<vector<long long>> dp(n, vector<long long>(2, INF64));     dp[n - 1][0] = 0;     dp[n - 1][1] = cost[n - 1];     for (int i = n - 2; i >= 0; i--) {       string currStr(s[i]), currrevStr(s[i]);       string prevStr(s[i + 1]), prevrevStr(s[i + 1]);       reverse(currrevStr.begin(), currrevStr.end());       reverse(prevrevStr.begin(), prevrevStr.end());       if (currStr.compare(prevStr) <= 0) dp[i][0] = min(dp[i][0], dp[i + 1][0]);       if (currStr.compare(prevrevStr) <= 0)         dp[i][0] = min(dp[i][0], dp[i + 1][1]);       if (currrevStr.compare(prevStr) <= 0)         dp[i][1] = min(dp[i][1], dp[i + 1][0] + cost[i]);       if (currrevStr.compare(prevrevStr) <= 0)         dp[i][1] = min(dp[i][1], dp[i + 1][1] + cost[i]);     }     ans = min(ans, min(dp[0][0], dp[0][1]));     if (ans == INF64)       cout << -1;     else       cout << ans;     return 0;   }   