#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') sum += a[i];
  }
  long long int pr[n + 1];
  pr[0] = 0;
  for (int i = 1; i <= n; i++) {
    pr[i] = pr[i - 1] + a[i - 1];
  }
  long long int ans = sum;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      sum = sum - a[i];
      ans = max(ans, pr[i] + sum);
    }
  }
  cout << ans;
}
