#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n;
  cin >> n;
  long long a[n];
  for (auto &i : a) cin >> i;
  string s;
  cin >> s;
  long long allprevset = 0;
  long long ans = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] == '1') ans = max(ans + a[i], allprevset);
    allprevset += a[i];
  }
  cout << ans;
}
