#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const long long inf = 0x3f3f3f3f3f3f3f3fLL;
const long long N = 3e5 + 10;
const long long MOD = 1e9 + 7;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  reverse(a.begin(), a.end());
  vector<long long> p(n);
  p[0] = a[0];
  for (long long i = 1; i < n; i++) p[i] = p[i - 1] + a[i];
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '1') ans += a[i];
  }
  long long S = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '1') {
      ans = max(ans, S + p[n - 1] - p[i]);
    }
    S += (s[i] == '1' ? a[i] : 0);
  }
  cout << ans;
  return 0;
}
