#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
int n;
void func(string str, vector<long long> &ls, vector<long long> &rs,
          vector<long long> v) {
  if (str[0] == 'B') ls[0] = v[0];
  for (int i = 1; i < n; ++i) {
    ls[i] = ls[i - 1];
    if (str[i] == 'B') ls[i] += v[i];
  }
  if (str[n - 1] == 'B') rs[n - 1] = v[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    rs[i] = rs[i + 1];
    if (str[i] == 'B') rs[i] += v[i];
  }
}
int main() {
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  string str;
  cin >> str;
  vector<long long> ls(n, 0), rs(n, 0), lr(n, 0), rr(n, 0);
  func(str, ls, rs, v);
  for (int i = 0; i < n; ++i) {
    if (str[i] == 'B')
      str[i] = 'A';
    else
      str[i] = 'B';
  }
  func(str, lr, rr, v);
  long long ans = 0LL;
  for (int i = 0; i < n - 1; ++i) {
    ans = max(ans, ls[i] + rs[i + 1]);
    ans = max(ans, ls[i] + rr[i + 1]);
    ans = max(ans, lr[i] + rs[i + 1]);
  }
  ans = max(ans, rr[0]);
  ans = max(ans, ls[0]);
  cout << ans << endl;
  return 0;
}
