#include <bits/stdc++.h>
using namespace std;
long long dp[600000][2], n, va[600000];
char s[600000];
int main() {
  while (scanf("%I64d", &n) != EOF) {
    long long re = -1;
    for (int i = 0; i < n; i++) scanf("%I64d", &va[i]);
    scanf("%s", s);
    if (s[0] == 'A') {
      dp[0][0] = 0;
      dp[0][1] = va[0];
    } else {
      dp[0][0] = va[0];
      dp[0][1] = 0;
    }
    for (int i = 1; i < n; i++) {
      if (s[i] == 'A') {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        dp[i][1] = dp[i - 1][1] + va[i];
      } else {
        dp[i][0] = max(dp[i - 1][0] + va[i], dp[i - 1][1] + va[i]);
        dp[i][1] = dp[i - 1][1];
      }
    }
    re = max(dp[n - 1][0], dp[n - 1][1]);
    if (s[n - 1] == 'A') {
      dp[n - 1][0] = 0;
      dp[n - 1][1] = va[n - 1];
    } else {
      dp[n - 1][0] = va[n - 1];
      dp[n - 1][1] = 0;
    }
    for (int i = n - 2; i >= 0; i--) {
      if (s[i] == 'A') {
        dp[i][0] = max(dp[i + 1][0], dp[i + 1][1]);
        dp[i][1] = dp[i + 1][1] + va[i];
      } else {
        dp[i][0] = max(dp[i + 1][0] + va[i], dp[i + 1][1] + va[i]);
        dp[i][1] = dp[i + 1][1];
      }
    }
    long long re2 = max(dp[0][0], dp[0][1]);
    re = max(re, re2);
    printf("%I64d\n", re);
  }
  return 0;
}
