#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
bool comp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first > b.first;
}
vector<int> adj[100005];
bool vis[100005] = {false};
int cats[100005];
int paths = 0;
int m;
void dfs(int par, int k) {
  vis[par] = true;
  if (k > m) {
    return;
  } else if ((int)adj[par].size() == 1 && par != 1) {
    paths++;
  } else {
    for (auto i : adj[par]) {
      if (!vis[i]) {
        if (cats[i] == 1)
          dfs(i, k + 1);
        else
          dfs(i, 0);
      }
    }
  }
}
void solve(int t) {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  string s;
  cin >> s;
  int ma = 0;
  int pref_sum1[n + 1];
  pref_sum1[0] = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == '1') {
      pref_sum1[i] = pref_sum1[i - 1] + arr[i - 1];
    } else
      pref_sum1[i] = pref_sum1[i - 1];
  }
  int pref_sum2[n + 1];
  pref_sum2[0] = 0;
  for (int i = 1; i <= n; i++) {
    pref_sum2[i] = pref_sum2[i - 1] + arr[i - 1];
  }
  ma = max(ma, pref_sum1[n]);
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == '1') {
      int x = pref_sum2[i - 1] + pref_sum1[n] - pref_sum1[i];
      ma = max(ma, x);
    }
  }
  cout << ma;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  for (int i = 0; i < t; i++) {
    solve(i);
    if (i < t - 1) cout << "\n";
  }
  return 0;
}
