#include <bits/stdc++.h>
using namespace std;
long long uklanjanje[100005];
string stat;
int n;
long long dp[100005][5];
string h = "hard";
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  cin >> n;
  cin >> stat;
  for (int i = 0; i < n; i++) cin >> uklanjanje[i];
  for (int i = 0; i < 100005; i++)
    for (int j = 0; j < 5; j++) dp[i][j] = 1e18;
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      dp[i + 1][j + (stat[i] == h[j])] =
          min(dp[i + 1][j + (stat[i] == h[j])], dp[i][j]);
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + uklanjanje[i]);
    }
  }
  cout << *min_element(dp[n], dp[n] + 4);
  return 0;
}
