#include <bits/stdc++.h>
using namespace std;
inline void inpint(int &n) {
  n = 0;
  register int ch = getchar_unlocked();
  bool sign = 0;
  while (ch < 48 || ch > 57) {
    if (ch == '-') sign = 1;
    ch = getchar_unlocked();
  }
  while (ch >= 48 && ch <= 57) {
    n = (n << 3) + (n << 1) + ch - 48, ch = getchar_unlocked();
  }
  if (sign) n = -n;
}
inline int sqr(int x) { return x * x; }
inline int cube(int x) { return x * x * x; }
inline long long sqrLL(long long x) { return x * x; }
inline long long cubeLL(long long x) { return x * x * x; }
const long long LLINF = 9223372036854775807LL;
const long long LLINF17 = 100000000000000000LL;
const int INF = 2147483647;
const int INF9 = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-7;
const double PI = acos(-1.0);
int dr[] = {1, 0, -1, 0, -1, 1, 1, -1};
int dc[] = {0, -1, 0, 1, 1, 1, -1, -1};
int n, arr[100005];
char str[100005];
int memo[100005][2];
inline int dp(int pos, bool less) {
  if (pos == n + 1) return 0;
  int &ret = memo[pos][less];
  if (ret != -1) return ret;
  ret = -INF9;
  if (less) {
    for (int i = 0; i <= 1; i++) {
      (ret) = max((ret), (arr[pos] * i + dp(pos + 1, 1)));
    }
  } else {
    int cur = str[pos] - '0';
    for (int i = 0; i <= cur; i++) {
      if (i == 0) {
        (ret) = max((ret), (dp(pos + 1, i != cur)));
      } else {
        (ret) = max((ret), (arr[pos] * i + dp(pos + 1, i != cur)));
      }
    }
  }
  return ret;
}
int main() {
  cin >> n;
  memset(memo, -1, sizeof(memo));
  for (int(i) = (1); (i) <= (n); (i)++) cin >> arr[i];
  scanf("%s", str + 1);
  int lo = 1, hi = n;
  while (lo <= hi) {
    swap(str[lo], str[hi]);
    swap(arr[lo], arr[hi]);
    lo++;
    hi--;
  }
  printf("%d\n", dp(1, 0));
  return 0;
}
