#include <bits/stdc++.h>
using namespace std;
char t[500001];
long long int s[500001], sa[500001], sb[500001];
int main() {
  long long int n, i, j;
  cin >> n;
  for (i = 0; i < n; i++) cin >> s[i];
  cin >> t[0];
  (t[0] == 'A' ? sa[0] = s[0] : sb[0] = s[0]);
  for (i = 1; i < n; i++) {
    cin >> t[i];
    sa[i] += sa[i - 1] + s[i] * (t[i] == 'A');
    sb[i] += sb[i - 1] + s[i] * (t[i] == 'B');
  }
  long long int mx = 0, m1, m2;
  for (i = 0; i < n; i++) {
    m1 = sa[i] + sb[n - 1] - sb[i];
    m2 = sb[i] + sa[n - 1] - sa[i];
    mx = max(mx, max(m1, m2));
  }
  cout << mx << endl;
  return 0;
}
