#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 10;
int num[maxn];
int main() {
  int n, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
    sum += num[i];
  }
  string str;
  cin >> str;
  int i = n - 1, ans = 0;
  while (i >= 0) {
    while (i >= 0 && str[i] == '0') {
      sum -= num[i];
      i--;
    }
    if (i < 0) break;
    ans = max(ans, sum - num[i]);
    i--;
  }
  int t = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == '1') t += num[i];
  }
  ans = max(ans, t);
  cout << ans;
}
