#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long int inf = 1e18;
vector<long long int> a(N);
vector<vector<long long int> > dp(N, vector<long long int>(10, -1));
string p = "hard";
long long int n;
string s;
long long int recur(long long int ind, long long int j) {
  if (j == 4) return inf;
  if (ind == n) return 0;
  long long int &ans = dp[ind][j];
  if (ans != -1) return ans;
  if (p[j] == s[ind]) {
    ans = recur(ind + 1, j + (p[j] == s[ind]));
    ans = min(ans, a[ind] + recur(ind + 1, j));
  } else
    ans = recur(ind + 1, j);
  return ans;
}
void solve() {
  cin >> n >> s;
  for (long long int i = 0; i < n; i++) cin >> a[i];
  cout << recur(0, 0);
}
void debug(long long int tt) {}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
}
