#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i;
  string s;
  cin >> n;
  long long int maxSum = 0, sum = 0, sum2 = 0;
  long long int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  cin >> s;
  for (i = 0; i < n; i++) {
    if (s[i] == 'B') sum += a[i];
  }
  sum2 = sum;
  maxSum = sum;
  for (i = 0; i < n; i++) {
    if (s[i] == 'A')
      sum += a[i];
    else if (s[i] == 'B')
      sum -= a[i];
    maxSum = max(sum, maxSum);
  }
  for (i = n - 1; i >= 0; --i) {
    if (s[i] == 'A')
      sum2 += a[i];
    else if (s[i] == 'B')
      sum2 -= a[i];
    maxSum = max(sum2, maxSum);
  }
  cout << maxSum << '\n';
}
