#include <bits/stdc++.h>
using namespace std;
int a[100005];
int w[100005];
int x[100005];
int main() {
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; n > i; i++) {
    scanf("%d", &a[i]);
  }
  w[0] = a[0];
  for (i = 1; n > i; i++) {
    w[i] = w[i - 1] + a[i];
  }
  int k;
  string s;
  cin >> s;
  unsigned int max = 0;
  unsigned int sum = 0;
  for (i = 0; n > i; i++) {
    if (s[i] == '1') {
      sum += a[i];
    }
    x[i] = sum;
  }
  int temp;
  max = sum;
  for (i = 1; n > i; i++) {
    if (s[i] == '1') {
      temp = sum - x[i] + w[i - 1];
      if (temp > max) {
        max = temp;
      }
    }
  }
  printf("%d", max);
}
