#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> arr(n);
  for (long long i = 0; i < n; i++) cin >> arr[i];
  reverse(arr.begin(), arr.end());
  string m;
  cin >> m;
  reverse(m.begin(), m.end());
  vector<long long> prefix(n + 1, 0);
  for (long long i = n - 1; i >= 0; i--) {
    prefix[i] = prefix[i + 1] + arr[i];
  }
  long long curr_sum = 0;
  long long max_sum = 0;
  for (int i = 0; i < n; i++) {
    if (m[i] == '0') continue;
    max_sum = max(max_sum, curr_sum + prefix[i + 1]);
    curr_sum += arr[i];
    max_sum = max(max_sum, curr_sum);
  }
  cout << max_sum << endl;
  return 0;
}
