#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<int> t(n + 2);
  for (int i = 1; i <= n; i++) cin >> t[i];
  reverse(t.begin() + 1, t.begin() + n + 1);
  cin >> s;
  reverse(s.begin(), s.end());
  vector<int> sum(n + 2);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + t[i];
  int answer = 0;
  int current_sum = 0;
  for (int i = 1; i <= n; i++)
    if (s[i - 1] == '1') current_sum += t[i];
  answer = max(answer, current_sum);
  for (int i = n; i >= 1; i--) {
    if (s[i - 1] == '0') continue;
    current_sum -= t[i];
    answer = max(answer, current_sum + sum[n] - sum[i]);
  }
  cout << answer;
  return 0;
}
