#include <bits/stdc++.h>
using namespace std;
int l[500000];
long long dp1[500001], dp2[500001];
int main() {
  long long n, k, sum = 0;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &l[i]);
  }
  cin >> s;
  for (int i = 0; i < n; i++)
    if (s[i] == 'B') sum += l[i];
  dp1[0] = dp2[n] = sum;
  for (int i = 1; i <= n; i++) {
    long long tmp = dp1[i - 1];
    if (s[i - 1] == 'A')
      tmp += l[i - 1];
    else
      tmp -= l[i - 1];
    dp1[i] = tmp;
  }
  for (int i = n - 1; i >= 0; i--) {
    long long tmp = dp2[i + 1];
    if (s[i] == 'A')
      tmp += l[i];
    else
      tmp -= l[i];
    dp2[i] = tmp;
  }
  long long m1 = 0, m2 = 0;
  for (int i = 0; i <= n; i++) {
    if (m1 < dp1[i]) m1 = dp1[i];
    if (m2 < dp2[i]) m2 = dp2[i];
  }
  cout << max(m1, m2);
}
