#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main() {
  {
    long long int n, i, s = 0, m = 0;
    cin >> n;
    long long int a[n], dp[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
      s += a[i];
      dp[i] = s;
    }
    string str;
    cin >> str;
    s = 0;
    for (i = n - 1; i > 0; i--) {
      if (str[i] == '1') {
        m = max(m, s + dp[i - 1]);
        s += a[i];
      }
    }
    if (str[0] == '1') s += a[0];
    m = max(m, s);
    cout << m;
    cout << '\n';
  }
  return 0;
}
