#include <bits/stdc++.h>
using namespace std;
void mahakal() {}
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, 1, 0, -1};
char c[4] = {'D', 'R', 'U', 'L'};
const long long maxN = 2e5 + 5;
long long n, a[maxN], dp[maxN][5];
string second, t;
void solve() {
  cin >> n >> second;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  second = " " + second;
  t = " hard";
  memset(dp, 0x3f, sizeof dp);
  for (long long i = 1; i <= 4; i++) dp[0][i] = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= 4; j++) {
      if (second[i] != t[j]) {
        dp[i][j] = dp[i - 1][j];
      } else {
        dp[i][j] = min(dp[i - 1][j] + a[i], dp[i - 1][j - 1]);
      }
    }
  }
  long long ans = dp[n][4];
  cout << ans << endl;
}
int main() {
  mahakal();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) solve();
  cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs"
       << endl;
  return 0;
}
