#include <bits/stdc++.h>
int num[100001];
int sum[100001];
int cho[100001];
int ans[100001], max, now;
int last;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &num[i]);
    sum[i] = sum[i - 1] + num[i];
  }
  while (getchar() != '\n')
    ;
  for (int i = 1; i <= n; ++i) {
    cho[i] = getchar() - '0';
    if (cho[i]) {
      last = i;
      ans[i] = num[i] + ans[i - 1];
    } else
      ans[i] = ans[i - 1];
  }
  max = now = ans[last];
  while (last > 1) {
    if (cho[last]) {
      if (max < now - ans[last] + sum[last - 1]) {
        max = now - ans[last] + sum[last - 1];
      }
    }
    --last;
  }
  printf("%d\n", max);
  return 0;
}
