#include <bits/stdc++.h>
const long long N = 1000006;
using namespace std;
const long long MOD = 1000000007LL;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T power(T x, T y, long long m = MOD) {
  T ans = 1;
  while (y > 0) {
    if (y & 1LL) ans = (ans * x) % m;
    y >>= 1LL;
    x = (x * x) % m;
  }
  return ans % m;
}
long long a[N], pref[N];
int32_t main() {
  long long n;
  cin >> n;
  for (long long(i) = (1); i < (n + 1); i++)
    cin >> a[i], pref[i] = a[i] + pref[i - 1];
  string s;
  cin >> s;
  long long maxi = 0, ct = 0;
  reverse(s.begin(), s.end());
  for (long long(i) = (1); i < (n + 1); i++) {
    if (s[i - 1] == '1') {
      maxi = max(maxi, ct + pref[n - i]);
      ct += a[n - i + 1];
      maxi = max(maxi, ct);
    }
  }
  cout << maxi;
}
