#include <bits/stdc++.h>
using namespace std;
int min(int a, int b) { return a > b ? b : a; }
string st = "hard";
char c[100005];
long long a[100005], f[100005][5];
int main() {
  int n, i, j;
  cin >> n >> c + 1;
  for (i = 1; i <= n; i++) cin >> a[i];
  memset(f, 0x3f, sizeof(f));
  for (i = 1; i < 5; i++) f[0][i] = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= 4; j++)
      if (c[i] != st[j - 1])
        f[i][j] = f[i - 1][j];
      else
        f[i][j] = min(f[i - 1][j - 1], f[i - 1][j] + a[i]);
  long long ans = f[n][0];
  for (i = 1; i < 5; i++) ans = min(ans, f[n][i]);
  cout << ans << endl;
}
