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