#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  string s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> s;
  vector<pair<long long, long long> > m(n), v(n);
  if (s[0] == 'A')
    m[0] = make_pair(a[0], 0);
  else
    m[0] = make_pair(0, a[0]);
  if (s[n - 1] == 'A')
    v[n - 1] = make_pair(a[n - 1], 0);
  else
    v[n - 1] = make_pair(0, a[n - 1]);
  for (int i = 1; i < n; i++) {
    if (s[i] == 'A')
      m[i] = make_pair(m[i - 1].first + a[i], m[i - 1].second);
    else
      m[i] = make_pair(m[i - 1].first, m[i - 1].second + a[i]);
  }
  for (int i = n - 2; i >= 0; i--) {
    if (s[i] == 'A')
      v[i] = make_pair(v[i + 1].first + a[i], v[i + 1].second);
    else
      v[i] = make_pair(v[i + 1].first, v[i + 1].second + a[i]);
  }
  long long mp = n, mr = 0;
  for (int i = 0; i < n; i++) {
    if (m[i].first - m[i].second > mr) {
      mr = m[i].first - m[i].second;
      mp = i;
    }
  }
  long long vp = n, vr = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (v[i].first - v[i].second > vr) {
      vr = v[i].first - v[i].second;
      vp = i;
    }
  }
  long long ans = 0;
  if (vp == n && mp == n) {
    cout << v[0].second;
    return 0;
  }
  if (vr >= mr) {
    if (vp > 0) ans += m[vp - 1].second;
    ans += v[vp].first;
  } else {
    if (mp < n - 1) ans += v[mp + 1].second;
    ans += m[mp].first;
  }
  cout << ans;
  return 0;
}
