#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
int ans1 = 0, ans2 = 0, cnt[100005];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int j = 0;
  string s;
  cin >> s;
  cnt[0] = a[0];
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '1') {
      j = i;
      ans1 += a[i];
    }
    if (i > 0) cnt[i] = cnt[i - 1] + a[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      if (i) ans1 = max(ans1, cnt[i - 1] + ans2);
      ans2 += a[i];
    }
  }
  cout << ans1;
  return 0;
}
