#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int i;
  for (i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  i = 0;
  char ch[n + 1];
  cin >> ch;
  long long ans = 0;
  while (i < n) {
    if (ch[i] == 'B') ans += arr[i];
    ++i;
  }
  long long origB = ans;
  long long sumB = ans;
  for (i = 0; i < n; ++i) {
    if (ch[i] == 'A')
      sumB += arr[i];
    else
      sumB -= arr[i];
    if (sumB > ans) {
      ans = sumB;
    }
  }
  sumB = origB;
  for (i = (n - 1); i >= 0; --i) {
    if (ch[i] == 'A')
      sumB += arr[i];
    else
      sumB -= arr[i];
    if (sumB > ans) {
      ans = sumB;
    }
  }
  cout << ans << endl;
  return 0;
}
