#include using namespace std; using ll = long long; template using vec = vector; template using vvec = vector>; template bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;} template bool chmax(T& a,T b){if(a=0;i--) #define all(x) (x).begin(),(x).end() #define debug(x) cerr << #x << " = " << (x) << endl; using P = pair; const ll inf = 1e17; class min_cost_flow{ private: int N; struct edge{int to; ll cap,cost; int rev; bool is_rev;}; vector> G; vector h,dist,prevv,preve; public: min_cost_flow(int n){ N = n; G = vector>(N); h = dist = prevv = preve = vector(N,0); } void add_edge(int from,int to,ll cap,ll cost){ G[from].push_back((edge){to,cap,cost,(int) G[to].size(),false}); G[to].push_back((edge){from,0,-cost,(int) G[from].size()-1,true}); } ll answer(int s,int t,ll f){ ll res = 0; fill(h.begin(),h.end(),0); while(f>0){ priority_queue,greater

> Q; fill(dist.begin(),dist.end(),inf); dist[s] = 0; Q.push(P(0,s)); while(!Q.empty()){ P p = Q.top(); Q.pop(); int v = p.second; if(dist[v]0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){ dist[e.to] = dist[v]+e.cost+h[v]-h[e.to]; prevv[e.to] = v; preve[e.to] = i; Q.push(P(dist[e.to],e.to)); } } } if(dist[t]==inf) return -1; for(int v=0;v> N; string S; cin >> S; vec A(N); rep(i,N) cin >> A[i]; min_cost_flow flow(N+2); string yuki = "yuki"; int s = N,t = N+1; ll offset = 1e15; rep(i,N){ rep(j,4) if(S[i]==yuki[j]){ if(j==0) flow.add_edge(s,i,1,0); if(j==3) flow.add_edge(i,t,1,offset-A[i]); for(int k=i+1;k