#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[100010];
  int tot = 0;
  int dp[100010];
  cin >> a[0];
  dp[0] = a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    dp[i] = dp[i - 1] + a[i];
  }
  string s;
  cin >> s;
  s += '0';
  int dp1[100010] = {0};
  for (int i = n - 1; i >= 0; i--) {
    dp1[i] = dp1[i + 1] + (s[i] - '0') * a[i];
  }
  int mx = 0;
  int sm = 0;
  for (int i = 0; i < n; i++) {
    if (s[i + 1] == '1') {
      mx = max(mx, dp[i] + dp1[i + 2]);
    }
  }
  cout << max(mx, dp1[0]) << endl;
  return 0;
}
