#include <bits/stdc++.h>
using namespace std;
int arr[100005], pd[100005], pd2[100005];
char s[100005];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%d", arr);
  pd[0] = arr[0];
  for (int i = (1); i < (n); ++i) {
    scanf("%d", &arr[i]);
    pd[i] = pd[i - 1] + arr[i];
  }
  scanf("%s", s);
  pd2[0] = s[0] == '1' ? arr[0] : 0;
  for (int i = (1); i < (n); ++i) {
    pd2[i] = pd2[i - 1] + (s[i] == '1' ? arr[i] : 0);
  }
  int ans = pd2[n - 1];
  for (int i = (0); i < (n); ++i) {
    if (s[i] == '1') {
      int aux = pd2[n - 1] - pd2[i];
      if (i) aux += pd[i - 1];
      ans = max(ans, aux);
    }
  }
  printf("%d\n", ans);
  return 0;
}
