#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 10;
int a[Maxn];
char c[Maxn];
int n;
int f[Maxn][2];
bool done[Maxn][2];
int F(int i, int les) {
  if (i == n) return 0;
  if (done[i][les]) return f[i][les];
  done[i][les] = true;
  f[i][les] = F(i + 1, les || c[i] == '1');
  if (les || c[i] == '1') f[i][les] = max(f[i][les], F(i + 1, les) + a[i]);
  return f[i][les];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  reverse(a, a + n);
  cin >> c;
  reverse(c, c + n);
  cout << F(0, 0);
}
