#include <bits/stdc++.h>
using namespace std;
int v[100010];
char s[100010];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d\n", &v[i]);
  }
  fgets(s, 100010, stdin);
  int s1 = 0, s2 = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      s1 = max(s1 + v[i], s2);
    }
    s2 += v[i];
  }
  printf("%d\n", s1);
  return 0;
}
