#include <bits/stdc++.h>
using namespace std;
const long long N = 100011;
long long n, dp[N][4], c[N];
string s, a = "hard";
int main() {
  scanf("%lld", &n);
  cin >> s;
  for (int i = 1; i <= n; i++) scanf("%lld", &c[i]);
  for (int i = 1; i <= n; i++)
    dp[i][0] = dp[i - 1][0] + ((s[i - 1] == 'h') * c[i]);
  for (int j = 1; j < 4; j++) {
    for (int i = 1; i <= n; i++) {
      if (s[i - 1] != a[j])
        dp[i][j] = dp[i - 1][j];
      else
        dp[i][j] = min(dp[i - 1][j] + c[i], dp[i - 1][j - 1]);
    }
  }
  cout << dp[n][3];
}
