#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int n, m, s, index = -1, j, cnt = 0;
  string str;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> str;
  for (int i = 0; i < n; i++) {
    if (str[i] == '1') {
      index = i;
      cnt++;
    }
  }
  if (cnt == 0) {
    cout << 0;
  } else if (cnt == 1) {
    s = 0;
    m = a[index];
    for (int i = 0; i < index; i++) {
      s += a[i];
    }
    cout << max(m, s);
  } else {
    s = 0;
    m = 0;
    for (int i = 0; i < index; i++) {
      s += a[i];
    }
    m = max(s, m);
    s = 0;
    for (int i = 0; i < n; i++) {
      if (str[i] == '1') {
        s += a[i];
      }
    }
    m = max(m, s);
    s = 0;
    for (int i = 0; i < index; i++) {
      s += a[i];
    }
    j = index - 1;
    while (j >= 0) {
      while (j >= 0 && str[j] != '1') {
        s -= a[j];
        j--;
      }
      if (j >= 0) {
        s -= a[j];
      }
      s += a[index];
      m = max(m, s);
      if (j >= 0) {
        index = j;
      }
      j--;
    }
    cout << m;
  }
  return 0;
}
