#include <bits/stdc++.h>
using namespace std;
long long power(long long x, unsigned long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x;
    }
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long long powermod(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long Mod(long long x, long long m) { return (x % m + m) % m; }
long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const long long mxn = 1e5 + 5;
long long n;
string s;
long long val[mxn];
long long dp[mxn][4];
string a = "hard";
long long solve(long long ind, long long cur) {
  if (cur >= a.size()) {
    return 1000000000000000000;
  }
  if (ind >= n) {
    return 0;
  }
  if (dp[ind][cur] != -1) {
    return dp[ind][cur];
  }
  long long res = 1000000000000000000;
  res = min(res, solve(ind + 1, cur + (s[ind] == a[cur])));
  res = min(res, val[ind] + solve(ind + 1, cur));
  return dp[ind][cur] = res;
}
int32_t main() {
  for (long long i = 0; i < mxn; i++) {
    for (long long j = 0; j < 4; j++) {
      dp[i][j] = -1;
    }
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  cin >> s;
  for (long long i = 0; i < n; i++) {
    cin >> val[i];
  }
  cout << solve(0, 0);
  return 0;
}
