#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
string a = "hard", s;
int cost[(int)1e5 + 10], n;
long long dp[(int)1e5 + 10][5];
long long solver(int pos, int idx) {
  if (idx == 4) {
    return (long long)1e18;
  }
  if (pos == n) {
    return 0;
  }
  long long &ret = dp[pos][idx];
  if (~ret) return ret;
  ret = (long long)1e18;
  ret = min(ret, cost[pos] + solver(pos + 1, idx));
  ret = min(ret, solver(pos + 1, idx + (a[idx] == s[pos])));
  return ret;
}
void track(int pos, int idx) {
  if (idx == 5) {
    return;
  }
  if (pos == n) {
    return;
  }
  long long opt = solver(pos, idx);
  long long ret = (long long)1e18;
  ret = min(ret, cost[pos] + solver(pos + 1, idx));
  if (opt == ret) {
    cout << pos << "," << s[pos] << endl;
    track(pos + 1, idx);
    return;
  }
  ret = min(ret, solver(pos + 1, idx + (a[idx] == s[pos])));
  if (opt == ret) {
    track(pos + 1, idx + (a[idx] == s[pos]));
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> s;
  for (int i = 0; i < n; i++) cin >> cost[i];
  memset(dp, -1, sizeof(dp));
  cout << solver(0, 0) << endl;
  return 0;
}
