#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s, p = "hard";
  cin >> n >> s;
  vector<long long> c(n);
  for (int i = 0; i < n; i++) cin >> c[i];
  vector<vector<long long> > dp(n + 1, vector<long long>(5, 1e18));
  for (int j = 0; j < 4; j++) dp[0][j] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 4; j++) {
      if (s[i] != p[j])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      else {
        dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + c[i]);
      }
    }
  long long ans = LLONG_MAX;
  for (int j = 0; j < 4; j++) ans = min(ans, dp[n][j]);
  cout << ans << endl;
  return 0;
}
