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