#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int a[MAXN];
char str[MAXN];
int sum[MAXN];
int ss[MAXN];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%s", str + 1);
  int ma = 0;
  for (int i = n; i >= 1; i--) {
    if (str[i] == '1') {
      ma = i;
      break;
    }
  }
  memset(sum, 0, sizeof(sum));
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  memset(ss, 0, sizeof(ss));
  for (int i = 1; i <= n; i++) {
    ss[i] = ss[i - 1];
    if (str[i] == '1') ss[i] = ss[i - 1] + a[i];
  }
  int ans1, ans2;
  ans1 = ans2 = 0;
  for (int i = 1; i <= ma; i++) {
    if (str[i] != '0') ans1 += a[i];
  }
  for (int i = ma; i >= 0; i--) {
    int ans2 = 0;
    if (str[i] == '1') {
      ans2 += ss[ma] - ss[i];
      ans2 += sum[i - 1];
    }
    ans1 = max(ans1, ans2);
  }
  printf("%d\n", max(ans1, ans2));
  return 0;
}
