#include <bits/stdc++.h>
using namespace std;
inline long long IN() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void OUT(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    OUT(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int N = 500005;
int n, a[N];
char s[N];
long long pre[N], suf[N], Sum;
int main() {
  n = IN();
  for (int i = 1; i <= n; i++) a[i] = IN();
  scanf("%s", s + 1);
  pre[0] = 0, Sum = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'A')
      pre[i] = pre[i - 1] + a[i];
    else
      pre[i] = pre[i - 1] - a[i], Sum += a[i];
  }
  suf[n + 1] = 0;
  for (int i = n; i >= 1; i--) {
    if (s[i] == 'A')
      suf[i] = suf[i + 1] + a[i];
    else
      suf[i] = suf[i + 1] - a[i];
  }
  long long Ans = 0;
  for (int i = 1; i <= n; i++) Ans = max(Ans, max(pre[i], suf[i]));
  OUT(Ans + Sum);
}
