#include <bits/stdc++.h>
using namespace std;
int n;
string w;
const int N = 1e5 + 5;
vector<int> a(N);
long long dp[N][2];
long long solve(int p, bool can) {
  if (p < 0) return 0;
  if (dp[p][can] != -1) return dp[p][can];
  long long tot = 0;
  if (w[p] == '0') {
    if (!can) {
      tot = max(tot, solve(p - 1, 0));
    } else {
      tot = max(tot, a[p] + solve(p - 1, 1));
    }
  } else {
    if (!can) {
      tot = max(tot, solve(p - 1, 1));
      tot = max(tot, a[p] + solve(p - 1, 0));
    } else {
      tot = max(tot, a[p] + solve(p - 1, 1));
    }
  }
  return dp[p][can] = tot;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> w;
  memset(dp, -1, sizeof(dp));
  cout << solve(n - 1, 0) << '\n';
  return 0;
}
