#include <bits/stdc++.h>
using namespace std;
long long gcd(int x, int y) { return (!y) ? x : gcd(y, x % y); }
int main() {
  int a, n, arr[100000];
  long long sum = 0, ans = 0;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      sum += arr[i];
    else {
      if (arr[i] < sum) {
        ans += sum;
        sum = arr[i];
      } else
        ans += arr[i];
    }
  }
  cout << ans << endl;
  return 0;
}
