Valera has array a, consisting of n integers a0, a1, ..., an - 1, and function f(x), taking an integer from 0 to 2n - 1 as its single argument. Value f(x) is calculated by formula <image>, where value bit(i) equals one if the binary representation of number x contains a 1 on the i-th position, and zero otherwise.

For example, if n = 4 and x = 11 (11 = 20 + 21 + 23), then f(x) = a0 + a1 + a3.

Help Valera find the maximum of function f(x) among all x, for which an inequality holds: 0 ≤ x ≤ m.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of array elements. The next line contains n space-separated integers a0, a1, ..., an - 1 (0 ≤ ai ≤ 104) — elements of array a.

The third line contains a sequence of digits zero and one without spaces s0s1... sn - 1 — the binary representation of number m. Number m equals <image>.

Output

Print a single integer — the maximum value of function f(x) for all <image>.

Examples

Input

2
3 8
10


Output

3


Input

5
17 0 10 2 1
11010


Output

27

Note

In the first test case m = 20 = 1, f(0) = 0, f(1) = a0 = 3.

In the second sample m = 20 + 21 + 23 = 11, the maximum value of function equals f(5) = a0 + a2 = 17 + 10 = 27.
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class C {

    void run() throws IOException {
        int n = ni();
        int[] a = na(n);
        char[] m = nl().toCharArray();
        long[] s = new long[n];
        s[0] = a[0];

        for (int i = 1; i < n; i++) {
            s[i] = s[i - 1] + a[i];
        }
        boolean z = true;
        for (char c : m) {
            if (c == '1') {
                z = false;
            }
        }
        if (z) {
            pw.println(0);
            return;
        }

        long ans = a[0] * (m[0] - 48L);

        for (int i = 1; i < n; i++) {
            if (m[i] == '1') {
                if (a[i] + ans >= s[i - 1]) {
                    ans += a[i];
                } else {
                    ans = s[i - 1];
                }

            }
        }
        pw.println(ans);
    }

    int gcd(int a, int b) {
        return (b == 0) ? (a) : (gcd(b, a % b));
    }

    int[] na(int a_len) throws IOException {
        int[] _a = new int[a_len];
        for (int i = 0; i < a_len; i++)
            _a[i] = ni();
        return _a;
    }

    int[][] nm(int a_len, int a_hei) throws IOException {
        int[][] _a = new int[a_len][a_hei];
        for (int i = 0; i < a_len; i++)
            for (int j = 0; j < a_hei; j++)
                _a[i][j] = ni();
        return _a;
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(next());
    }

    String nl() throws IOException {
        return br.readLine();
    }

    void tr(String debug) {
        if (!OJ)
            pw.println(" " + debug);
    }

    static PrintWriter pw;
    static BufferedReader br;
    static StringTokenizer st;
    static boolean OJ;

    public static void main(String[] args) throws IOException {
        long timeout = System.currentTimeMillis();
        OJ = System.getProperty("ONLINE_JUDGE") != null;
        pw = new PrintWriter(System.out);
        br = new BufferedReader(OJ ? new InputStreamReader(System.in) : new FileReader(new File("C.txt")));

        while (br.ready())
            new C().run();
        if (!OJ) {
            pw.println();
            pw.println(System.currentTimeMillis() - timeout);
        }
        br.close();
        pw.close();
    }

}
