#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

template< typename flow_t, typename cost_t >
struct MinCostFlow {
  const cost_t INF;

  struct edge {
    int to;
    flow_t cap;
    cost_t cost;
    int rev;
    bool isrev;
  };
  vector<vector<edge>> graph;
  vector<cost_t> potential,min_cost;
  vector<int> prevv,preve;

  MinCostFlow(int V) : graph(V),INF(numeric_limits< cost_t >::max()) {}

  void add_edge(int from,int to,flow_t cap,cost_t cost){
    graph[from].emplace_back((edge){to,cap,cost,(int)graph[to].size(),false});
    graph[to].emplace_back((edge){from,0,-cost,(int)graph[from].size()-1,true});
  }

  cost_t min_cost_flow(int s,int t,flow_t f){
    int V=(int)graph.size();
    cost_t ret=0;
    using Pi = pair<cost_t,int>;
    priority_queue<Pi,vector<Pi>,greater<Pi>> PQ;
    potential.assign(V,0);
    preve.assign(V,-1);
    prevv.assign(V,-1);

    while(f>0){
      min_cost.assign(V,INF);
      PQ.emplace(0,s);
      min_cost[s]=0;
      while(!PQ.empty()){
        cost_t d;
        int now;
        tie(d,now)=PQ.top();
        PQ.pop();
        if(min_cost[now]<d) continue;
        
        for(int i=0;i<graph[now].size();i++){
          edge &e=graph[now][i];
          cost_t nextCost=min_cost[now]+(e.cost+potential[now]-potential[e.to]);
          if(e.cap>0&&min_cost[e.to]>nextCost){
            min_cost[e.to]=nextCost;
            prevv[e.to]=now;
            preve[e.to]=i;
            PQ.emplace(min_cost[e.to],e.to);
          }
        }
      }

      if(min_cost[t]==INF) return -1;

      for(int v=0;v<V;v++) potential[v]+=min_cost[v];
      flow_t addflow=f;
      for(int v=t;v!=s;v=prevv[v]){
        addflow=min(addflow,graph[prevv[v]][preve[v]].cap);
      }
      f-=addflow;
      ret+=addflow*potential[t];
      
      for(int v=t;v!=s;v=prevv[v]){
        edge &e=graph[prevv[v]][preve[v]];
        e.cap-=addflow;
        graph[v][e.rev].cap+=addflow;
      }
    }
    return ret;
  }
};

const int L=500;
string P="yuki";
const ll INF=1e9;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin>>N;
  string S;
  cin>>S;
  vector<ll> V(N);
  rep(i,N) cin>>V[i];

  MinCostFlow<int,ll> mcf(N+2);
  int s=N;
  int t=N+1;
  vector<vector<int>> v(4);
  rep(i,N){
      rep(j,4) if(S[i]==P[j]) v[j].push_back(i);
  }

  int M=N/4;

  for(int j=0;j<4;j++){
      for(int i=0;i+1<v[j].size();i++){
          mcf.add_edge(v[j][i],v[j][i+1],M,0);
      }
      if(j==3){
          for(int i=0;i<v[j].size();i++) mcf.add_edge(v[j][i],t,1,INF-V[v[j][i]]);
      }else{
          for(int i=0;i<v[j].size();i++){
              int z=lower_bound(all(v[j+1]),v[j][i])-v[j+1].begin();
              if(z<v[j+1].size()) mcf.add_edge(v[j][i],v[j+1][z],1,INF-V[v[j][i]]);
          }
      }
  }
  if(v[0].size()) mcf.add_edge(s,v[0][0],M,0);
  mcf.add_edge(s,t,M,4*INF-0);

  ll ans=mcf.min_cost_flow(s,t,M);
  ans=-(ans-INF*M*4);
  cout<<ans<<endl;

  return 0;
}