#E. Vasya and Binary String

    Type: RemoteJudge 2000ms 256MiB

Vasya and Binary String

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Description

Vasya has a string ss of length nn consisting only of digits 0 and 1. Also he has an array aa of length nn.

Vasya performs the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue together the remaining parts (any of them can be empty). For example, if he erases substring 111 from string 111110 he will get the string 110. Vasya gets axa_x points for erasing substring of length xx.

Vasya wants to maximize his total points, so help him with this!

The first line contains one integer nn (1n1001 \le n \le 100) — the length of string ss.

The second line contains string ss, consisting only of digits 0 and 1.

The third line contains nn integers a1,a2,ana_1, a_2, \dots a_n (1ai1091 \le a_i \le 10^9), where aia_i is the number of points for erasing the substring of length ii.

Print one integer — the maximum total points Vasya can get.

Input

The first line contains one integer nn (1n1001 \le n \le 100) — the length of string ss.

The second line contains string ss, consisting only of digits 0 and 1.

The third line contains nn integers a1,a2,ana_1, a_2, \dots a_n (1ai1091 \le a_i \le 10^9), where aia_i is the number of points for erasing the substring of length ii.

Output

Print one integer — the maximum total points Vasya can get.

Sample Input 1

7
1101001
3 4 9 100 1 2 3

Sample Output 1

109

Sample Input 2

5
10101
3 10 15 15 15

Sample Output 2

23

Note

In the first example the optimal sequence of erasings is: 1101001 \rightarrow 111001 \rightarrow 11101 \rightarrow 1111 \rightarrow \varnothing.

In the second example the optimal sequence of erasings is: 10101 \rightarrow 1001 \rightarrow 11 \rightarrow \varnothing.

20240618集训

Not Attended
Status
Done
Rule
IOI
Problem
7
Start at
2024-6-18 19:00
End at
2024-6-18 21:00
Duration
2 hour(s)
Host
Partic.
12