#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> p(n);
  for (auto& it : p) scanf("%d", &it);
  char buf[500000 + 1];
  scanf("%500001s", buf);
  std::string s(buf);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += int(s[i] == 'B') * p[i];
  }
  std::vector<long long> prefix{sum};
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'A') {
      prefix.push_back(prefix.back() + p[i]);
    } else {
      prefix.push_back(prefix.back() - p[i]);
    }
  }
  std::vector<long long> suffix{sum};
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'A') {
      suffix.push_back(suffix.back() + p[i]);
    } else {
      suffix.push_back(suffix.back() - p[i]);
    }
  }
  long long answ = std::max(*std::max_element(prefix.begin(), prefix.end()),
                            *std::max_element(suffix.begin(), suffix.end()));
  printf("%lld\n", answ);
  return 0;
}
