#include <bits/stdc++.h>
using namespace std;
long long int a[500010];
int main() {
  int n;
  cin >> n;
  for (int i = (0); i < (n); ++i) {
    cin >> a[i];
  }
  string s;
  cin >> s;
  long long int ans = 0;
  for (int i = (0); i < (s.size()); ++i) {
    if (s[i] == 'B') {
      ans += a[i];
    }
  }
  long long int ans1 = ans;
  long long int maxi = ans;
  for (int i = (0); i < (s.size()); ++i) {
    if (s[i] == 'A') {
      ans1 += a[i];
    } else {
      ans1 -= a[i];
    }
    maxi = max(ans1, maxi);
  }
  long long int ans2 = ans;
  for (int i = (s.size() - 1); i >= (0); --i) {
    if (s[i] == 'A') {
      ans2 += a[i];
    } else {
      ans2 -= a[i];
    }
    maxi = max(ans2, maxi);
  }
  cout << maxi << endl;
  return 0;
}
