#include <bits/stdc++.h>
using namespace std;
long long modexpo(long long x, long long p) {
  long long res = 1;
  x = x % 1000000007;
  while (p) {
    if (p % 2) res = res * x;
    p >>= 1;
    x = x * x % 1000000007;
    res %= 1000000007;
  }
  return res;
}
struct compare {
  bool operator()(const vector<long long> a, const vector<long long> b) const {
    return (a[0] - a[1]) < (b[0] - b[1]);
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  string s;
  cin >> n >> s;
  long long arr[n + 1];
  arr[0] = 0;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  string t = "hard";
  long long dp[n + 1][5];
  memset(dp, 0, sizeof(dp));
  for (long long i = 0; i < n + 1; i++) {
    for (long long j = 0; j < 5; j++) {
      dp[i][j] = 1e18;
    }
  }
  dp[0][0] = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 4; j++) {
      long long temp = (s[i] == t[j]);
      dp[i + 1][j + temp] = min(dp[i + 1][j + temp], dp[i][j]);
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + arr[i]);
    }
  }
  long long ans = *min_element(dp[n], dp[n] + 4);
  cout << ans << "\n";
}
