#include <bits/stdc++.h>
using namespace std;
int n, a[100010], res, p[100010], s;
char c[100010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("\n");
  for (int i = 1; i <= n; i++) scanf("%c", &c[i]);
  for (int i = 1; i <= n; i++) {
    if (c[i] == '1') res += a[i];
    p[i] = p[i - 1] + a[i];
  }
  for (int i = n; i >= 1; i--) {
    if (c[i] == '1') {
      res = max(res, p[i - 1] + s);
      s += a[i];
    }
  }
  printf("%d", res);
  return 0;
}
