#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  int sum = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == '1') sum += a[i];
  int ans = sum;
  for (int i = 0, acc = 0; i < n; i++) {
    if (s[i] == '1') {
      sum -= a[i];
      ans = max(ans, sum + acc);
    }
    acc += a[i];
  }
  cout << ans << '\n';
  return 0;
}
