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