#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int s[100005];
char m[100005];
int main() {
  int i, j, k, t, max = 0;
  cin >> n;
  for (i = 0; i <= n; i++) s[i] = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    s[i] = s[i - 1] + a[i];
  }
  cin >> m;
  i = n;
  t = 0;
  while (i >= 1) {
    if (m[i - 1] == '1') {
      if (max < s[i - 1] + t) max = s[i - 1] + t;
      t += a[i];
    }
    i--;
  }
  if (max < t) max = t;
  cout << max;
  return 0;
}
