#include <bits/stdc++.h>
using namespace std;
int n, ans, k, sum;
int v[100001];
char str[100001];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> v[i];
  cin >> str;
  for (int i = 0; i < n; ++i) {
    if (str[i] == '0')
      k += v[i];
    else {
      if (v[i] > k)
        ans += v[i];
      else {
        ans += k;
        k = v[i];
      }
    }
  }
  cout << ans;
  return 0;
}
