#include <bits/stdc++.h>
char s[100005];
int v[100005];
int sum[100005];
int array[100005];
int main(void) {
  int n;
  int i;
  scanf(" %d", &n);
  for (i = 1; i <= n; i++) {
    scanf(" %d", &v[i]);
  }
  scanf(" %s", s + 1);
  sum[0] = 0;
  array[0] = 0;
  for (i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + v[i];
  }
  for (i = 1; i <= n; i++) {
    array[i] = array[i - 1] + (s[i] - '0') * v[i];
    if (s[i] == '1') {
      if (array[i] < sum[i - 1]) {
        array[i] = sum[i - 1];
      }
    }
  }
  printf("%d\n", array[n]);
  return 0;
}
