#include <bits/stdc++.h>
using namespace std;
string hard = "hard";
const long long INF64 = 1e18;
long long dp[100005][5];
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> ambiguity;
  for (int i = 0; i < n; i++) {
    int aux;
    cin >> aux;
    ambiguity.push_back(aux);
  }
  for (int i = 0; i < 100005; i++) {
    for (int j = 0; j < 4; j++) dp[i][j] = INF64;
  }
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      if (s[i] == hard[j])
        dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
      else
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      dp[i + 1][j] = min(dp[i][j] + ambiguity[i], dp[i + 1][j]);
    }
  }
  cout << *min_element(dp[n], dp[n] + 4) << '\n';
}
