#include <bits/stdc++.h>
using namespace std;
char str[500009];
long long p[500009], sum[500009];
int main() {
  int n, i;
  while (scanf("%d", &n) != EOF) {
    memset(sum, 0, sizeof(sum));
    for (i = 1; i <= n; i++) scanf("%d", &p[i]);
    scanf("%s", str + 1);
    for (i = 1; i <= n; i++) {
      if (str[i] == 'B')
        sum[i] = sum[i - 1] + p[i];
      else
        sum[i] = sum[i - 1];
    }
    long long ans = 0, res = 0;
    for (i = 1; i <= n; i++) {
      if (str[i] == 'A') res += p[i];
      ans = max(ans, sum[n] - sum[i - 1] + res);
    }
    res = 0;
    for (i = n; i >= 1; i--) {
      if (str[i] == 'A') res += p[i];
      ans = max(ans, sum[i - 1] + res);
    }
    printf("%lld\n", max(ans, sum[n]));
  }
  return 0;
}
