#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9, PI = 2 * acos(0.0);
const int maxn = 100000 + 100, MOD = 1000 * 1000 * 1000 + 7,
          INF = 1000 * 1000 * 1000;
int a[maxn], sum[maxn];
string s;
int main() {
  int n;
  int i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum[i] = (i ? sum[i - 1] : 0) + a[i];
  }
  cin >> s;
  int sz = s.size();
  int cursum, ans;
  cursum = 0;
  ans = -1;
  for (i = sz - 1; i >= 0; i--) {
    if (s[i] == '1') {
      if (i && ans < cursum + sum[i - 1]) ans = cursum + sum[i - 1];
    }
    cursum += (s[i] == '1' ? a[i] : 0);
  }
  if (ans < cursum) ans = cursum;
  cout << ans << endl;
  return 0;
}
