#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long int> a(n);
  int i;
  for (i = 0; i < n; i++) cin >> a[i];
  string ini;
  cin >> ini;
  vector<long long int> c(n);
  c[0] = a[0];
  for (i = 1; i < n; i++) c[i] = c[i - 1] + a[i];
  vector<long long int> asum(n);
  if (ini[0] == '1')
    asum[0] = a[0];
  else
    asum[0] = 0;
  for (i = 1; i < n; i++) {
    if (ini[i] == '1')
      asum[i] = asum[i - 1] + a[i];
    else
      asum[i] = asum[i - 1];
  }
  long long int tsum = asum[n - 1];
  for (i = n - 1; i >= 0; i--) {
    if (ini[i] == '1') {
      long long int extrasum = asum[n - 1] - asum[i];
      if (extrasum + c[i] - a[i] > tsum) tsum = extrasum + c[i] - a[i];
    }
  }
  cout << tsum << "\n";
}
