#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const double pi = 2 * asin(1.0);
int n;
int m;
char ss[100010];
int s1[100010], s2[100010], a[100010];
int main() {
  scanf("%d", &n);
  int ss1 = 0, ss2 = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    ss2 += a[i];
    s2[i] = ss2;
  }
  gets(ss);
  gets(ss);
  int smax = 0;
  for (int i = 0; i < n; i++) {
    ss1 += a[i] * (ss[i] - '0');
    if (ss[i] == '1') m = i;
    s1[i] = ss1;
  }
  smax = ss1;
  for (int i = 0; i < n; i++) {
    s1[i] = ss1 - s1[i];
  }
  for (int i = 1; i <= m; i++) {
    if (ss[i] == '0') continue;
    smax = max(smax, s1[i] + s2[i - 1]);
  }
  printf("%d\n", smax);
  return 0;
}
