#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 100005;
const ll mod = 1e9 + 7;
ll dp[N][5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x;
  string s, t = "hard";
  cin >> n >> s;
  s = '#' + s;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 4; j++) {
      dp[i][j] = 1e17;
    }
  }
  for (int i = 1; i <= n; i++) {
    cin >> x;
    for (int j = 0; j <= 3; j++) {
      if (t[j] == s[i]) {
        dp[i][j + 1] = dp[i - 1][j];
        dp[i][j] = dp[i - 1][j] + x;
      } else
        dp[i][j] = min(dp[i - 1][j], dp[i][j]);
    }
  }
  ll ans = 1e17;
  for (int i = 0; i <= 3; i++) {
    ans = min(ans, dp[n][i]);
  }
  cout << ans;
  return 0;
}
