#include <bits/stdc++.h>
using namespace std;
const int MX = 100000 * 5 + 100;
int n;
long long ar[MX], a[MX], b[MX], AAA, B, ret;
string s;
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ar[i];
  cin >> s;
  if (s[0] == 'A') {
    a[0] = ar[0];
    AAA += ar[0];
  } else {
    b[0] = ar[0];
    B += ar[0];
  }
  for (int i = 1; i < n; i++) {
    if (s[i] == 'A') {
      a[i] = a[i - 1] + ar[i];
      b[i] = b[i - 1];
      AAA += ar[i];
    } else {
      B += ar[i];
      b[i] = b[i - 1] + ar[i];
      a[i] = a[i - 1];
    }
  }
  ret = max(B, AAA);
  for (int i = 0; i < n; i++) {
    ret = max(ret, (long long)B - b[i] + a[i]);
  }
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  B = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A') {
      a[i] = a[i + 1] + ar[i];
      b[i] = b[i + 1];
    } else {
      B += ar[i];
      b[i] = b[i + 1] + ar[i];
      a[i] = a[i + 1];
    }
  }
  ret = max(ret, B);
  for (int i = n - 1; i >= 0; i--) {
    ret = max(ret, B - b[i] + a[i]);
  }
  cout << ret << endl;
  return 0;
}
