#include <bits/stdc++.h>
using namespace std;
const long double PI = 2 * acos(0);
const long double eps = 1e-15;
const int inf = 1e9 + 7;
const long long Linf = (long long)1e18 + 7;
const int MOD = 1e9 + 7;
const int LMAX = 1e6 + 7;
const int MAX = 1e5 + 7;
const int BASE = 1e9 + 7;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
long long f1[MAX], f2[MAX];
int a[MAX];
int n;
string s;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = (1); i <= (n); i++) cin >> a[i];
  cin >> s;
  s = " " + s;
  while (s[n] == '0') n--;
  for (int i = (1); i <= (n); i++) {
    f1[i] = f1[i - 1] + a[i];
  }
  for (int i = (n); i >= (1); i--) {
    f2[i] = f2[i + 1] + (s[i] - '0') * a[i];
  }
  long long res = f2[1];
  for (int i = (n); i >= (1); i--) {
    if (s[i] == '1') res = max(res, f2[i + 1] + f1[i - 1]);
  }
  cout << res;
  return 0;
}
