#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100010];
char s[100010];
void solve() {
  int i, j, ans, val;
  m = n;
  while (m && s[m - 1] == '0') m--;
  if (m == 0) {
    printf("0\n");
    return;
  }
  ans = 0;
  val = 0;
  for (i = 0; i < m; i++)
    if (s[i] == '1') {
      ans = max(ans + a[i], val);
      val += a[i];
    } else {
      for (j = i; j < m && s[j] == '0'; j++) val += a[j];
      i = j - 1;
    }
  printf("%d\n", ans);
}
void input() {
  int i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  scanf("%s", &s);
  solve();
}
int main() {
  input();
  fclose(stdin);
  fclose(stdout);
  return 0;
}
