#include <bits/stdc++.h>
using namespace std;
long long ans = 0, ar[100001], n, ll, ars[100001];
string s;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ars[i]);
    ar[i] = ar[i - 1] + ars[i];
  }
  cin >> s;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      ans = max(ans, ar[i] + ll);
    }
    if (s[i] == '1') ll += (ars[i + 1]);
  }
  ans = max(ans, ll);
  cout << ans;
  return 0;
}
