#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> v(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
  }
  string str;
  cin >> str;
  str = " " + str;
  vector<long long> prefixA(n + 2, 0), prefixB(n + 2, 0);
  vector<long long> suffixA(n + 2, 0), suffixB(n + 2, 0);
  for (int i = 1; i <= n; ++i) {
    if (str[i] == 'A') {
      prefixA[i] = prefixA[i - 1] + v[i];
      prefixB[i] = prefixB[i - 1];
    } else {
      prefixB[i] = prefixB[i - 1] + v[i];
      prefixA[i] = prefixA[i - 1];
    }
  }
  for (int i = n; i >= 1; --i) {
    if (str[i] == 'A') {
      suffixA[i] = suffixA[i + 1] + v[i];
      suffixB[i] = suffixB[i + 1];
    } else {
      suffixB[i] = suffixB[i + 1] + v[i];
      suffixA[i] = suffixA[i + 1];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, prefixB[i] + suffixA[i + 1]);
  }
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, prefixA[i] + suffixB[i + 1]);
  }
  cout << ans;
  return 0;
}
