#include <bits/stdc++.h>
using namespace std;
int a[500010];
char s[500010], temp[500010];
int n;
long long Max = -1000, sum = 0;
void init() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
}
void work() {
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B') sum += a[i];
  }
  Max = sum;
  long long temp = sum;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A') {
      sum += a[i];
      if (sum > Max) Max = sum;
    } else {
      sum -= a[i];
    }
  }
  sum = temp;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') {
      sum += a[i];
      if (sum > Max) Max = sum;
    } else {
      sum -= a[i];
    }
  }
}
int main() {
  init();
  work();
  cout << Max << endl;
}
