#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-11;
void fast() { std::ios_base::sync_with_stdio(0); }
int n;
vector<int> arr;
string s;
vector<vector<int>> dp;
int calc(int i, int state) {
  if (i == n) return 0;
  int &ret = dp[i][state];
  if (ret != -1) {
    return ret;
  }
  if (state == 1) return ret = calc(i + 1, 1) + arr[i];
  if (s[i] == '0') return ret = calc(i + 1, 0);
  int x = calc(i + 1, 0) + arr[i];
  int y = calc(i + 1, 1);
  return ret = max(x, y);
}
int main() {
  scanf("%d", &n);
  arr.resize(n);
  dp.resize(n);
  for (int i = 0; i < n; i++) dp[i].resize(2, -1);
  for (int &i : arr) scanf("%d", &i);
  cin >> s;
  reverse(arr.begin(), arr.end());
  reverse(s.begin(), s.end());
  printf("%d\n", calc(0, 0));
  return 0;
}
