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