#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long st[n];
  for (int i = 0; i < n; i++) {
    cin >> st[i];
  }
  string s;
  cin >> s;
  long long sap[n], sbp[n], sas[n], sbs[n], sumpa = 0, sumsa = 0, sumpb = 0,
                                            sumsb = 0;
  memset(sap, 0, sizeof(sap));
  memset(sbs, 0, sizeof(sbs));
  memset(sbp, 0, sizeof(sbp));
  memset(sas, 0, sizeof(sas));
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (s[i] == 'A') {
        sap[i] = st[i];
      } else {
        sap[i] = 0;
      }
    } else {
      if (s[i] == 'A') {
        sap[i] = sap[i - 1] + st[i];
      } else {
        sap[i] = sap[i - 1];
      }
    }
    if (i == 0) {
      if (s[i] == 'B') {
        sbp[i] = st[i];
      } else {
        sbp[i] = 0;
      }
    } else {
      if (s[i] == 'B') {
        sbp[i] = sbp[i - 1] + st[i];
      } else {
        sbp[i] = sbp[i - 1];
      }
    }
  }
  sumsa = sap[n - 1];
  sumsb = sbp[n - 1];
  for (int i = n - 1; i >= 0; i--) {
    if (i == (n - 1)) {
      if (s[i] == 'A') {
        sas[i] = st[i];
      } else {
        sas[i] = 0;
      }
    } else {
      if (s[i] == 'A') {
        sas[i] = sas[i + 1] + st[i];
      } else {
        sas[i] = sas[i + 1];
      }
    }
    if (i == (n - 1)) {
      if (s[i] == 'B') {
        sbs[i] = st[i];
      } else {
        sbs[i] = 0;
      }
    } else {
      if (s[i] == 'B') {
        sbs[i] = sbs[i + 1] + st[i];
      } else {
        sbs[i] = sbs[i + 1];
      }
    }
  }
  long long tempa = sumsa, tempb = sumsb, mind = 0, ansa = sumsa, ansb = sumsb;
  for (int i = 0; i < n; i++) {
    tempb -= sbp[i];
    tempb += sap[i];
    if (tempb > ansb) {
      ansb = tempb;
      mind = i;
    }
    tempb = sumsb;
  }
  for (int i = n - 1; i >= 0; i--) {
    tempb -= sbs[i];
    tempb += sas[i];
    if (tempb > ansb) {
      ansb = tempb;
      mind = i;
    }
    tempb = sumsb;
  }
  cout << ansb;
  return 0;
}
