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