#include <bits/stdc++.h>
using namespace std;
class Solution {
  const long long INF = 1ll << 60;
  vector<vector<long long>> dp;
  int n;
  vector<long long> A;
  string s;

 public:
  void run(istream &in, ostream &out) {
    in >> n;
    in >> s;
    A.resize(n);
    dp.assign(5, vector<long long>(n + 1, INF));
    for (int i = 0; i < n; ++i) in >> A[i];
    dp[0][0] = dp[1][0] = dp[2][0] = dp[3][0] = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 4; ++j) {
        dp[j][i + 1] = s[i] != "hard"[j] ? dp[j][i]
                       : j == 0          ? dp[j][i] + A[i]
                                         : min(dp[j][i] + A[i], dp[j - 1][i]);
      }
    }
    out << min({dp[0][n], dp[1][n], dp[2][n], dp[3][n]}) << '\n';
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  Solution().run(std::cin, std::cout);
  return 0;
}
