#include <bits/stdc++.h>
using namespace std;
void IOS() {
  ios::sync_with_stdio(false);
  cout.precision(10);
  cout << fixed;
}
const long long MOD = 1e9 + 7;
const long long mx = 1e5 + 5;
long long i, j, k;
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }
int32_t main() {
  IOS();
  long long n;
  cin >> n;
  vector<long long> ar(n);
  for ((i) = 0; (i) < (long long)(n); (i)++) cin >> ar[i];
  string s;
  cin >> s;
  long long insum = 0;
  long long pref[n + 1];
  pref[0] = 0;
  long long last_idx = 0;
  for ((i) = 0; (i) < (long long)(n); (i)++) {
    if (s[i] == '1') {
      insum += ar[i];
      last_idx = max(last_idx, i);
    }
  }
  for (long long i = 0; i < n; i++) pref[i + 1] = pref[i] + ar[i];
  long long cur = 0;
  long long ans = 0;
  for (long long i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      ans = max(ans, cur + pref[i]);
      cur += ar[i];
    }
  }
  cout << max(ans, insum) << "\n";
  return 0;
}
