#include <bits/stdc++.h>
using namespace std;
int n;
long long r, p[500010], b[500010], a[500010];
char c;
int main() {
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) scanf("%lld", &p[i]);
  scanf(" %c", &c);
  if (c == 'A')
    a[0] = p[0];
  else
    b[0] = p[0];
  for (int i = 1; i < n; i++) {
    scanf(" %c", &c);
    a[i] = a[i - 1];
    b[i] = b[i - 1];
    if (c == 'A')
      a[i] += p[i];
    else
      b[i] += p[i];
  }
  r = b[n - 1];
  for (int i = 0; i < n; i++) r = max(r, b[n - 1] - b[i] + a[i]);
  for (int i = 0; i < n; i++) r = max(r, a[n - 1] - a[i] + b[i]);
  printf("%lld\n", r);
}
