#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int pref[N];
int n;
char str[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    pref[i] = pref[i - 1] + x;
  }
  scanf("%s", str + 1);
  int ans = 0, suff = 0;
  for (int i = n; i >= 1; --i) {
    if (str[i] == '1') {
      ans = max(ans, suff + pref[i - 1]);
      suff += pref[i] - pref[i - 1];
    }
  }
  printf("%d\n", max(ans, suff));
  return 0;
}
