#include <bits/stdc++.h>
using namespace std;
char s[500005];
int v[500005];
int main() {
  int n;
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &v[i]);
  scanf("%s", &s);
  long long sum1 = 0, sum2 = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B') ans += v[i];
  }
  sum1 = sum2 = ans;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A')
      sum1 += v[i];
    else
      sum1 -= v[i];
    ans = max(ans, sum1);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A')
      sum2 += v[i];
    else
      sum2 -= v[i];
    ans = max(ans, sum2);
  }
  printf("%lld\n", ans);
}
