#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int A[n + 1], S[n + 1], S1[n + 3];
  A[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  S[0] = 0;
  for (int i = 1; i <= n; i++) {
    S[i] = S[i - 1] + A[i];
  }
  string st;
  cin >> st;
  S1[n + 1] = 0;
  S1[n + 2] = 0;
  for (int i = n; i > 0; i--) {
    S1[i] = S1[i + 1] + (st[i - 1] - '0') * A[i];
  }
  int ans = -1;
  for (int i = n; i > 0; i--) {
    int aux;
    if (st[i - 1] == '1') {
      ans = max(ans, S1[i + 1] + S[i - 1]);
    }
  }
  cout << max(ans, S1[1]) << endl;
  return 0;
}
