#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> v(n + 1);
  for (long long i = 0; i < n; i++) cin >> v[i];
  string s;
  cin >> s;
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'B') res += v[i];
  }
  long long sum = 0, curr = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'A')
      curr += v[i];
    else
      curr -= v[i];
    sum = max(sum, curr);
  }
  curr = 0;
  for (long long i = n - 1; i >= 0; i--) {
    if (s[i] == 'A')
      curr += v[i];
    else
      curr -= v[i];
    sum = max(sum, curr);
  }
  cout << sum + res;
  return 0;
}
