#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; int n; string s; ll v[3030]; const string s0="yuki"; int main() { cin>>n; cin>>s; for(int i=0; i>v[i]; ll ans=0; priority_queue que[3]; for(int i=n-1; i>=0; i--){ if(s[i]=='i'){ que[0].push(v[i]); }else if(s[i]=='k'){ if(que[0].empty()) continue; ll x=que[0].top(); que[0].pop(); que[1].push(x+v[i]); }else if(s[i]=='u'){ if(que[1].empty()) continue; ll x=que[1].top(); que[1].pop(); que[2].push(x+v[i]); }else{ if(que[2].empty()) continue; ans+=que[2].top()+v[i]; que[2].pop(); } } cout<