#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n + 2];
  for (int i = 1; i <= n; i++) cin >> arr[i];
  string s;
  cin >> s;
  pair<long long, long long> dp1[n + 2], dp2[n + 2];
  dp1[0] = make_pair(0, 0);
  for (int i = 1; i <= n; i++) {
    dp1[i] = dp1[i - 1];
    if (s[i - 1] == 'A')
      dp1[i].first += arr[i];
    else
      dp1[i].second += arr[i];
  }
  dp2[n + 1] = make_pair(0, 0);
  for (int i = n; i > 0; i--) {
    dp2[i] = dp2[i + 1];
    if (s[i - 1] == 'A')
      dp2[i].first += arr[i];
    else
      dp2[i].second += arr[i];
  }
  long long res = 0;
  for (int i = 1; i <= n + 1; i++)
    res = max(res, dp1[i - 1].first + dp2[i].second);
  for (int i = n; i >= 0; i--) res = max(res, dp2[i + 1].first + dp1[i].second);
  cout << res;
}
