#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
string s;
void input();
void solve() {
  vector<long long> val(n, 0), pref(n, 0);
  pref[0] = a[0];
  for (int i = 0; i < n; i++) {
    val[i] = a[i] * (s[i] - '0');
  }
  for (int i = 1; i < n; i++) {
    val[i] += val[i - 1];
    pref[i] += pref[i - 1] + a[i];
  }
  long long ans = val[n - 1];
  for (int i = n - 1; i > 0; i--) {
    if (s[i] == '0') continue;
    long long cur = pref[i - 1] + (val[n - 1] - val[i]);
    ans = max(ans, cur);
  }
  cout << ans << "\n";
}
void Clear() {}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  input();
  solve();
  Clear();
}
void input() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    a.push_back(p);
  }
  cin >> s;
}
