#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 100000000;
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
long long r[((int)1e5) + 10], l[((int)1e5) + 10];
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  string s;
  cin >> s;
  for (int i = 0; i < (n); i++) {
    if (s[i] == '0') {
      l[i + 1] = l[i];
    } else {
      l[i + 1] = max(l[i] + a[i], r[i]);
    }
    r[i + 1] = r[i] + a[i];
  }
  cout << l[n] << endl;
  return 0;
}
