PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000164. Rô-bốt phân biệt trẻ em và người lớn (Robot Takahashi)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Rô-bốt phân biệt trẻ em và người lớn (Robot Takahashi)

Robot Takahashi

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN people, each truly a child or an adult. The string SS gives the true labels: Si=0S_i=0 for a child and Si=1S_i=1 for an adult. Person ii has integer weight WiW_i. Given any real threshold XX, a robot labels weights strictly less than XX as children and weights greater than or equal to XX as adults. Let f(X)f(X) be the number of correct labels. Find the maximum possible f(X)f(X) over all real XX.

Input

  • Line 1 contains integer NN.
  • Line 2 contains binary string SS of length NN.
  • Line 3 contains NN integers W1,W2,…,WNW_1,W_2,\ldots,W_N.

Output

Print one integer: the maximum number of people the robot can classify correctly.

Subtasks

  • Subtask 1 (20 points): 1≤N≤501\le N\le 50; 1≤Wi≤1001\le W_i\le 100 for all ii; SS contains only 0, 1 and has length NN.
  • Subtask 2 (30 points): 1≤N≤50001\le N\le 5000; 1≤Wi≤10000000001\le W_i\le 1000000000 for all ii; SS contains only 0, 1 and has length NN.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 1≤Wi≤10000000001\le W_i\le 1000000000 for all ii; SS contains only 0, 1 and has length NN.

Examples

Input

5
10101
60 45 30 40 80

Output

4

Explanation

Choose X=50X=50: people with weights 60,8060,80 are classified as adults, and people with weights 45,30,4045,30,40 as children. The true labels 10101 mean people 1, 3, 5 are adults, and 2, 4 are children. People 1, 2, 4, 5 are classified correctly, giving 44. It is impossible to classify all 5 correctly because the adult of weight 3030 and the child of weight 4545 cannot both be correctly classified by one threshold.