#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
string t;
long long int n, a[100005], dp[100005][2];
long long int maxm(long long int ind, long long int f) {
  if (ind < 0) return 0;
  if (dp[ind][f] != -1) return dp[ind][f];
  long long int s;
  if (f == 1)
    s = a[ind] + maxm(ind - 1, 1);
  else if (f == 0) {
    if (t[ind] == '1')
      s = max(maxm(ind - 1, 1), a[ind] + maxm(ind - 1, 0));
    else
      s = maxm(ind - 1, 0);
  }
  dp[ind][f] = s;
  return dp[ind][f];
}
int main() {
  long long int i;
  while (cin >> n) {
    memset(a, 0, sizeof(a));
    for (i = 0; i < n; i++) cin >> a[i];
    cin >> t;
    memset(dp, -1, sizeof(dp));
    long long int ans = maxm(t.size() - 1, 0);
    cout << ans << endl;
  }
  return 0;
}
