#include <bits/stdc++.h>
using namespace std;
const long long MAXN = (int)3e5 + 5;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
long long last[4], first[4], a[100001], dp[4][100001];
string s, h = "hard";
long long calc(long long itr, long long ind) {
  if (ind < 0)
    return 0;
  else if (itr < 0)
    return LLONG_MAX;
  else if (dp[itr][ind] == -1) {
    long long x = 0;
    if (s[ind] == h[itr] && ind >= first[itr] && ind <= last[itr]) x += a[ind];
    return dp[itr][ind] = min(calc(itr - 1, ind), calc(itr, ind - 1) + x);
  } else
    return dp[itr][ind];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  cin >> s;
  long long itr = 0;
  for (long long int i = (long long int)0; i < (long long int)n; i++)
    cin >> a[i];
  for (long long int i = (long long int)0; i < (long long int)n; i++) {
    if (s[i] == h[itr]) {
      first[itr] = i;
      itr++;
    }
    if (itr == 4) break;
  }
  if (itr == 4)
    itr--;
  else {
    cout << 0;
    return 0;
  }
  for (long long i = n - 1; i >= 0; i--) {
    if (s[i] == h[itr]) {
      last[itr] = i;
      itr--;
    }
    if (itr == -1) break;
  }
  for (long long int i = (long long int)0; i < (long long int)4; i++)
    for (long long int j = (long long int)0; j < (long long int)n; j++)
      dp[i][j] = -1;
  cout << calc(3, n - 1);
  return 0;
}
