#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  string s;
  cin >> s;
  int maxone = -1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') maxone = i;
  }
  if (maxone == -1) {
    cout << 0 << endl;
    return 0;
  }
  long long sum = 0;
  int prefix[maxone + 1];
  prefix[0] = a[0];
  int original[maxone + 1];
  if (s[0] == '0')
    original[0] = 0;
  else
    original[0] = a[0];
  for (int i = 1; i <= maxone; i++) {
    prefix[i] = prefix[i - 1] += a[i];
    if (s[i] == '1')
      original[i] = original[i - 1] + a[i];
    else
      original[i] = original[i - 1];
  }
  long long maxans = original[maxone];
  for (int i = 1; i <= maxone; i++) {
    if (s[i] != '0') {
      sum = prefix[max(i - 1, 0)] - a[i] + (original[maxone] - original[i]);
    }
    maxans = max(maxans, sum);
  }
  cout << maxans << endl;
  return 0;
}
