#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-7;
const double PI = acos(-1.0);
const int N = 1e5 + 5;
long long n, a[N];
string m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cin >> m;
  long long maxx = 0;
  vector<long long> pre(n + 1);
  for (int i = 0; i < (int)m.size(); ++i) {
    if (m[i] == '1') {
      maxx += a[i];
      pre[i] = a[i];
    }
  }
  for (int i = n - 2; i >= 0; --i) {
    pre[i] += pre[i + 1];
  }
  for (int i = 1; i < n; ++i) {
    a[i] += a[i - 1];
  }
  for (int i = 0; i < n; ++i) {
    if (m[i] == '1') {
      maxx = max(maxx, (i ? a[i - 1] : 0) + pre[i + 1]);
    }
  }
  cout << maxx << '\n';
}
