#include <bits/stdc++.h>
using namespace std;
void yes() {
  cout << "YES"
       << "\n";
}
void no() {
  cout << "NO"
       << "\n";
}
struct arra {
  long long d, idx;
} arr[200001];
bool comp(struct arra a, struct arra b) { return (a.d < b.d); }
int main() {
  long long n;
  cin >> n;
  long long int* arr = new long long int[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  string s;
  cin >> s;
  long long int* pre = new long long int[n];
  pre[0] = arr[0];
  long long res = 0;
  for (int i = 1; i < n; i++) pre[i] = pre[i - 1] + arr[i];
  for (int i = 0; i < n; i++) res += (s[i] - '0') * arr[i];
  long long temp = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      if (i != 0) res = max(res, temp + pre[i - 1]);
      temp += arr[i];
    }
  }
  res = max(res, temp);
  cout << res;
  return 0;
}
