#include <bits/stdc++.h>
using namespace std;
long long res;
long long qian[200000], hou[200000];
int a[200000];
char str[200000];
int vis[200000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  scanf("%s", str);
  memset(hou, 0, sizeof(hou));
  for (int i = 0; i < n; ++i)
    if (str[i] == '1')
      vis[i] = 1;
    else
      vis[i] = 0;
  qian[0] = a[0];
  for (int i = 1; i < n; ++i) qian[i] = a[i] + qian[i - 1];
  hou[n - 1] = a[n - 1] * vis[n - 1];
  for (int i = n - 2; i >= 0; --i) hou[i] = hou[i + 1] + a[i] * vis[i];
  res = hou[0];
  for (int i = 1; i <= n; ++i) {
    if (vis[i] == 1) res = max(res, qian[i - 1] + hou[i + 1]);
  }
  cout << res << endl;
}
