#include <bits/stdc++.h>
using namespace std;
long long n, a[500000], kq, k, x, b[500000];
string s;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> s;
  kq = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == '1') kq = kq + a[i];
  for (int i = 0; i < n; i++) b[i] = b[i - 1] + a[i];
  k = 0;
  for (int i = n - 1; i >= 0; i--)
    if (s[i] == '1') {
      kq = max(kq, max(k + a[i], k + b[i - 1]));
      k += a[i];
    }
  cout << kq;
}
