#include <bits/stdc++.h>
using namespace std;
long long dp[100005][5];
string s1, s2 = "hard";
long long a[100005], n;
long long solve(long long i, long long j) {
  if (i == n) return 0;
  long long &re = dp[i][j];
  if (re != -1) return re;
  if (s1[i] == s2[j]) {
    re = solve(i + 1, j) + a[i];
    if (j < 3) {
      re = min(re, solve(i + 1, j + 1));
    }
  } else {
    re = solve(i + 1, j);
  }
  return re;
}
int main() {
  cin >> n >> s1;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof dp);
  cout << solve(0, 0) << endl;
}
