#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  string s;
  cin >> s;
  int c1[n], c2[n];
  c2[0] = a[0];
  if (s[0] == '1')
    c1[0] = a[0];
  else
    c1[0] = 0;
  for (int i = 1; i < n; i++) {
    c1[i] = c1[i - 1];
    c2[i] = c2[i - 1] + a[i];
    if (s[i] == '1') {
      c1[i] += a[i];
    }
  }
  int last, ans = c1[n - 1];
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      last = i;
      break;
    }
  }
  for (int i = 1; i <= last; i++) {
    if (s[i] == '1') {
      ans = max(ans, c2[i - 1] + c1[n - 1] - c1[i]);
    }
  }
  printf("%d", ans);
}
