#include <bits/stdc++.h>
using namespace std;
map<string, pair<long long int, long long int> > mp;
long long int dp[100001][4];
int32_t main() {
  long long int tt;
  tt = 1;
  while (tt--) {
    string h = "hard";
    long long int n;
    cin >> n;
    long long int a[n];
    string s;
    cin >> s;
    for (long long int i = 0; i < n; i++) cin >> a[i];
    if (s[0] == 'h') {
      dp[0][0] = a[0];
    }
    for (long long int i = 1; i < n; i++) {
      for (long long int j = 0; j < 4; j++) {
        if (s[i] == h[j]) {
          if (s[i] == 'h')
            dp[i][j] = dp[i - 1][j] + a[i];
          else
            dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j] + a[i]);
        } else
          dp[i][j] = dp[i - 1][j];
      }
    }
    cout << dp[n - 1][3];
  }
  return 0;
}
