#include <bits/stdc++.h>
using namespace std;
template <typename T>
void dbg(T t) {
  cerr << t << endl;
}
template <typename T, typename... Args>
void dbg(T t, Args... args) {
  cerr << t << " ";
  dbg(args...);
}
long long sum[100001];
int t[100001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n;
  cin >> n;
  string s;
  for (int i = 0; i < n; i++) cin >> t[i];
  cin >> s;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      sum[i] = t[i];
    else
      ans += t[i];
  }
  long long mx_gain = 0;
  long long org = ans;
  for (int i = 0; i < n - 1; i++) sum[i + 1] += sum[i];
  for (int i = n - 1; i > 0; i--) {
    int mn = INT_MAX;
    while (s[i] == '1') {
      mn = min(mn, t[i]);
      i--;
    }
    ans = max(ans, org + sum[i] - mn);
  }
  cout << ans << endl;
}
