#include <bits/stdc++.h>
const int mx = 500000 + 1024;
long long preA[mx], preB[mx], sufA[mx], sufB[mx], val[mx];
char s[mx];
int main() {
  long long n, ans, t;
  while (~scanf("%I64d", &n)) {
    ans = 0LL;
    memset(preA, 0, sizeof(preA));
    memset(preB, 0, sizeof(preB));
    memset(sufA, 0, sizeof(sufA));
    memset(sufB, 0, sizeof(sufB));
    memset(val, 0, sizeof(val));
    memset(s, 0, sizeof(s));
    for (int i = 1; i <= n; i++) scanf("%I64d", &val[i]);
    scanf("%s", s);
    for (int i = 1; i <= n; i++) {
      if (s[i - 1] == 'A')
        preA[i] += preA[i - 1] + val[i], preB[i] = preB[i - 1];
      else
        preB[i] = preB[i - 1] + val[i], preA[i] = preA[i - 1];
    }
    for (int i = n; i >= 0; i--) {
      if (s[i - 1] == 'A')
        sufA[i] = sufA[i + 1] + val[i], sufB[i] = sufB[i + 1];
      else
        sufB[i] = sufB[i + 1] + val[i], sufA[i] = sufA[i + 1];
    }
    for (int i = 0; i <= n; i++) {
      t = std::max(preA[i] + sufB[i + 1], preB[i] + sufA[i + 1]);
      ans = std::max(t, ans);
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
