#include <bits/stdc++.h>
using namespace std;
const int N = 500023;
bool vis[N];
vector<int> adj[N];
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> p;
  for (long long int i = 0; i < n; i++) {
    long long int c;
    cin >> c;
    p.push_back(c);
  }
  string s;
  cin >> s;
  long long int temp = 0;
  long long int initial = 0;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == 'B') initial += p[i];
  }
  long long int max = initial;
  long long int t = initial;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == 'A') {
      temp += p[i];
    } else {
      initial -= p[i];
    }
    if ((initial + temp) > max) max = initial + temp;
  }
  initial = t;
  temp = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A') {
      temp += p[i];
    } else {
      initial -= p[i];
    }
    if ((initial + temp) > max) max = initial + temp;
  }
  cout << max;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  int t = 0;
  while (t++ < T) {
    solve();
  }
}
