func_code_string: #include <bits/stdc++.h>   using namespace std;   void USACO(string s) {     ios_base::sync_with_stdio(0);     cin.tie(0);     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   const long long MAXN = 5010;   void solve() {     long long n;     string s;     cin >> n;     cin >> s;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     long long dp[n][4];     memset(dp, 0, sizeof(dp));     dp[0][0] = (s[0] !=  h  ? 0 : a[0]);     dp[0][1] = (s[0] ==  h  ? 0 : 1e15);     dp[0][2] = dp[0][3] = 1e15;     for (long long i = 1; i < n; i++) {       dp[i][0] = dp[i][1] = dp[i][2] = dp[i][3] = 1e15;       dp[i][0] = dp[i - 1][0] + (s[i] ==  h  ? a[i] : 0);       if (s[i] ==  h ) dp[i][1] = dp[i - 1][0];       dp[i][1] = min(dp[i][1], dp[i - 1][1] + (s[i] ==  a  ? a[i] : 0));       if (s[i] ==  a ) dp[i][2] = dp[i - 1][1];       dp[i][2] = min(dp[i][2], dp[i - 1][2] + (s[i] ==  r  ? a[i] : 0));       if (s[i] ==  r ) dp[i][3] = dp[i - 1][2];       dp[i][3] = min(dp[i][3], dp[i - 1][3] + (s[i] ==  d  ? a[i] : 0));     }     cout << min(min(dp[n - 1][0], dp[n - 1][1]), min(dp[n - 1][2], dp[n - 1][3]))          <<   n ;   }   int main() { solve(); }   