#include <bits/stdc++.h>
using namespace std;
long long a[500010];
char b[500010];
int main() {
  long long n, ans1 = 0, ans2 = 0, maxn = 0;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  getchar();
  scanf("%s", b);
  for (int i = 0; i < n; i++) {
    if (b[i] == 'A') {
      ans1 += a[i];
    } else
      ans2 += a[i];
  }
  long long res1 = ans1, res2 = ans2;
  for (int i = 0; i < n; i++) {
    if (b[i] == 'A') {
      ans2 += a[i];
      ans1 -= a[i];
    } else {
      ans1 += a[i];
      ans2 -= a[i];
    }
    maxn = max(max(ans1, ans2), maxn);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (b[i] == 'A') {
      res2 += a[i];
      res1 -= a[i];
    } else {
      res1 += a[i];
      res2 -= a[i];
    }
    maxn = max(max(res1, res2), maxn);
  }
  printf("%lld\n", maxn);
  return 0;
}
