#include <bits/stdc++.h>
using namespace std;
char t;
long long n, p[500005], sum1[500005], sum2[500005], ans;
long long getinvsum(int ind) {
  return max(sum2[n] - sum2[ind] + sum1[ind],
             sum1[n] - sum1[ind - 1] + sum2[ind - 1]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n; i++) {
    cin >> t;
    sum1[i] += p[i] * (t == 'A') + sum1[i - 1];
    sum2[i] += p[i] * (t == 'B') + sum2[i - 1];
  }
  ans = sum2[n];
  for (int i = 1; i <= n; i++) ans = max(ans, getinvsum(i));
  cout << ans;
  return 0;
}
