#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int a[100010], sum[100010];
char s[100010];
inline void solve() {
  int n;
  scanf("%d", &n);
  sum[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  scanf("%s", s + 1);
  int ans = 0, tmp = 0;
  for (int i = n + 1 - 1; i >= 1; i--) {
    if (s[i] == '1') {
      ans = max(ans, tmp + sum[i - 1]);
      tmp += a[i];
    }
  }
  printf("%d\n", max(ans, tmp));
}
int main() {
  solve();
  return 0;
}
