#include <bits/stdc++.h>
using namespace std;
long long n, a[500005], b[500005], p[500005], a1[500005], b1[500005];
char s[500005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'A') {
      a[i] = a[i - 1] + p[i];
      b[i] = b[i - 1];
    } else {
      b[i] = b[i - 1] + p[i];
      a[i] = a[i - 1];
    }
  }
  a1[n + 1] = 0;
  b1[n + 1] = 0;
  for (int i = n; i >= 1; i--) {
    if (s[i] == 'A') {
      a1[i] = a1[i + 1] + p[i];
      b1[i] = b1[i + 1];
    } else {
      b1[i] = b1[i + 1] + p[i];
      a1[i] = a1[i + 1];
    }
  }
  long long ans = b[n];
  for (int i = 1; i <= n; i++) {
    ans = max(ans, a[i] + b1[i + 1]);
  }
  for (int i = n; i >= 1; i--) {
    ans = max(ans, a1[i] + b[i]);
  }
  cout << ans << endl;
}
