#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 5;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  for (auto &it : v) cin >> it;
  ;
  string s;
  cin >> s;
  long long int ans = 0, zx = 0, as = 0, req = 0, me = 0;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == 'A') {
      me += v[i];
    } else {
      req += v[i];
    }
    ans = max(ans, req);
  }
  for (long long int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A') {
      as += v[i];
    } else {
      zx += v[i];
    }
    long long int prefb = req - zx;
    long long int prefa = me - as;
    ans = max(ans, prefb + as);
    ans = max(ans, prefa + zx);
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) solve();
  return 0;
}
