#include <bits/stdc++.h>
using namespace std;
void fastInOut() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
int main() {
  int n, last;
  cin >> n;
  long long sum = 0, sum2 = 0;
  string x;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  cin >> x;
  for (int i = n - 1; i >= 0; --i) {
    if (x[i] == '1')
      sum2 = max(sum2, sum - arr[i]);
    else
      sum -= arr[i];
  }
  cout << max(sum, sum2);
}
