#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int w[N];
long long sa[N], sb[N];
char a[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  scanf("%s", a + 1);
  for (int i = 1; i <= n; i++)
    if (a[i] == 'A')
      sa[i] = sa[i - 1] + w[i], sb[i] = sb[i - 1] + 0;
    else
      sa[i] = sa[i - 1] + 0, sb[i] = sb[i - 1] + w[i];
  long long maxv = sb[n];
  for (int i = 1; i <= n; i++) maxv = max(maxv, sa[i] + sb[n] - sb[i]);
  memset(sa, 0, sizeof sa);
  memset(sb, 0, sizeof sb);
  for (int i = n; i >= 1; i--)
    if (a[i] == 'A')
      sa[i] = sa[i + 1] + w[i], sb[i] = sb[i + 1] + 0;
    else
      sa[i] = sa[i + 1] + 0, sb[i] = sb[i + 1] + w[i];
  for (int i = n; i >= 1; i--) maxv = max(maxv, sa[i] + sb[1] - sb[i]);
  printf("%lld\n", maxv);
  return 0;
}
