#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  int n;
  cin >> n;
  vector<ll> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i];
  string s;
  cin >> s;
  vector<ll> ca(n + 1, 0), cb(n + 1, 0);
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'A') {
      ca[i + 1] = ca[i] + p[i];
      cb[i + 1] = cb[i];
    } else {
      ca[i + 1] = ca[i];
      cb[i + 1] = cb[i] + p[i];
    }
  }
  ll res = 0;
  for (int i = 0; i <= n; ++i) {
    ll left = ca[i] + cb.back() - cb[i];
    ll right = cb[i] + ca.back() - ca[i];
    res = max(res, max(left, right));
  }
  cout << res << endl;
  return 0;
}
