#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N, M, e, i, j, k, a, b, c, d, f, x, y, z, m, n, p, s, t;
  vector<long long int> P, Q, R, A, B;
  char U[500002];
  vector<long long int>::iterator it;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> x;
    P.push_back(x);
  }
  cin >> U;
  s = 0;
  for (i = 0; i < N; i++) {
    if (U[i] == 'B') {
      s = s + P[i];
    }
  }
  t = s;
  x = s;
  i = 0;
  j = N - 1;
  while (1) {
    if (U[i] == 'B') {
      s = s - P[i];
    } else if (U[i] == 'A') {
      s = s + P[i];
    }
    if (s > x) {
      Q.push_back(s);
    }
    if (U[j] == 'B') {
      t = t - P[j];
    } else if (U[j] == 'A') {
      t = t + P[j];
    }
    if (t > x) {
      R.push_back(t);
    }
    i++;
    j--;
    if (j == -1 || i == N) {
      break;
    }
  }
  if (Q.size() > 0) {
    a = *max_element(Q.begin(), Q.end());
  } else {
    a = 0;
  }
  if (R.size() > 0) {
    b = *max_element(R.begin(), R.end());
  } else {
    b = 0;
  }
  A.push_back(a);
  A.push_back(b);
  A.push_back(x);
  m = *max_element(A.begin(), A.end());
  cout << m << endl;
  return 0;
}
