#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-12;
const int INF = (1 << 31) - 1;
const long long LLINF = ((long long)1 << 62) - 1;
const int maxn = 1000 * 100 + 10;
int a[maxn], sum[maxn], sum2[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i)
      sum[i] = sum[i - 1] + a[i];
    else
      sum[i] = a[i];
  }
  string s;
  getline(cin, s);
  getline(cin, s);
  for (int i = (int)s.size() - 1; i >= 0; i--) {
    if (i != (int)s.size() - 1) {
      sum2[i] = sum2[i + 1] + (s[i] - '0') * a[i];
    } else {
      sum2[i] = (s[i] - '0') * a[i];
    }
  }
  long long maxx = 0LL;
  for (int i = (int)s.size() - 1; i >= 0; i--) {
    if (s[i] == '1') {
      long long cur = 0LL;
      cur = sum[i - 1];
      cur += sum2[i + 1];
      maxx = max(maxx, cur);
    }
  }
  printf("%lld", max(maxx, (long long)sum2[0]));
  return 0;
}
