#include #include #define endl "\n" using namespace std; typedef long long ll; typedef pair l_l; typedef pair i_i; template inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } const long long INF = 1e18; //const ll mod = 1000000007; ll N; string S; vector V; ll ans = 0; vector s; string yuki = "yuki"; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> S; V.resize(N); for(int i = 0; i < N; i++) cin >> V[i]; ll s = 4 * N; ll t = s + 1; atcoder::mcf_graph g(t + 1); g.add_edge(s, 0, N, 0); for(int i = 0; i + 1 < N; i++) { for(int j = 0; j < 4; j++) { g.add_edge(4 * i + j, 4 * (i + 1) + j, N, 0); } } for(int i = 0; i < N; i++) { for(int j = 0; j < 4; j++) { if(S[i] != yuki[j]) continue; if(j != 3) { g.add_edge(4*i+j, 4*i+j+1, 1, (ll)1e9 - V[i]); } else { g.add_edge(4*i+j, t, 1, (ll)1e9 - V[i]); } } } l_l tmp = g.flow(s, t); ll ans = tmp.first * (ll)1e9 * 4 - tmp.second; cout << ans << endl; return 0; }