#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, x;
  cin >> n;
  long long int numbers[n], ones_c[n], zeros_c[n];
  char ones_zeros[n];
  for (i = 0; i < n; i++) scanf("%lld", &numbers[i]);
  scanf("%s", &ones_zeros);
  for (i = 0; i < n; i++) {
    ones_c[i] = 0;
    zeros_c[i] = 0;
  }
  if (ones_zeros[0] == '1')
    ones_c[0] = numbers[0];
  else
    zeros_c[0] = numbers[0];
  for (i = 1; i < n; i++)
    if (ones_zeros[i] == '1')
      ones_c[i] = ones_c[i - 1] + numbers[i];
    else
      ones_c[i] = ones_c[i - 1];
  for (i = 1; i < n; i++)
    if (ones_zeros[i] == '0')
      zeros_c[i] = zeros_c[i - 1] + numbers[i];
    else
      zeros_c[i] = zeros_c[i - 1];
  long long int maxx = 0, sum = 0;
  for (i = 1; i < n; i++) {
    if (ones_zeros[i] == '1') sum = zeros_c[i] + ones_c[n - 1] - numbers[i];
    if (sum > maxx) maxx = sum;
  }
  cout << max(ones_c[n - 1], maxx);
  return 0;
}
