n=int(input()) s=list(input()) v=list(map(int,input().split())) taken=[0]*n pre=-1 ans=0 while pre!=ans: y=[0,-1] yu=[0,-1,-1] yuk=[0,-1,-1,-1] yuki=[0,-1,-1,-1,-1] pre=ans for i in range(n): if taken[i]==1:continue if s[i]=='y': if y[0]0: if yu[0]0: if yuk[0]0: if yuki[0]0: ans+=yuki[0] taken[yuki[1]]=1 taken[yuki[2]]=1 taken[yuki[3]]=1 taken[yuki[4]]=1 print(ans)