#include <bits/stdc++.h>
using namespace std;
int n, a[110000], b[110000];
char s[110000];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  scanf("%s", s);
  for (int i = n - 1; i >= 0; --i) b[i] = a[i] * (s[i] == '1') + b[i + 1];
  for (int i = 1; i < n; ++i) a[i] += a[i - 1];
  int res = b[0];
  for (int i = 1; i < n; ++i)
    if (s[i] == '1') res = max(a[i - 1] + b[i + 1], res);
  cout << res << endl;
  return 0;
}
