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