#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 2;
long long front[N], Back[N], Suff[N], Pref[N], a[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  Pref[0] = (s[0] == 'A' ? a[0] : 0);
  front[0] = (s[0] == 'B' ? a[0] : 0);
  for (int i = 1; i < n; i++)
    Pref[i] = Pref[i - 1] + (s[i] == 'A' ? a[i] : 0),
    front[i] = front[i - 1] + (s[i] == 'B' ? a[i] : 0);
  Suff[n - 1] = (s[n - 1] == 'A' ? a[n - 1] : 0);
  Back[n - 1] = (s[n - 1] == 'B' ? a[n - 1] : 0);
  for (int i = n - 2; i >= 0; i--)
    Suff[i] = Suff[i + 1] + (s[i] == 'A' ? a[i] : 0),
    Back[i] = Back[i + 1] + (s[i] == 'B' ? a[i] : 0);
  long long m = 0;
  for (int i = 0; i < n - 1; i++)
    m = max(m, max(front[i], front[i] + Suff[i + 1]));
  for (int i = n - 1; i > 0; i--) m = max(m, Back[i] + Pref[i - 1]);
  cout << max(m, max(Suff[0], max(Pref[n - 1], front[n - 1]))) << endl;
}
