#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int arr[maxn], sum[maxn];
int dp[maxn][2];
string m;
int solve(int cur, bool grt) {
  if (cur < 0) return 0;
  if (dp[cur][grt] != -1) return dp[cur][grt];
  if (grt)
    return sum[cur];
  else {
    if (m[cur] == '0')
      dp[cur][grt] = solve(cur - 1, 0);
    else
      dp[cur][grt] = max(solve(cur - 1, 1), arr[cur] + solve(cur - 1, 0));
  }
  return dp[cur][grt];
}
int main() {
  int n, i, j;
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    if (i == 0)
      sum[0] = arr[i];
    else
      sum[i] = sum[i - 1] + arr[i];
  }
  cin >> m;
  printf("%d\n", solve(m.size() - 1, 0));
  return 0;
}
