#include <bits/stdc++.h>
using namespace std;
long long n;
long long lefa[500005], lefb[500005], riga[500005], rigb[500005];
char data[500005];
long long dat[500005];
void pre() {
  memset(lefa, 0, sizeof lefa);
  memset(lefb, 0, sizeof lefb);
  memset(riga, 0, sizeof riga);
  memset(rigb, 0, sizeof rigb);
  for (int i = 1; i <= n; i++) {
    if (data[i] == 'A') {
      lefa[i] = lefa[i - 1] + dat[i];
      lefb[i] = lefb[i - 1];
    } else {
      lefb[i] = lefb[i - 1] + dat[i];
      lefa[i] = lefa[i - 1];
    }
  }
  for (int i = n; i >= 1; i--) {
    if (data[i] == 'A') {
      riga[i] = riga[i + 1] + dat[i];
      rigb[i] = rigb[i + 1];
    } else {
      rigb[i] = rigb[i + 1] + dat[i];
      riga[i] = riga[i + 1];
    }
  }
}
int main() {
  while (scanf("%I64d", &n) == 1) {
    for (int i = 1; i <= n; i++) {
      scanf("%I64d", &dat[i]);
    }
    cin >> data + 1;
    long long ans = 0;
    pre();
    for (int i = 1; i <= n; i++) {
      ans = max(ans, lefa[i] + rigb[i + 1]);
    }
    for (int i = n; i >= 1; i--) {
      ans = max(ans, riga[i] + lefb[i - 1]);
    }
    printf("%I64d\n", max(ans, lefb[n]));
  }
  return 0;
}
