#include <bits/stdc++.h>
using namespace std;
static long long a[100005];
static long long low[100005];
static long long high[100005];
int main() {
  long long n, total = 0, num = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    low[i] = total;
    total += a[i];
  }
  string m;
  cin >> m;
  long long pos = m.find_last_of('1');
  long long lastOne = pos != string::npos ? pos : 0;
  for (int i = n - 1; i >= 0; --i)
    if (m[i] == '1') {
      high[i] = num;
      num += a[i];
    }
  for (int i = lastOne; i >= 0; --i) {
    if (m[i] == '1') num = max(num, low[i] + high[i]);
  }
  cout << num << endl;
  return 0;
}
