#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long fastpower(long long b, long long p) {
  long long ans = 1;
  while (p) {
    if (p % 2) {
      ans = (ans * b);
    }
    b = (b * b);
    p /= 2;
  }
  return ans;
}
char s[(int)1e6];
long long arr[(int)1e6];
int main() {
  int n;
  scanf("%d", &n);
  long long hasnot = 0;
  long long has = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
  }
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    has += arr[i];
    if (s[i] == '0') {
      hasnot += arr[i];
    }
    if (s[i] == '1' && hasnot >= arr[i]) {
      hasnot = arr[i];
    }
  }
  printf("%lld", has - hasnot);
  return 0;
}
