#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500100;
long long n, a[MAXN], sol, sumA, sumB, sum;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> s;
  for (int i = 0; i < n; i++)
    if (s[i] == 'A')
      sumA += a[i];
    else
      sumB += a[i];
  sum = sumA + sumB;
  sol = sumB;
  long long pSum = 0;
  long long pSol = 0;
  for (int i = 0; i < n; i++) {
    pSum += a[i];
    if (s[i] == 'A') pSol += a[i];
    long long tmp = pSol + sumB - pSum + pSol;
    sol = max(sol, tmp);
  }
  long long sSum = 0;
  long long sSol = 0;
  for (int i = n - 1; i >= 0; i--) {
    sSum += a[i];
    if (s[i] == 'A') sSol += a[i];
    long long tmp = sSol + sumB - sSum + sSol;
    sol = max(sol, tmp);
  }
  cout << sol << '\n';
  ;
}
