#include <bits/stdc++.h>
using namespace std;
stringstream ss;
long long mod = 1000000007LL;
long long a[100010], sum[100010];
int main() {
  int n;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum[i] = (i ? sum[i - 1] : 0) + a[i];
  }
  cin >> s;
  long long mx = 0, now = 0;
  for (int i = s.size() - 1; i >= 0; i--)
    if (s[i] == '1') {
      mx = max(mx, now + (i ? sum[i - 1] : 0));
      now += a[i];
    }
  mx = max(mx, now);
  cout << mx << endl;
  return 0;
}
