#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int a[n];
  for (int i = (0), _b = (n); i < _b; i++) cin >> a[i];
  string bit;
  cin >> bit;
  long m = 0;
  long zeroc = 0;
  long sumi = 0;
  int prev0 = 0;
  for (int i = (0), _b = (n); i < _b; i++) {
    if (bit[i] == '1' && !prev0)
      m += a[i];
    else if (bit[i] == '0') {
      prev0 = 1;
    } else {
      if (sumi > a[i] + m)
        m = sumi;
      else
        m += a[i];
    }
    sumi += a[i];
  }
  cout << m << '\n';
  return 0;
}
