#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T>
inline T biton(T n, T pos) {
  return n | ((T)1 << pos);
}
template <class T>
inline T bitoff(T n, T pos) {
  return n & ~((T)1 << pos);
}
template <class T>
inline T ison(T n, T pos) {
  return (bool)(n & ((T)1 << pos));
}
template <class T>
inline T gcd(T a, T b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
template <typename T>
string NumberToString(T Number) {
  ostringstream second;
  second << Number;
  return second.str();
}
inline int nxt() {
  int aaa;
  scanf("%d", &aaa);
  return aaa;
}
inline long long int lxt() {
  long long int aaa;
  scanf("%lld", &aaa);
  return aaa;
}
inline double dxt() {
  double aaa;
  scanf("%lf", &aaa);
  return aaa;
}
template <class T>
inline T bigmod(T p, T e, T m) {
  T ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % m;
    p = (p * p) % m;
  }
  return (T)ret;
}
long long int ar[1000010];
vector<pair<char, long long int> > v;
int getLast(int l, int r, char c) {
  for (int i = r; i >= l; i--) {
    if (v[i].first == c) {
      return i;
    }
  }
  return -1;
}
int getFirst(int l, int r, char c) {
  for (int i = l; i <= r; i++) {
    if (v[i].first == c) return i;
  }
  return v.size() + 10;
}
string g = "hard";
long long int dp[100010][5];
long long int go(int pos, int cnt) {
  if (cnt >= 4) return (long long int)3e17;
  if (pos == v.size()) {
    if (cnt == 4) {
      return (long long int)3e17;
    }
    return 0;
  }
  long long int& res = dp[pos][cnt];
  if (res != -1) return res;
  res = (long long int)3e17;
  res = min(res, go(pos + 1, cnt) + v[pos].second);
  res = min(res, go(pos + 1, cnt + (v[pos].first == g[cnt])));
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == 'h' || s[i] == 'r' || s[i] == 'a' || s[i] == 'd') {
      v.push_back(make_pair(s[i], ar[i]));
    }
  }
  long long int ans = 0;
  memset(dp, -1, sizeof(dp));
  ans = go(0, 0);
  cout << ans << endl;
  return 0;
}
