#include <bits/stdc++.h>
using namespace std;
int a[1000 * 100 + 10];
int par[1000 * 100 + 10];
string s;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      par[0] = a[0];
    else
      par[i] = par[i - 1] + a[i];
  }
  cin >> s;
  int ans = 0;
  int kol = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      ans = max(ans, i > 0 ? par[i - 1] + kol : 0);
      kol += a[i];
    }
  }
  cout << max(ans, kol) << endl;
  return 0;
}
