#include <bits/stdc++.h>
using namespace std;
long long dp[123456][10], n, a[123456];
char str[123456];
char s[5] = {'h', 'a', 'r', 'd'};
long long dfs(int id, int k) {
  if (id == n + 1) return 0;
  if (dp[id][k] != -1) return dp[id][k];
  dp[id][k] = 1e18;
  if (str[id] == s[k + 1]) {
    if (k != 2) dp[id][k] = min(dp[id][k], dfs(id + 1, k + 1));
  } else
    dp[id][k] = min(dp[id][k], dfs(id + 1, k));
  dp[id][k] = min(dp[id][k], dfs(id + 1, k) + a[id]);
  return dp[id][k];
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%lld%s", &n, str + 1);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  printf("%lld\n", dfs(1, -1));
  return 0;
}
