#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  char c;
  int x = 0, f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
  return x * f;
}
const int N = 100005;
int a[N];
long long f[N][10];
char s[N], st[N], tp;
const char m[10] = "hard";
bool g[N][10];
int main() {
  int n = gi();
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i) a[i] = gi();
  memset(f, -1, sizeof(f));
  f[0][0] = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < 4; j++) {
      if (m[j] == s[i]) {
        f[i][j + 1] = 1ll << 60;
        for (int k = 0; k <= j + 1; k++)
          f[i][j + 1] = min(f[i][j + 1], max(0ll, f[i - 1][k]));
        if (f[i - 1][j] != -1) f[i][j] = f[i - 1][j] + a[i];
      } else if (m[j - 1] != s[i])
        f[i][j] = f[i - 1][j];
    }
  long long ans = 1ll << 60;
  for (int j = 0; j < 4; j++)
    if (f[n][j] != -1) ans = min(ans, f[n][j]);
  printf("%I64d", ans);
}
