## https://yukicoder.me/problems/no/1288 from atcoder.mincostflow import MCFGraph MAXINT = 10 ** 14 def main(): N = int(input()) S = input() V = list(map(int, input().split())) # ネットワークフローを使って解く mcf_graph = MCFGraph(2 * N + 2) for i in range(N): if S[i] == "y": mcf_graph.add_edge(0, i + 1, 1, 0) for i in range(N): if S[i] == "u": for j in range(i): if S[j] == "y": mcf_graph.add_edge(N + j + 1, i + 1, 1, 0) elif S[i] == "k": for j in range(i): if S[j] == "u": mcf_graph.add_edge(N + j + 1, i + 1, 1, 0) elif S[i] == "i": for j in range(i): if S[j] == "k": mcf_graph.add_edge(N + j + 1, i + 1, 1, 0) for i in range(N): if S[i] == "i": mcf_graph.add_edge(N + i + 1, 2 * N + 1, 1, 0) for i in range(N): mcf_graph.add_edge(i + 1, N + i + 1, 1, MAXINT - V[i]) s_list = mcf_graph.slope(0, 2 * N + 1) answer = 0 for f, a in s_list: x = f * 4 * MAXINT - a answer = max(answer, x) print(answer) if __name__ == "__main__": main()