#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e8;
class fenwick {
 public:
  int n;
  vector<long long> t;
  int nextF(int x) { return (x & (x + 1)); }
  int nextH(int x) { return (x | (x + 1)); }
  long long sum(int l) {
    long long res = 0;
    for (int i = l; i >= 0; i = nextF(i) - 1) res += t[i];
    return res;
  }
  long long sum(int l, int r) { return sum(r) - sum(l - 1); }
  void inc(int x, long long a) {
    for (int i = x; i < n; i = nextH(i)) t[i] += a;
  }
  fenwick(int n) : n(n), t() { t.resize(n, 0); }
};
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<long long> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  string s;
  cin >> s;
  fenwick f1 = fenwick(n);
  fenwick f2 = fenwick(n);
  for (int i = 0; i < n; i++)
    if (s[i] == 'A')
      f1.inc(i, p[i]);
    else
      f2.inc(i, p[i]);
  long long ans = max(f1.sum(n - 1), f2.sum(n - 1));
  for (int i = 0; i < n; i++) {
    long long x = f1.sum(0, i) + f2.sum(i + 1, n - 1);
    ans = max(ans, x);
    x = f2.sum(0, i) + f1.sum(i + 1, n - 1);
    ans = max(ans, x);
  }
  cout << ans << '\n';
  return 0;
}
