#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5 + 3;
int n, p[N];
unsigned long long A, B, nA, nB, ans;
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> p[i];
  cin >> s;
  for (int i = 0; i < n; ++i)
    if (s[i] == 'A')
      A += p[i];
    else
      B += p[i];
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'A') {
      A -= p[i];
      nB += p[i];
    } else {
      B -= p[i];
      nA += p[i];
    }
    ans = max(max(A + nA, B + nB), ans);
  }
  cout << ans;
  return 0;
}
