#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const long long mod = 1e9;
#pragma GCC optimize("-O2")
const long long INF = 10000000;
long long getIInput() {
  cout.flush();
  long long x;
  cin >> x;
  return x;
}
void flash() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(9);
}
void solve();
int32_t main() {
  flash();
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
void solve() {
  long long n;
  cin >> n;
  long long arr[n + 1];
  long long a[n + 1];
  long long b[n + 1];
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  string s;
  cin >> s;
  a[0] = 0;
  b[0] = 0;
  for (long long i = 1; i <= n; i++) {
    a[i] = a[i - 1] + arr[i];
    b[i] = b[i - 1];
    if (s[i - 1] == '1') {
      b[i] = b[i] + arr[i];
    }
  }
  long long ans = -1;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '1') ans = max(ans, a[i] + b[n] - b[i + 1]);
  }
  ans = max(ans, b[n]);
  cout << ans << "\n";
  return;
}
