#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t, n, num, m, k;
  cin >> n;
  long long aa[n];
  long long left_sum = 0, right_sum = 0, maxi = 0;
  for (long long i = 0; i < n; i++) {
    cin >> aa[i];
    left_sum += aa[i];
  }
  string s;
  cin >> s;
  for (long long i = n - 1; i >= 0; i--) {
    left_sum -= aa[i];
    if (s[i] == '1') {
      if (i == 0) {
        right_sum += aa[0];
      }
      maxi = max(maxi, left_sum + right_sum);
      right_sum += aa[i];
    }
  }
  cout << maxi;
  return 0;
}
