#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  vector<int> num(n, 0);
  for (i = 0; i < n - 1; ++i) {
    cin >> num[n - 1 - i];
  }
  scanf("%d\n", &num[0]);
  vector<int> m(n, 0);
  for (i = 0; i < n; ++i) {
    char c;
    cin >> c;
    m[n - 1 - i] = c - '0';
  }
  vector<int> sum(n, 0);
  sum[n - 1] = 0;
  for (i = n - 2; i >= 0; --i) {
    sum[i] = sum[i + 1] + num[i + 1];
  }
  int mx = 0;
  int sm = 0;
  for (i = 0; i < n; ++i) {
    if (m[i] == 1) {
      if (mx < sm + sum[i]) {
        mx = sm + sum[i];
      }
      sm += num[i];
    }
  }
  if (sm > mx) mx = sm;
  cout << mx;
  return 0;
}
