#include <bits/stdc++.h>
using namespace std;
int p[500000];
int a[500000];
int64_t apref[500000];
int64_t bpref[500000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    a[i] = c == 'A' ? 1 : 0;
  }
  apref[0] = 0;
  bpref[0] = 0;
  if (a[0]) {
    apref[0] = p[0];
  } else {
    bpref[0] = p[0];
  }
  for (int i = 1; i < n; i++) {
    if (a[i]) {
      apref[i] = apref[i - 1] + p[i];
      bpref[i] = bpref[i - 1];
    } else {
      apref[i] = apref[i - 1];
      bpref[i] = bpref[i - 1] + p[i];
    }
  }
  int64_t answ = apref[n - 1];
  if (answ < bpref[n - 1]) answ = bpref[n - 1];
  for (int i = 0; i < n; i++) {
    int64_t curr = 0;
    curr = apref[i] + bpref[n - 1] - bpref[i];
    if (curr > answ) answ = curr;
    curr = bpref[i] + apref[n - 1] - apref[i];
    if (curr > answ) answ = curr;
  }
  cout << answ << endl;
  return 0;
}
