#ABC257C. [ABC257C] Robot Takahashi

[ABC257C] Robot Takahashi

Score : 300300 points

Problem Statement

There are NN people, each of whom is either a child or an adult. The ii-th person has a weight of WiW_i. Whether each person is a child or an adult is specified by a string SS of length NN consisting of 0 and 1. If the ii-th character of SS is 0, then the ii-th person is a child; if it is 1, then the ii-th person is an adult.

When Takahashi the robot is given a real number XX, Takahashi judges a person with a weight less than XX to be a child and a person with a weight more than or equal to XX to be an adult. For a real value XX, let f(X)f(X) be the number of people whom Takahashi correctly judges whether they are children or adults.

Find the maximum value of f(X)f(X) for all real values of XX.

Constraints

  • 1N2×1051\leq N\leq 2\times 10^5
  • SS is a string of length NN consisting of 0 and 1.
  • 1Wi1091\leq W_i\leq 10^9
  • NN and WiW_i are integers.

Input

Input is given from Standard Input in the following format:

NN

SS

W1W_1 W2W_2 \ldots WNW_N

Output

Print the maximum value of f(X)f(X) as an integer in a single line.

5
10101
60 45 30 40 80
4

When Takahashi is given X=50X=50, it judges the 22-nd, 33-rd, and 44-th people to be children and the 11-st and 55-th to be adults. In reality, the 22-nd and 44-th are children, and the 11-st, 33-rd, and 55-th are adults, so the 11-st, 22-nd, 44-th, and 55-th people are correctly judged. Thus, f(50)=4f(50)=4.

This is the maximum since there is no XX that judges correctly for all 55 people. Thus, 44 should be printed.

3
000
1 2 3
3

For example, X=10X=10 achieves the maximum value f(10)=3f(10)=3. Note that the people may be all children or all adults.

5
10101
60 50 50 50 60
4

For example, X=55X=55 achieves the maximum value f(55)=4f(55)=4. Note that there may be multiple people with the same weight.