#include <bits/stdc++.h>
using namespace std;
int main() {
std:
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  long long A[N];
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  string S;
  cin >> S;
  long long B[N + 1], val = 0;
  B[0] = 0;
  for (long long j = 0; j < N; j++) {
    if (S[j] == 'B') val = val + A[j];
    if (S[j] == 'B')
      B[j + 1] = B[j] - A[j];
    else
      B[j + 1] = B[j] + A[j];
  }
  long long large = val;
  for (long long j = 1; j <= N; j++) {
    long long X = B[j], Y = B[N] - B[j - 1];
    if (Y > X) X = Y;
    if (val + X > large) large = val + X;
  }
  cout << large << endl;
}
