#include <bits/stdc++.h>
using namespace std;
int val[100050], n, sum[100050], tt[100050];
char m[100050];
void prework() {
  sum[0] = val[0];
  for (int i = 1; i <= n - 1; i++) sum[i] = val[i] + sum[i - 1];
}
void solve() {
  prework();
  int ans = 0;
  int Max = 0;
  int len = strlen(m);
  for (int i = 0; i <= n; i++) tt[i] = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (m[i] == '1') {
      ans += val[i];
      tt[i] = ans;
    }
  }
  for (int i = len - 1; i > 1; i--) {
    if (m[i] == '1') {
      ans = max(ans, tt[i + 1] + sum[i - 1]);
    }
  }
  printf("%d\n", ans);
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i <= n - 1; i++) scanf("%d", &val[i]);
    scanf("%s", m);
    solve();
  }
  return 0;
}
