#include <bits/stdc++.h>
char s[(int)1e6];
int p[(int)1e6];
int main() {
  int n, i, len;
  long long bp, tm, mx;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  getchar();
  gets(s);
  bp = 0;
  len = strlen(s);
  for (i = 0; i < len; i++) {
    if (s[i] == 'B') bp += p[i];
  }
  mx = bp;
  tm = bp;
  for (i = 0; i < len; i++) {
    if (s[i] == 'A')
      bp += p[i];
    else
      bp -= p[i];
    if (bp > mx) mx = bp;
  }
  bp = tm;
  for (i = len - 1; i >= 0; i--) {
    if (s[i] == 'A')
      bp += p[i];
    else
      bp -= p[i];
    if (bp > mx) mx = bp;
  }
  printf("%I64d\n", mx);
  return 0;
}
