#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653689793238460;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 5;
const int pr = 31;
using ld = long double;
int mod = 998244353;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  string p;
  cin >> p;
  long long mx = 0;
  long long prx = 0;
  long long sux = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] == 'A') {
      prx += (long long)a[i];
      mx = max(mx, prx);
    } else {
      prx -= (long long)a[i];
      mx = max(mx, prx);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (p[i] == 'A') {
      sux += a[i];
      mx = max(mx, sux);
    } else {
      sux -= a[i];
      mx = max(mx, sux);
    }
  }
  long long sm = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] == 'B') sm += (long long)a[i];
  }
  cout << sm + mx << endl;
}
