#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 100;
const long long MOD = 1e9 + 7;
long long preA[N];
long long preB[N];
long long sufA[N];
long long sufB[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  long long p[n + 1];
  for (int i = 1; i <= n; i++) cin >> p[i];
  string second;
  cin >> second;
  for (int i = 0; i < n; i++) {
    if (second[i] == 'A') {
      preA[i + 1] = preA[i] + p[i + 1];
      preB[i + 1] = preB[i];
    } else {
      preA[i + 1] = preA[i];
      preB[i + 1] = preB[i] + p[i + 1];
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (second[i] == 'A') {
      sufA[i + 1] = sufA[i + 2] + p[i + 1];
      sufB[i + 1] = sufB[i + 2];
    } else {
      sufB[i + 1] = sufB[i + 2] + p[i + 1];
      sufA[i + 1] = sufA[i + 2];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (second[i - 1] == 'B') {
      ans += p[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    ans = max(ans, preA[i] + sufB[i + 1]);
  }
  for (int i = n; i >= 1; i--) {
    ans = max(ans, sufA[i] + preB[i - 1]);
  }
  cout << ans << endl;
  return 0;
}
