#include <bits/stdc++.h>
using namespace std;
const double PI = (double)3.141592653589793238462643383279502884L;
const long long MOD = 1000000007;
template <typename T>
T gcd(T a, T b) {
  return a == 0 ? b : gcd(b % a, a);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
string toString(T x) {
  if (x == 0) return "0";
  bool negative = false;
  if (x < 0) {
    negative = true;
    x *= -1;
  }
  string res;
  while (x) {
    res.push_back('0' + (x % 10));
    x /= 10;
  }
  if (negative) res.push_back('-');
  reverse(res.begin(), res.end());
  return res;
}
void ioFromFile(string inputFileName = "input.txt",
                string outputFileName = "output.txt") {
  ifstream* fin = new ifstream(inputFileName);
  ofstream* fout = new ofstream(outputFileName);
  cin.rdbuf(fin->rdbuf());
  cout.rdbuf(fout->rdbuf());
}
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
void write(int x) { printf("%d ", x); }
int main() {
  int n = read();
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    a[i] = read();
  }
  reverse(a.begin(), a.end());
  vector<int> suf(n + 1);
  for (int i = n - 1; i >= 0; i--) {
    suf[i] = suf[i + 1] + a[i];
  }
  string s;
  cin >> s;
  for (char& c : s) c -= '0';
  reverse(s.begin(), s.end());
  int res = 0;
  int cur = 0;
  for (int i = 0; i < n; i++) {
    if (s[i]) {
      int alt = cur + suf[i + 1];
      cur += a[i];
      res = max(res, cur);
      res = max(res, alt);
    }
  }
  write(res);
  return 0;
}
