#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T = 1;
  while (T--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long a[n + 3];
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long dp[n + 2][5];
    for (long long i = 0; i <= n; i++)
      for (long long j = 0; j <= 4; j++) dp[i][j] = 2e18;
    dp[0][0] = 0;
    string t = "hard";
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j <= 4; j++) {
        if ((s[i] == t[j]))
          dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
        else {
          dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i]);
      }
    }
    cout << *min_element(dp[n], dp[n] + 4);
  }
}
