#include <bits/stdc++.h>
using namespace std;
int A[100001];
int preSum[100001];
int suffSum[100001];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  string str;
  cin >> str;
  preSum[0] = A[0];
  for (int i = 1; i < n; i++) preSum[i] = A[i] + preSum[i - 1];
  if (str[str.length() - 1] == '1') suffSum[n - 1] = A[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    suffSum[i] += suffSum[i + 1];
    if (str[i] == '1') suffSum[i] += A[i];
  }
  int maX = 0;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '1') maX += A[i];
  }
  maX = max(maX, suffSum[1]);
  for (int i = 1; i < n - 1; i++) {
    if (str[i] == '1') maX = max(maX, preSum[i - 1] + suffSum[i + 1]);
  }
  if (str[n - 1] == '1') maX = max(maX, preSum[n - 2]);
  cout << maX << endl;
  return 0;
}
