#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, initial = 0, ans = 0, fwd, bwd;
  cin >> n;
  long long a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  i = 0;
  while (s[i]) {
    if (s[i] == 'B') initial += a[i];
    i++;
  }
  i = 0;
  ans = initial;
  fwd = initial;
  while (s[i]) {
    if (s[i] == 'A')
      fwd += a[i];
    else
      fwd -= a[i];
    ans = max(ans, fwd);
    i++;
  }
  i = s.length() - 1;
  bwd = initial;
  while (s[i]) {
    if (s[i] == 'A')
      bwd += a[i];
    else
      bwd -= a[i];
    ans = max(ans, bwd);
    i--;
  }
  cout << ans << "\n";
  return 0;
}
