#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000;
int sum[maxn];
int a[maxn];
int sum2[maxn];
int main() {
  int n;
  char s[maxn];
  while (cin >> n) {
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= n; ++i) {
      scanf("%d", a + i);
      sum[i] = sum[i - 1] + a[i];
    }
    scanf("%s", s + 1);
    int c = 0, ans = 0;
    for (int i = n; i >= 1; --i) {
      if (s[i] == '1') {
        ans = max(ans, c + sum[i - 1]);
        c += a[i];
      }
    }
    cout << max(c, ans) << endl;
  }
}
