#include <bits/stdc++.h>
using namespace std;
string s;
long long sum[100005];
long long a[100005];
long long solve(int index) {
  if (index < 0) {
    return 0;
  }
  if (s[index] == '0') return solve(index - 1);
  long long ans1 = sum[index - 1];
  long long ans2 = solve(index - 1) + a[index];
  return max(ans1, ans2);
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  cin >> s;
  sum[0] = a[0];
  for (int i = 1; i < N; i++) {
    sum[i] = sum[i - 1] + a[i];
  }
  cout << solve(N - 1) << endl;
}
