#include <bits/stdc++.h>
using namespace std;
long long n, sa, sb, ra, rb, ans, a[500005];
string s;
inline long long read() {
  long long f = 1, q = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (isdigit(ch)) q = (q << 3) + (q << 1) + (ch ^ 48), ch = getchar();
  return f ? q : -q;
}
inline void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + 48);
}
signed main() {
  n = read();
  for (register long long i = 1; i <= n; ++i) a[i] = read();
  cin >> s;
  for (register long long i = 1; i <= n; ++i)
    s[i - 1] == 'B' ? sb += a[i] : sa += a[i];
  ans = max(sa, sb);
  for (register long long i = 1; i <= n; ++i) {
    (!(s[i - 1] ^ 'B')) ? rb += a[i] : ra += a[i];
    ans = max(ans, max(sb + (ra - rb), sa - (ra - rb)));
  }
  print(ans);
  return 0;
}
