#include <bits/stdc++.h>
using namespace std;
const long long int M = 5e5 + 7;
long long int a[M + 100], b[M + 100];
int main() {
  long long int n, ans = 0;
  scanf("%lld", &n);
  long long int i, p[n + 1];
  for (i = 0; i < n; i++) {
    scanf("%lld", &p[i]);
  }
  string s;
  cin >> s;
  if (s[0] == 'A')
    a[0] = p[0];
  else
    b[0] = p[0];
  i = 0;
  for (i = 1; i < n; i++) {
    if (s[i] == 'A')
      a[i] = p[i];
    else
      b[i] = p[i];
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }
  ans = max(a[n - 1], b[n - 1]);
  for (i = 0; i < n; i++) {
    ans = max(ans, a[i] + b[n - 1] - b[i]);
    ans = max(ans, a[n - 1] + b[n - i - 1] - a[n - i - 1]);
  }
  cout << ans << endl;
  return 0;
}
