#K12306. Minimum Value of Function g(y)

    ID: 23661 Type: Default 1000ms 256MiB

Minimum Value of Function g(y)

Minimum Value of Function g(y)

You are given an integer n, an array of n integers b, and a binary string s representing an integer t in binary form. Consider a function \(g(y)\) defined for every integer \(y\) satisfying \(0 \le y \le t\) as follows:

[ g(y) = \sum_{i=0}^{n-1} b[i] \cdot (p[i] + q[i]), ]

where

[ p[i] = \begin{cases} 1, & \text{if the } i\text{-th bit of } y \text{ is } 0, \ 0, & \text{otherwise}, \end{cases} ]

[ q[i] = \begin{cases} 1, & \text{if the } i\text{-th bit of } y \text{ is } 1, \ 0, & \text{otherwise}. \end{cases} ]

Notice that for any fixed \(y\) the sum \(p[i]+q[i]\) is always 1 for every index \(i\) (since a bit is either 0 or 1). Therefore, the function simplifies to:

[ g(y) = \sum_{i=0}^{n-1} b[i]. ]

Your task is to compute the minimum value of \(g(y)\) over all \(y\) with \(0 \le y \le t\). Since \(g(y)\) is independent of \(y\), the answer is simply \(\sum_{i=0}^{n-1} b[i]\).

Note: Even though the problem description may appear to depend on \(y\), the definition guarantees the result is constant. Use the input values only to compute the sum of the array b.

inputFormat

The input is given via standard input and consists of three lines:

  • The first line contains an integer \(n\) representing the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the array b.
  • The third line contains a binary string s representing the upper bound \(t\) in binary form.

outputFormat

Output via standard output a single integer, the minimum value of \(g(y)\), which is the sum of the array b.

## sample
2
5 9
11
14