#include <bits/stdc++.h>
using namespace std;
int n, v[100100];
int dp[100100][2];
char b[100100];
int calc(int i, bool l) {
  if (i == n) return 0;
  if (dp[i][l] == -1) {
    dp[i][l] = calc(i + 1, l || b[i] == '1');
    if (b[i] == '1' || l) dp[i][l] = max(dp[i][l], v[i] + calc(i + 1, l));
  }
  return dp[i][l];
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", v + i);
  reverse(v, v + n);
  scanf("%s", b);
  reverse(b, b + strlen(b));
  for (int i = n - 1; i >= 0; i -= 512) calc(i, 1) + calc(i, 0);
  printf("%d\n", calc(0, 0));
  return 0;
}
