#include <bits/stdc++.h>
using namespace std;
long long N;
deque<long long> DQ;
vector<long long> A;
vector<long long> B;
vector<char> s;
vector<long long> path;
int main() {
  cin >> N;
  DQ.resize(N);
  A.resize(N);
  s.resize(N);
  B.resize(A.size());
  for (int i = 0; i < N; i++) cin >> DQ[i];
  for (int i = 0; i < N; i++) cin >> s[i];
  A[0] = B[0] = 0;
  if (s[0] == 'A')
    A[0] += DQ.front();
  else
    B[0] = DQ.front();
  for (int i = 1; i < N; i++) {
    A[i] = A[i - 1];
    B[i] = B[i - 1];
    if (s[i] == 'B') B[i] += DQ[i];
    if (s[i] == 'A') A[i] += DQ[i];
  }
  long long ans = B[N - 1];
  long long a = ans;
  for (int i = 0; i < N; i++) {
    long long sum = A[i] - B[i];
    long long an = a + sum;
    ans = max(an, ans);
  }
  for (int i = N - 1; i >= 0; i--) {
    long long sum = (A[N - 1] - A[i]) - (B[N - 1] - B[i]);
    long long an = a + sum;
    ans = max(an, ans);
  }
  cout << ans << "\n";
  return 0;
}
