#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 123;
int dp[N][2], a[N];
int n;
int small = INT_MIN;
int large = INT_MAX;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  string m;
  cin >> m;
  int ms = m.size();
  m = '#' + m;
  dp[ms + 1][1] = -2e9;
  for (int i = ms; i > 0; --i) {
    int cur = m[i] - '0';
    if (cur == 0) {
      dp[i][1] = dp[i + 1][1] + a[i];
      dp[i][0] = dp[i + 1][0];
    } else {
      dp[i][1] = max(a[i] + dp[i + 1][1], dp[i + 1][0]);
      dp[i][0] = dp[i + 1][0] + a[i];
    }
  }
  cout << max(dp[1][1], dp[1][0]);
  return 0;
}
