#include <bits/stdc++.h>
using namespace std;
long long a[5 * (int)1e5 + 5];
long long pre[5 * (int)1e5 + 5], suf[5 * (int)1e5 + 5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A')
      pre[i] += a[i];
    else
      pre[i] -= a[i];
    if (i != 0) pre[i] += pre[i - 1];
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A')
      suf[i] += a[i];
    else
      suf[i] -= a[i];
    if (i != 0) suf[i] += suf[i + 1];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == 'B') ans += a[i];
  long long mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, max(suf[i], pre[i]));
  }
  cout << ans + mx;
  return 0;
}
