#include <bits/stdc++.h>
using namespace std;
int in[500005], n;
long long s1[500005], s2[500005];
char a[500005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", in + i);
  in[0] = in[n + 1] = 0;
  scanf(" %s", a + 1);
  for (int i = 1; i <= n; ++i) s1[i] = s1[i - 1] + in[i];
  for (int i = n; i >= 1; --i) s2[i] = s2[i + 1] + (a[i] == 'B' ? in[i] : 0);
  long long ans = 0, sum = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == 'B') sum += in[i];
    ans = max(ans, max(sum, s1[i] - sum) + s2[i + 1]);
  }
  sum = 0;
  for (int i = 1; i <= n; ++i) s1[i] = s1[i - 1] + (a[i] == 'B' ? in[i] : 0);
  for (int i = n; i >= 1; --i) s2[i] = s2[i + 1] + in[i];
  for (int i = n; i >= 1; --i) {
    if (a[i] == 'B') sum += in[i];
    ans = max(ans, max(sum, s2[i] - sum) + s1[i - 1]);
  }
  printf("%I64d\n", ans);
  return 0;
}
