#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, cr = 0, ans = 0, cr1 = 0;
  string s;
  cin >> n;
  vector<int> ar(n);
  for (int i = 0; i < n; i++) cin >> ar[i];
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B') cr += ar[i];
  }
  ans = cr1 = cr;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A')
      cr += ar[i];
    else
      cr -= ar[i];
    ans = max(ans, cr);
  }
  cr = cr1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A')
      cr += ar[i];
    else
      cr -= ar[i];
    ans = max(ans, cr);
  }
  cout << ans << endl;
}
