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