#include <bits/stdc++.h>
using namespace std;
long long int ans = 0, sum = 0, mx = 0, x;
char st[500005];
vector<long long int> v;
int main() {
  int i, j, k, a, b, n;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &x);
    v.push_back(x);
  }
  scanf("%s", st);
  for (i = 0; st[i]; i++) {
    if (st[i] == 'B') {
      sum += (v[i]);
    }
  }
  ans = sum;
  mx = sum;
  for (i = 0; st[i]; i++) {
    if (st[i] == 'A')
      sum += v[i];
    else
      sum -= v[i];
    mx = max(sum, mx);
  }
  sum = ans;
  for (i = n - 1; i >= 0; i--) {
    if (st[i] == 'A')
      sum += v[i];
    else
      sum -= v[i];
    mx = max(mx, sum);
  }
  cout << mx << endl;
  return 0;
}
