#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  vector<int> pref(n);
  vector<char> m(n);
  for (int i = int(0); i <= int(n - 1); i++) cin >> arr[i];
  pref[0] = arr[0];
  for (int i = int(1); i <= int(n - 1); i++) pref[i] = pref[i - 1] + arr[i];
  for (int i = int(0); i <= int(n - 1); i++) cin >> m[i];
  long total = 0;
  if (m[0] == '1') total = arr[0];
  for (int i = int(1); i <= int(n - 1); i++) {
    if (m[i] == '1') {
      if (total + arr[i] > pref[i - 1])
        total += arr[i];
      else
        total = pref[i - 1];
    }
  }
  cout << total << '\n';
  return 0;
}
