#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void rd(T &n) {
  T x = 0, f = 0;
  char ch = 0;
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  n = f ? -x : x;
}
const int maxn = 2e5 + 10;
int a[maxn];
long long dp[maxn][5];
string tmp = "@hard";
char ss[maxn];
int main() {
  int n;
  rd(n);
  scanf("\n%s", ss + 1);
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; ++i) {
    rd(a[i]);
    dp[i][1] = dp[i - 1][1];
    if (ss[i] == 'h') dp[i][1] += a[i];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 2; j <= 4; ++j) {
      if (ss[i] == tmp[j])
        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][4] << endl;
  return 0;
}
