#include <bits/stdc++.h>
using namespace std;
using pii = pair<long, long>;
int main() {
  vector<long> A;
  vector<bool> S;
  vector<long> Sin;
  vector<long> Sall;
  int n;
  cin >> n;
  A.reserve(n);
  S.reserve(n);
  Sin.resize(n);
  Sall.resize(n);
  for (int i = 0; i < n; ++i) {
    long a;
    cin >> a;
    A.push_back(a);
  }
  for (int i = 0; i < n; ++i) {
    char a;
    cin >> a;
    S.push_back((a == '1') ? true : false);
  }
  std::reverse(begin(A), end(A));
  std::reverse(begin(S), end(S));
  Sin[0] = S[0] ? A[0] : 0;
  Sall[0] = A[0];
  for (int i = 1; i < n; ++i) {
    Sin[i] = Sin[i - 1] + (S[i] ? A[i] : 0);
    Sall[i] = Sall[i - 1] + A[i];
  }
  pii maximal(-1, -1);
  for (int i = 0; i < n; ++i) {
    if (S[i]) {
      long newVal = (i > 0) ? Sin[i - 1] : 0;
      newVal += Sall[n - 1] - Sall[i];
      if (newVal > maximal.first) {
        maximal.first = newVal;
        maximal.second = i;
      }
    }
  }
  cout << std::max(Sin[n - 1], maximal.first) << endl;
  return 0;
}
