#include <bits/stdc++.h>
using lld = long long int;
using ld = long int;
using namespace std;
int main() {
  lld n, i, sum = 0, maxi = 0, flag = 0, sum1 = 0, sum2 = 0, ans;
  cin >> n;
  vector<lld> vec(n);
  for (i = 0; i < n; i++) {
    cin >> vec[i];
  }
  string s;
  cin >> s;
  lld pos;
  for (i = 0; i < n; i++) {
    if (s[i] == '1') {
      sum += vec[i];
      pos = i;
    }
  }
  for (i = 0; i < n; i++) {
    if (pos == 0) {
      maxi = vec[0];
    } else {
      if (i != 0) sum1 += vec[i - 1];
      if (s[i] == '1') {
        sum2 += vec[i];
        ans = sum1 + (sum - sum2);
        if (ans > maxi) maxi = ans;
      }
    }
  }
  cout << max(sum, maxi);
  return 0;
}
