#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int *list = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> list[i];
  }
  char *str = new char[n + 1];
  cin >> str;
  long long strength0 = 0;
  for (int i = 0; i < n; i++) {
    str[i] -= 'A';
    if (str[i] == 1) strength0 += list[i];
  }
  long long strength = strength0;
  long long max_strength = strength;
  for (int i = 0; i < n; i++) {
    if (str[i] == 0)
      strength += list[i];
    else
      strength -= list[i];
    if (strength > max_strength) max_strength = strength;
  }
  strength = strength0;
  for (int i = n - 1; i >= 0; i--) {
    if (str[i] == 0)
      strength += list[i];
    else
      strength -= list[i];
    if (strength > max_strength) max_strength = strength;
  }
  cout << max_strength;
  return 0;
}
