#include <bits/stdc++.h>
using namespace std;
long long int logy(long long int x, long long int y) {
  return ceil((long double)(log(x) / log(y)));
}
long long int powe(long long int a, long long int b) {
  long long int re = 1;
  while (b) {
    if (b & 1) re = (re * a);
    a = (a * a);
    b = b >> 1;
  }
  return re;
}
bool flag = 0, flag1 = 0, flag2 = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int tt = 1;
  while (tt--) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    ;
    long long int ans = 0, cc = 0, last = 0;
    string s;
    cin >> s;
    for (long long int i = 0; i < n; i++) {
      if (s[i] == '1') {
        ans = max(ans, cc);
        ans = max(ans, last + a[i]);
        last = ans;
      }
      cc += a[i];
    }
    cout << ans;
  }
  return 0;
}
