#include <bits/stdc++.h>
using namespace std;
void fast();
long long power(long long n, long long k) {
  if (k == 0) return 1;
  long long sq = power(n, k / 2);
  sq = sq * sq;
  if (k % 2 == 1) sq = sq * n;
  return sq;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int arr[100000 + 50];
int sum_[100000 + 50];
int main() {
  fast();
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  string s;
  cin >> s;
  int maxi = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1')
      sum_[i] = arr[i];
    else
      sum_[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    sum_[i] += sum_[i - 1];
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') sum += arr[i];
  }
  maxi = max(sum, maxi);
  for (int i = 1; i <= n; i++) {
    arr[i] += arr[i - 1];
  }
  for (int i = 1; i < n; i++) {
    if (s[i] == '1') {
      maxi = max(maxi, sum_[n - 1] - sum_[i] + arr[i - 1]);
    }
  }
  cout << maxi;
  return 0;
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
