#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long int LINF = 1e18;
char s[N];
int n, a[N];
long long int dp[N][10];
long long int f(int cur, int pos) {
  if (pos >= 4) return LINF;
  if (cur == n + 1) return 0;
  long long int &res = dp[cur][pos];
  if (res != -1) return res;
  res = f(cur + 1, pos) + a[cur];
  if (s[cur] == 'h')
    res = min(res, f(cur + 1, pos + (pos == 0)));
  else if (s[cur] == 'a')
    res = min(res, f(cur + 1, pos + (pos == 1)));
  else if (s[cur] == 'r')
    res = min(res, f(cur + 1, pos + (pos == 2)));
  else if (s[cur] == 'd')
    res = min(res, f(cur + 1, pos + (pos == 3)));
  else
    res = min(res, f(cur + 1, pos));
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> (s + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  memset(dp, -1, sizeof dp);
  cout << f(1, 0) << endl;
}
