#include <bits/stdc++.h>
using namespace std;
bool checkBit(long long int n, long long int i) { return (n & (1LL << i)); }
long long int setBit(long long int n, long long int i) {
  return (n | (1LL << i));
}
long long int resetBit(long long int n, long long int i) {
  return (n & (~(1LL << i)));
}
const long long int MX = 1e18;
const long long int mod = 1e9 + 7;
int n;
long long int dp[100003][5], val[100003];
string s, str = "hard";
long long int fuck(int x, int y) {
  if (x == n) return 0;
  long long int &ret = dp[x][y];
  if (ret != -1) return ret;
  long long int r1 = MX, r2 = MX;
  if (s[x] != str[y]) return ret = fuck(x + 1, y);
  r1 = val[x] + fuck(x + 1, y);
  if (y != 3) {
    r2 = fuck(x + 1, y + 1);
  }
  return ret = min(r1, r2);
}
void solve() {
  cin >> n;
  cin >> s;
  for (int i = 0; i < n; i++) {
    cin >> val[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << fuck(0, 0) << "\n";
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
