#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p[500000 + 20] = {};
  long long ans = 0, b = 0;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i];
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B') b += p[i];
  }
  ans = b;
  long long q = b;
  for (int i = 0, j = (n - 1); i < n && j >= 0; i++, j--) {
    if (s[i] == 'A')
      b += p[i];
    else
      b -= p[i];
    ans = max(ans, b);
    if (s[j] == 'A')
      q += p[j];
    else
      q -= p[j];
    ans = max(ans, q);
  }
  cout << ans << endl;
  return 0;
}
