#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 5;
vector<int> v, s;
string str;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, t, ans = 0;
  cin >> n;
  v.resize(n), s.resize(n);
  for (auto &i : v) cin >> i;
  s[0] = v[0];
  for (int i = 1; i < n; ++i) s[i] = s[i - 1] + v[i];
  cin >> str;
  for (int i = 0; i < str.size(); ++i)
    if (str[i] == '1') {
      if (i > 0)
        ans = max(ans + v[i], s[i - 1]);
      else
        ans = v[i];
    }
  cout << ans << '\n';
  return 0;
}
