#include <bits/stdc++.h>
using namespace std;
const int SIZE = 5 * 1e5 + 1;
int p[SIZE], n;
char s[SIZE];
long long pr[SIZE], pr_n[SIZE];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &p[i]);
  scanf("%s", s);
  pr[0] = (s[0] == 'A') ? p[0] : 0;
  pr_n[0] = (s[0] == 'B') ? p[0] : 0;
  for (int i = 1; i < n; i++) {
    pr[i] = pr[i - 1] + (s[i] == 'A') * (p[i]);
    pr_n[i] = pr_n[i - 1] + (s[i] == 'B') * (p[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++)
    ans = max(ans,
              max(pr[i] + pr_n[n - 1] - pr_n[i], pr_n[i] + pr[n - 1] - pr[i]));
  printf("%lld", ans);
  return 0;
}
