#include <bits/stdc++.h>
using namespace std;
long long n, a[1000000], ans = 0;
char s[1000000];
void solve() {
  long long an = 0, cur = 0, pos = -1;
  for (int i = 0; i < n; i++)
    if (s[i] == 'A') {
      cur += a[i];
      if (cur > an) an = cur, pos = i;
    } else
      cur -= a[i];
  an = 0;
  for (int i = 0; i <= pos; i++)
    if (s[i] == 'A') an += a[i];
  for (int i = pos + 1; i < n; i++)
    if (s[i] == 'B') an += a[i];
  ans = max(ans, an);
}
int main() {
  scanf("%I64d", &n);
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  for (int i = 0; i < n; i++) cin >> s[i];
  solve();
  reverse(s, s + n);
  reverse(a, a + n);
  solve();
  cout << ans;
  return 0;
}
