#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  scanf("%lld", &n);
  long long a[n];
  long long sum[n + 1];
  memset(sum, 0, sizeof(sum));
  ;
  for (long long i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    sum[i + 1] = sum[i] + a[i];
  }
  string s;
  cin >> s;
  long long ans = 0;
  long long leo = 0;
  for (long long i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      ans = max(ans, leo + sum[i]);
      leo += a[i];
    }
  }
  ans = max(ans, leo);
  cout << ans << "\n";
  return 0;
}
