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