#include <bits/stdc++.h>
using namespace std;
inline double ab(double a) { return (a < 0) ? (-(a)) : a; }
inline bool func(double a, double b) { return (a < b); }
inline long long unsigned int gcd(long long unsigned int a,
                                  long long unsigned int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
map<int, int> freq;
int main() {
  long long int n;
  cin >> n;
  long long int a[n + 1];
  long long int sum[n + 1];
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  string s;
  cin >> s;
  long long unsigned int last = 0;
  long long unsigned int f = 0;
  for (int i = s.length() - 1; i >= 0; i--) {
    if (s[i] == '0') continue;
    f = max(f, sum[i] + last);
    last += a[i + 1];
  }
  cout << max(f, last);
  return 0;
}
