#include <bits/stdc++.h>
using namespace std;
long long a[100005];
char m[100005];
int maximum(int x, int y) {
  if (x > y) {
    return x;
  }
  return y;
}
int minimum(int x, int y) {
  if (x < y) {
    return x;
  }
  return y;
}
int gcd(int x, int y) {
  if (x % y == 0) {
    return y;
  }
  return gcd(y, x % y);
}
void prime_factors(int n) {
  while (n % 2 == 0) {
    printf("2 ");
    n /= 2;
  }
  int i;
  for (i = 3; i < sqrt(n); i += 2) {
    while (n % i == 0) {
      printf("%d ", i);
      n /= i;
    }
  }
  if (n > 2) {
    printf("%d\n", n);
  }
  return;
}
int main() {
  int n;
  int i, j;
  long long sum, max;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  scanf("%s", m);
  sum = max = 0;
  j = n - 1;
  while (j >= 0 && m[j] == '0') {
    j--;
  }
  for (i = 0; i <= j; i++) {
    if (m[i] == '1') {
      sum += a[i];
    }
    max += a[i];
  }
  long long tmp = 0;
  long long zero_sum = 0;
  long long kmp;
  while (j >= 0) {
    if (m[j] == '1') {
      kmp = max - (a[j] + tmp + zero_sum);
      if (sum < kmp + tmp) {
        sum = kmp + tmp;
      }
      tmp += a[j];
    } else {
      zero_sum += a[j];
    }
    j--;
  }
  cout << sum << endl;
  return 0;
}
