#include <bits/stdc++.h>
using namespace std;
map<string, int> mapik;
vector<string> vect;
int _tempik = 0;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  string s;
  cin >> s;
  vector<pair<long long, long long>> sum(n + 1);
  vector<pair<long long, long long>> obr(n + 1);
  sum[0] = make_pair(0, 0);
  obr[0] = make_pair(0, 0);
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i];
    obr[i + 1] = obr[i];
    if (s[i] == 'A') {
      sum[i + 1].first += a[i];
    } else {
      sum[i + 1].second += a[i];
    }
    if (s[n - 1 - i] == 'A') {
      obr[i + 1].first += a[n - 1 - i];
    } else {
      obr[i + 1].second += a[n - 1 - i];
    }
  }
  pair<long long, long long> res = sum[n];
  long long ans = res.second;
  for (int i = 1; i <= n; i++) {
    pair<long long, long long> curres = res;
    curres = make_pair(res.first - sum[i].first + sum[i].second,
                       res.second - sum[i].second + sum[i].first);
    ans = max(curres.second, ans);
    curres = res;
    curres = make_pair(res.first - obr[i].first + obr[i].second,
                       res.second - obr[i].second + obr[i].first);
    ans = max(curres.second, ans);
  }
  cout << ans;
  return 0;
}
