#include <bits/stdc++.h>
using namespace std;
int a[500005];
long long a1[500005], a2[500005], b1[500005], b2[500005];
int main() {
  long long n;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  string s;
  cin >> s;
  for (int i = 0; i <= n - 1; i++) {
    if (s[i] == 'A') {
      a1[i + 1] = a1[i] + a[i];
      b1[i + 1] = b1[i];
    } else {
      a1[i + 1] = a1[i];
      b1[i + 1] = b1[i] + a[i];
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A') {
      a2[i + 1] = a2[i + 2] + a[i];
      b2[i + 1] = b2[i + 2];
    } else {
      a2[i + 1] = a2[i + 2];
      b2[i + 1] = b2[i + 2] + a[i];
    }
  }
  long long maxx = 0;
  for (int i = 1; i <= n; i++) {
    maxx = max(max(max(max(maxx, a1[i - 1] + a2[i]), a1[i - 1] + b2[i]),
                   b1[i - 1] + a2[i]),
               b1[i - 1] + b2[i]);
  }
  printf("%lld\n", maxx);
  return 0;
}
