#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const double PI = acos(-1.0);
const int N = 1e5 + 100;
long long ma[N], sum[N];
char st[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    ma[i] += ma[i - 1] + a;
  }
  scanf(" %s", st);
  long long mx = 0;
  for (int i = 0; i < n; i++) {
    if (st[i] == 49) {
      sum[i + 1] = ma[i + 1] - ma[i];
      mx += sum[i + 1];
    }
  }
  for (int i = 1; i <= n; i++) sum[i] += sum[i - 1];
  while (st[n - 1] == 48) n--;
  mx = max(mx, ma[n - 1]);
  for (int i = 0; i < n - 1; i++) {
    if (st[i] == 49) mx = max(mx, ma[i] + sum[n] - sum[i + 1]);
  }
  cout << mx;
  puts("");
  return 0;
}
