#include <bits/stdc++.h>
using namespace std;
long long sum[100000 + 2];
string s;
int n;
int a[100000 + 2];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sum[0] = a[0];
  for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + a[i];
  long long m = -100000000000000ll;
  long long b = 0;
  cin >> s;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '0') continue;
    if (i > 0) m = max(m, sum[i - 1] + b);
    b += a[i];
  }
  m = max(m, b);
  cout << m;
}
