#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long n, arr[maxn], arr1[maxn], arr2[maxn];
char c[maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    arr1[i] = arr1[i - 1] + arr[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    if (c[i] == '0') {
      arr2[i] = arr2[i - 1];
    } else {
      arr2[i] = max(arr2[i - 1] + arr[i], arr1[i - 1]);
    }
  }
  cout << arr2[n];
  return 0;
}
