#include <bits/stdc++.h>
using namespace std;
long long int binary_expo(long long int base, long long int pw) {
  long long int res = 1;
  while (pw) {
    if (pw % 2) {
      res *= base;
      res %= 1000000007;
      pw -= 1;
    } else {
      base *= base;
      base %= 1000000007;
      pw /= 2;
    }
  }
  return res;
}
long long int mod_inv(long long int k) {
  return binary_expo(k, 1000000007 - 2);
}
long long m_neg(long long a) {
  return (1000000007 + (a % 1000000007)) % 1000000007;
}
int t;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    string s;
    cin >> s;
    long long bo = 0;
    long long bo2 = 0;
    long long buff = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'B') {
        bo += arr[i];
        bo2 += arr[i];
      }
    }
    long long suf = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'A') {
        suf += arr[i];
      } else {
        buff += arr[i];
      }
      if (suf > buff) {
        bo += (suf - buff);
        suf = 0;
        buff = 0;
      }
    }
    suf = 0;
    buff = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == 'A') {
        suf += arr[i];
      } else {
        buff += arr[i];
      }
      if (suf > buff) {
        bo2 += (suf - buff);
        suf = 0;
        buff = 0;
      }
    }
    cout << max(bo, bo2) << "\n";
  }
  return 0;
}
