#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vll = vector<ll>;
using si = set<int>;
using sll = set<ll>;
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vll a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vi s(n);
  for (int i = 0; i < n; i++) {
    char x;
    cin >> x;
    s[i] = x - '0';
  }
  vll pref(n);
  pref[0] = a[0];
  for (int i = 1; i < n; i++) {
    pref[i] = pref[i - 1] + a[i];
  }
  vll pref_num(n);
  pref_num[n - 1] = s[n - 1] * a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    pref_num[i] = pref_num[i + 1] + s[i] * a[i];
  }
  ll ans = pref_num[0];
  for (int i = 1; i < n; i++) {
    if (s[i]) {
      ll cur = pref[i - 1];
      if (i + 1 < n) cur += pref_num[i + 1];
      ans = max(ans, cur);
    }
  }
  cout << ans << endl;
  return 0;
}
