#include <bits/stdc++.h>
using namespace std;
void read_file(bool outToFile = true) {}
int n;
int A[1000000 + 9], M[1000000 + 9];
int memo[1000000 + 9][2];
int rec(int i, bool em) {
  if (i == -1) return 0;
  int &ret = memo[i][em];
  if (ret != -1) return ret;
  ret = 0;
  int mx = em && M[i] == 0 ? 0 : 1;
  for (int d = 0; d <= mx; d++) {
    bool nem = em && d < M[i] ? 0 : em;
    ret = max(ret, d * A[i] + rec(i - 1, nem));
  }
  return ret;
}
int main() {
  read_file();
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);
    for (int i = 0; i < n; i++) scanf("%1d", &M[i]);
    int ans;
    memset(memo, -1, sizeof memo);
    ans = rec(n - 1, 1);
    printf("%d\n", ans);
  }
}
