#include <bits/stdc++.h>
using namespace std;
string m;
int v[100010], n, a[100010], b[100010];
int main() {
  ios_base::sync_with_stdio(0);
  while (cin >> n) {
    for (int i = 0; i < n; ++i) cin >> v[i];
    a[0] = v[0];
    for (int i = 1; i < n; ++i) a[i] = a[i - 1] + v[i];
    cin >> m;
    b[0] = m[0] == '1' ? v[0] : 0;
    for (int i = 1; i < n; ++i) b[i] = b[i - 1] + (m[i] == '1' ? v[i] : 0);
    int res = b[n - 1];
    for (int i = 0; i < n; ++i)
      if (m[i] == '1') res = max(res, a[i - 1] + b[n - 1] - b[i]);
    cout << res << endl;
  }
  return 0;
}
