#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
long long sa[N], sb[N], p[N];
char s[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i) {
    sa[i] = sa[i - 1];
    sb[i] = sb[i - 1];
    if (s[i] == 'A')
      sa[i] += p[i];
    else
      sb[i] += p[i];
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, sa[i - 1] + sb[n] - sb[i - 1]);
    ans = max(ans, sb[i - 1] + sa[n] - sa[i - 1]);
  }
  printf("%I64d\n", ans);
}
