#include <bits/stdc++.h>
using namespace std;
int getInt() {
  int x;
  scanf("%d", &x);
  return x;
}
long long getLongLong() {
  long long x;
  scanf("%I64d", &x);
  return x;
}
double getDouble() {
  double x;
  scanf("%lf", &x);
  return x;
}
char getChar() {
  char x;
  scanf("%c", &x);
  return x;
}
template <typename t>
t abs(t a) {
  if (a >= 0) return a;
  return -a;
}
struct dual {
  int a, b;
  bool const operator<(const dual &x) const {
    if (a == x.a) return b > x.b;
    return a < x.a;
  }
};
struct triple {
  int a, b, c;
  bool const operator<(const triple &x) const {
    if (c == x.c) {
      if (a == x.a) return b > x.b;
      return a < x.a;
    }
    return c < x.c;
  }
};
void FastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
int a[512345];
char s[512345];
long long ssb[512345] = {0}, psb[512345] = {0};
long long ssa[512345] = {0}, psa[512345] = {0};
int main() {
  int n = getInt();
  for (int i = 0; i < n; i++) a[i] = getInt();
  scanf("%s", s);
  if (s[0] == 'B')
    psb[0] = a[0];
  else
    psa[0] = a[0];
  for (int i = 1; i < n; i++) {
    psa[i] = psa[i - 1];
    psb[i] = psb[i - 1];
    if (s[i] == 'A')
      psa[i] += a[i];
    else
      psb[i] += a[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    ssa[i] = ssa[i + 1];
    ssb[i] = ssb[i + 1];
    if (s[i] == 'A')
      ssa[i] += a[i];
    else
      ssb[i] += a[i];
  }
  long long ans = max(ssa[0], ssb[0]);
  for (int i = 0; i < n; i++) {
    ans = max(ans, max(psa[i] + ssb[i + 1], psb[i] + ssa[i + 1]));
  }
  cout << ans << endl;
  return 0;
}
