#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long int n, ans = 0, fin = 0;
  cin >> n;
  long long int a[n + 10], ps[n + 10];
  string s;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> s;
  ps[0] = 0;
  for (long long int i = 1; i <= n; i++) {
    ps[i] = ps[i - 1] + a[i - 1];
  }
  for (long long int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == '1') {
      ans = max(ans, ps[i] + fin);
      fin += a[i];
      ans = max(ans, fin);
    }
  }
  cout << ans << "\n";
  return 0;
}
