#include <bits/stdc++.h>
using namespace std;
long long int str[500005];
char temp[500005];
void solve() {
  long long int n;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) scanf("%lld", &str[i]);
  long long int B = 0;
  scanf("%s", &temp);
  string s(temp);
  for (int i = 0; i < n; i++)
    if (s[i] == 'B') B += str[i];
  long long int tempB = B;
  long long int sol = B;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A')
      tempB += str[i];
    else
      tempB -= str[i];
    sol = max(sol, tempB);
  }
  tempB = B;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A')
      tempB += str[i];
    else
      tempB -= str[i];
    sol = max(sol, tempB);
  }
  printf("%lld\n", sol);
}
int main() {
  solve();
  return 0;
}
