#include <bits/stdc++.h>
using namespace std;
int n;
long long w[500005], a[500005], b[500005];
char c[500005];
int main() {
  while (~scanf("%d", &n)) {
    for (int i = (1); i <= (n); i++) {
      scanf("%I64d", &w[i]);
    }
    scanf("%s", c);
    a[0] = b[0] = 0;
    for (int i = (1); i <= (n); i++) {
      a[i] = a[i - 1], b[i] = b[i - 1];
      if (c[i - 1] == 'A')
        a[i] += w[i];
      else
        b[i] += w[i];
    }
    long long ans = a[n];
    for (int i = (1); i <= (n); i++) {
      ans = max(ans, max(a[n] - a[i] + b[i], a[i] + b[n] - b[i]));
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
