#include <bits/stdc++.h>
using namespace std;
using namespace std;
int a[100010], acum[100010];
char s[100010];
int main() {
  int n, ret1 = 0, ret2 = 0, ret = 0;
  scanf("%d", &n);
  for (int i = int(0); i <= int(n - 1); i++) {
    scanf("%d", &a[i]);
    acum[i] = a[i];
  }
  for (int i = int(1); i <= int(n - 1); i++) acum[i] += acum[i - 1];
  scanf("%s", s);
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      ret2 = ret1, ret1 += a[i];
      if (i) ret2 += acum[i - 1];
      ret = max(ret, ret2);
    }
  }
  printf("%d\n", max(ret1, ret));
  return 0;
}
