#include <bits/stdc++.h>
using namespace std;
int a[120000], d[120000], n, t, ans;
string s;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  reverse(a, a + n);
  for (int i = 0; i < n; i++) {
    if (i)
      d[i] = d[i - 1] + a[i];
    else
      d[i] = a[i];
  }
  cin >> s;
  reverse(s.begin(), s.end());
  for (int i = 0; i < n; i++) ans += (s[i] - '0') * a[i];
  for (int i = 0; i < n; i++)
    if (s[i] == '1') {
      if (t + d[n - 1] - d[i] > ans) {
        ans = d[n - 1] + t - d[i];
      }
      t += a[i];
    }
  cout << ans;
  return 0;
}
