#include <bits/stdc++.h>
using namespace std;
char M[100100];
int A[100100], onesr[100100], leftone[100100], leftsum[100100];
int N;
void input() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) scanf("%d", A + i);
  scanf("%s", M);
}
void precalc() {
  for (int i = N - 1; i >= 0; --i) {
    onesr[i] = onesr[i + 1] + ((M[i] == '1') ? A[i] : 0);
  }
  leftone[0] = -1;
  leftsum[0] = A[0];
  for (int i = 1; i < N; ++i) {
    if (M[i - 1] == '1')
      leftone[i] = i - 1;
    else
      leftone[i] = leftone[i - 1];
    leftsum[i] = A[i] + leftsum[i - 1];
  }
}
int calc(int idx) {
  int total = 0;
  if (idx >= 0) total = leftsum[idx];
  return total;
}
int main() {
  input();
  precalc();
  int ans = 0;
  bool firstone = false;
  for (int i = N - 1; i >= 0; --i) {
    if (M[i] == '1') {
      ans = std::max<int>(ans, onesr[i] + calc(leftone[i] - 1));
      if (!firstone) {
        firstone = true;
        ans = std::max<int>(ans, calc(i - 1));
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
