#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e5 + 100;
const long long maxM = 1e3 + 100;
const long long mod = 1e9 + 7;
const long long hmod = 1e16 + 7;
const long double PI = 3.141592653;
const long double eps = 1e-8;
const long long D = 1379;
const long long INF = 1e18 + 20;
const long long Inf = 1e9 + 140;
void NO() {
  cout << "NO" << endl;
  exit(0);
}
void YES() {
  cout << "YES" << endl;
  exit(0);
}
long long n, a[maxN], sum[maxN], ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    sum[i] = (i ? sum[i - 1] : 0) + a[i];
  }
  string s;
  cin >> s;
  long long mx = 0;
  for (long long i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      ((mx) = max((mx), (ans + sum[i - 1])));
      ans += a[i];
    }
  }
  cout << max(ans, mx) << endl;
}
