#include <bits/stdc++.h>
using namespace std;
const int maxn = 5 * 1e5 + 7;
long long p[maxn];
long long pre[maxn], suf[maxn];
int n;
string s;
int main() {
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    sum += p[i];
  }
  cin >> s;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == 'A')
      pre[i] = pre[i - 1] - p[i];
    else
      pre[i] = pre[i - 1] + p[i];
  }
  for (int i = n; i >= 1; i--) {
    if (s[i - 1] == 'A')
      suf[i] = suf[i + 1] - p[i];
    else
      suf[i] = suf[i + 1] + p[i];
  }
  long long D = -(1LL << 60);
  for (int i = 0; i <= n; i++) {
    D = max(D, max(-pre[i] + suf[i + 1], pre[i] - suf[i + 1]));
  }
  cout << (sum - D) / 2 + D;
  return 0;
}
