#include <bits/stdc++.h>
int a[100005], s[100005], f[100005], g[100005];
char str[100005];
int Max(int x, int y) { return x > y ? x : y; }
int main() {
  int N, i, j, p = 0, ans = 0;
  memset(s, 0, sizeof(s));
  memset(g, 0, sizeof(g));
  scanf("%d", &N);
  for (i = 0; i < N; i++) scanf("%d", &a[i]);
  s[0] = 0;
  for (i = 1; i < N; i++) s[i] = s[i - 1] + a[i - 1];
  scanf("%s", str);
  for (i = 0; i < N; i++) {
    if (str[i] == '1') {
      f[i] = a[i];
      p += a[i];
    }
  }
  g[N - 1] = 0;
  for (i = N - 2; i >= 0; i--) g[i] = g[i + 1] + f[i + 1];
  for (i = 0; i < N; i++) {
    int t = s[i] + g[i];
    if (str[i] == '1' && t > ans) ans = t;
  }
  if (p > ans) ans = p;
  printf("%d\n", ans);
  return 0;
}
