#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &i : a) cin >> i;
  string s;
  cin >> s;
  vector<int> memo(n, a[0] * (s[0] == '1'));
  vector<int> prefx(n, a[0]);
  for (int i = 1; i < n; i++)
    memo[i] = memo[i - 1] + a[i] * (s[i] == '1'),
    prefx[i] = prefx[i - 1] + a[i];
  int ans = memo[n - 1];
  for (int i = n - 1; i >= 0; i--) {
    if (prefx[i] > memo[i] + a[i] && s[i] == '1') {
      ans = max(memo[n - 1] + prefx[i] - a[i] - memo[i], ans);
    }
  }
  cout << ans << "\n";
  return 0;
}
