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