#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  long long int sum = 0, x = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') sum = max(sum + a[i], x);
    x += a[i];
  }
  cout << sum << endl;
}
