#include <bits/stdc++.h>
using namespace std;
int num[500010];
string str;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &num[i]);
  }
  cin >> str;
  long long sum = 0, sum1 = 0, ans;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'B') sum += num[i];
  }
  sum1 = sum;
  ans = sum;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'A') sum1 += num[i];
    if (str[i] == 'B') sum1 -= num[i];
    if (sum1 > ans) ans = sum1;
  }
  sum1 = sum;
  for (int i = n - 1; i > 0; i--) {
    if (str[i] == 'A') sum1 += num[i];
    if (str[i] == 'B') sum1 -= num[i];
    if (sum1 > ans) ans = sum1;
  }
  printf("%I64d\n", ans);
  return 0;
}
