#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
int F[N];
char L[N];
int main(void) {
  int n, t;
  cin >> n;
  long long pA = 0, pB = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &F[i]);
  }
  scanf("%s", L);
  long long dL = 0, dR = 0, res = 0;
  char u;
  for (int i = 0; i < n; i++) {
    if (L[i] == 'A') {
      dL += F[i];
      pA += F[i];
    } else {
      dL -= F[i];
      pB += F[i];
    }
    if (L[n - i - 1] == 'A') {
      dR += F[n - i - 1];
    } else {
      dR -= F[n - i - 1];
    }
    res = max(res, max(dL, dR));
  }
  cout << (pB + res);
  return 0;
}
