#include <bits/stdc++.h>
using namespace std;
vector<long long> cost;
string s;
int n;
long long dp[100010][10];
long long solve(long long i, long long acc) {
  if (i == n) {
    if (acc == 4) return (1LL * 10000 * INT_MAX);
    return 0;
  }
  long long &r = dp[i][acc];
  if (r != -1LL) return r;
  long long res = 1LL * 10000 * INT_MAX;
  res = min(res, solve(i + 1, acc + ((acc == 0 && s[i] == 'h') ||
                                     (acc == 1 && s[i] == 'a') ||
                                     (acc == 2 && s[i] == 'r') ||
                                     (acc == 3 && s[i] == 'd'))));
  res = min(res, cost[i] + solve(i + 1, acc));
  return r = res;
}
int main() {
  cin >> n;
  cin >> s;
  cost.resize(n);
  memset(dp, -1LL, sizeof(dp));
  for (int i = 0; i < n; i++) cin >> cost[i];
  cout << solve(0, 0) << endl;
  return 0;
}
