#include <bits/stdc++.h>
using namespace std;
long long int a[100001], sum[100001];
int b[100001][2], c[100001][2];
long long int max(long long int x, long long int y) {
  if (x > y) return x;
  return y;
}
string s;
long long int find(long long int x, long long int make) {
  if (b[x][make] == 1) return c[x][make];
  if (x == 0 && make == 0) {
    c[x][make] = (s[0] - 48) * a[0];
    b[x][make] = 1;
    return c[x][make];
  }
  if (x == 0 && make == 1) {
    c[x][make] = s[0] - 48;
    b[x][make] = 1;
    return c[x][make];
  } else if (s[x] == '1') {
    c[x][make] = max(a[x] + find(x - 1, 0), sum[x - 1]);
    b[x][make] = 1;
    return c[x][make];
  } else {
    c[x][make] = find(x - 1, 0);
    b[x][make] = 1;
    return c[x][make];
  }
}
int main() {
  long long int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    b[i][0] = 0;
    b[i][1] = 0;
  }
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    if (i > 0) sum[i] = sum[i - 1] + a[i];
    if (i == 0) sum[0] = a[0];
  }
  cin >> s;
  cout << find(s.length() - 1, 0);
  return 0;
}
