#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
void debugarr(int* arr, int n) {
  cout << "[";
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << "]" << endl;
}
void debugvec(vector<int> arr) {
  cout << "[";
  for (int i = 0; i < ((int)(arr.size())); i++) cout << arr[i] << " ";
  cout << "]" << endl;
}
int main() {
  int n;
  scanf("%d", &n);
  long long sum[n];
  vector<int> num;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    num.push_back(a);
    if (i == 0)
      sum[i] = a;
    else
      sum[i] = sum[i - 1] + a;
  }
  string str;
  cin >> str;
  long long ans[n];
  memset(ans, 0, sizeof(ans));
  ans[0] = (str[0] == '1' ? num[0] : 0);
  for (int i = 1; i < ((int)(str.size())); i++) {
    if (str[i] == '1')
      ans[i] = ans[i - 1] + num[i];
    else
      ans[i] = ans[i - 1];
  }
  long long final = ans[n - 1];
  for (int i = ((int)(str.size())) - 1; i >= 0; i--) {
    if (str[i] == '1') {
      final = ((final) > (ans[n - 1] - ans[i] + (i > 0 ? sum[i - 1] : 0))
                   ? (final)
                   : (ans[n - 1] - ans[i] + (i > 0 ? sum[i - 1] : 0)));
    }
  }
  cout << final << endl;
  return 0;
}
