#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
const long double PI =
    3.141592653589793238462643383279502884197169399375105820974944;
inline void io() {}
const long long mod = 1e18 + 7;
const long long maxn = 1e5 + 5;
long long a[maxn];
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '1') ans += a[i];
  }
  long long cur = 0, z = ans;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '1') z -= a[i];
    if (s[i] == '1') ans = max(cur + z, ans);
    cur += a[i];
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(16);
  long long tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
