#include <bits/stdc++.h>
using namespace std;
int64_t a[512345], as[512345], bs[512345];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  string s;
  cin >> s;
  for (int i = 1; i <= n; ++i) {
    if (s[i - 1] == 'B')
      bs[i] = bs[i - 1] + a[i], as[i] = as[i - 1];
    else
      bs[i] = bs[i - 1], as[i] = as[i - 1] + a[i];
  }
  bs[n + 1] = bs[n];
  as[n + 1] = as[n];
  int64_t r = 0;
  for (int i = 0; i <= n; ++i) {
    r = max(r, as[i] + bs[n + 1] - bs[i]);
  }
  for (int i = n + 1; i > 0; --i) {
    r = max(r, bs[i - 1] + as[n + 1] - as[i - 1]);
  }
  cout << r;
}
