cswork / OAOpen practice workspace

AmazonOA #75

Move Units (Protect Cities)

Estimated MediumJudge-ready

Topics (AI-labelled)GreedyDP Basics

unit[i]=1 means city i has one unit; each unit can stay where it is or, when i>1, move one step to the left, at most once. A city is covered if it has at least one unit; the population of a city covered more than once counts only once. Find the maximum total covered population.

Input

The first line contains n (1..100000), the second line contains n populations (1..10000), and the third line contains a 01 string of length n.

Output

Output a single integer answer.

Example 1

Input:

5
10 5 8 9 6
01101

Output:

27

Example 2

Input:

1
7
0

Output:

0

Example 3

Input:

2
3 8
11

Output:

11

Example notes

Example 1: the unit in city 2 moves to 1, the unit in city 3 stays at 3, and the unit in city 5 moves to 4, for a population of 10+8+9=27. Example 2: there are no units, so the coverage is 0. Example 3: both units stay in place, for a population of 3+8=11.

Editorial

Loading solution…