#include <bits/stdc++.h>
using namespace std;
int N;
int A[101010];
int dp[101010][2];
string S;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  cin >> S;
  dp[0][0] = dp[0][1] = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == '0') {
      dp[i + 1][0] = dp[i][0];
      dp[i + 1][1] = max(dp[i][0] + A[i], dp[i][1] + A[i]);
    } else {
      dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1]);
      dp[i + 1][1] = max(dp[i][0] + A[i], dp[i][1] + A[i]);
    }
  }
  cout << dp[N][0];
  return 0;
}
