#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10;
int a[MAXN], sum[MAXN];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  reverse(a, a + n);
  string s;
  cin >> s;
  reverse((s).begin(), (s).end());
  for (int i = n - 1; i >= 0; i--) sum[i] = sum[i + 1] + a[i];
  int pos = n;
  for (int i = 0; i < n; i++)
    if (s[i] == '1') {
      pos = i;
      break;
    }
  int ans = 0;
  for (int i = pos + 1; i < n; i++) ans += a[i];
  int cur = a[pos];
  for (int i = pos + 1; i < n; i++) {
    if (s[i] == '1') {
      ans = max(ans, cur + sum[i + 1]);
      cur += a[i];
    }
  }
  ans = max(ans, cur);
  cout << ans << endl;
  return 0;
}
