#include <bits/stdc++.h>
using namespace std;
long long v[500005], pref[500005][2], suff[500005][2];
char s[500005];
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) scanf("%lld", &v[i]);
  scanf("%s", s + 1);
  for (long long i = 1; i <= n; i++) {
    pref[i][0] = pref[i - 1][0] + (s[i] == 'A' ? v[i] : 0);
    pref[i][1] = pref[i - 1][1] + (s[i] == 'B' ? v[i] : 0);
  }
  for (long long i = n; i >= 1; i--) {
    suff[i][0] = suff[i + 1][0] + (s[i] == 'A' ? v[i] : 0);
    suff[i][1] = suff[i + 1][1] + (s[i] == 'B' ? v[i] : 0);
  }
  long long res = pref[n][1];
  for (long long i = 1; i <= n; i++) {
    long long sum = pref[i][0] + suff[i + 1][1];
    res = max(res, sum);
  }
  for (long long i = n; i >= 1; i--) {
    long long sum = suff[i][0] + pref[i - 1][1];
    res = max(res, sum);
  }
  printf("%lld\n", res);
  return 0;
}
