#include <bits/stdc++.h>
using namespace std;
inline void FAST_IO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
vector<int> in(100000);
string s;
int n;
int j = 0;
int tb[100000][2];
int dp(int i, bool can) {
  if (i == n) return 0;
  if (tb[i][can] != -1) return tb[i][can];
  int limit = can ? 1 : s[i] - '0';
  int max = 0;
  for (int d = 0; d <= limit; ++d) {
    if (d == 0) {
      if (s[i] == '1')
        max = dp(i + 1, true);
      else
        max = dp(i + 1, can);
    } else if (d == 1) {
      max = std::max(max, dp(i + 1, can) + in[i]);
    }
  }
  return tb[i][can] = max;
}
int main() {
  FAST_IO();
  memset(tb, -1, sizeof(tb));
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> in[i];
  cin >> s;
  reverse(in.begin(), in.begin() + n);
  reverse(s.begin(), s.end());
  while (s[j] == '0' && j < n) j++;
  cout << dp(j, false) << endl;
  return 0;
}
