#include <bits/stdc++.h>
using namespace std;
template <typename Head>
inline void dout(Head in) {
  cerr << in << '\n';
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  string s;
  cin >> s;
  long long bob = 0;
  for (int i = 0; i < n; i++) {
    bob += a[i] * (s[i] == 'B');
  }
  long long pre = bob, suf = bob;
  bob = max(bob, sum - bob);
  for (int i = 0; i < n - 1; i++) {
    if (s[n - i - 1] == 'A') {
      suf += a[n - i - 1];
    } else {
      suf -= a[n - i - 1];
    }
    if (s[i] == 'A') {
      pre += a[i];
    } else {
      pre -= a[i];
    }
    bob = max(bob, max(pre, suf));
  }
  cout << bob;
  return 0;
}
