#include <bits/stdc++.h>
using namespace std;
int n;
int inp[200200];
int sum[200200];
char str[200200];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &inp[i]);
  scanf("%s", str);
  int len = strlen(str);
  reverse(inp, inp + n);
  reverse(str, str + len);
  sum[n] = 0;
  for (int i = n - 1; ~i; --i) sum[i] = sum[i + 1] + inp[i];
  int v = 0, ans = 0;
  for (int i = 0; i < len; ++i) {
    if (str[i] == '1') {
      ans = max(ans, v + sum[i + 1]);
      v += inp[i];
    }
    if (0) printf(" << i %2d, v %2d, ans %2d\n", i, v, ans);
  }
  if (0) {
    for (int i = 0; i < n; ++i) printf(" %d\n", inp[i]);
    puts("");
    for (int i = 0; i < n; ++i) printf(" %d\n", sum[i]);
    puts("");
  }
  if (0) printf("< v %d\n", v);
  printf("%d\n", max(ans, v));
  return 0;
}
