#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long int n, i, ans;
  ans = -1;
  scanf("%lld", &n);
  int arr[n];
  char str[n + 1];
  long long int total = 0;
  for (i = 0; i < n; i++) scanf("%d", arr + i);
  scanf("%s", str);
  long long int prefix[n], suffix[n], prefixb[n], suffixb[n];
  prefix[0] = arr[0];
  for (i = 1; i < n; i++) {
    prefix[i] = prefix[i - 1] + arr[i];
  }
  suffix[n - 1] = arr[n - 1];
  for (i = n - 2; i >= 0; i--) {
    suffix[i] = suffix[i + 1] + arr[i];
  }
  prefixb[0] = (str[0] == 'B') ? arr[0] : 0;
  for (i = 1; i < n; i++) {
    if (str[i] == 'B')
      prefixb[i] = prefixb[i - 1] + arr[i];
    else
      prefixb[i] = prefixb[i - 1];
  }
  suffixb[n - 1] = str[n - 1] == 'B' ? arr[n - 1] : 0;
  for (i = n - 2; i >= 0; i--) {
    if (str[i] == 'B')
      suffixb[i] = suffixb[i + 1] + arr[i];
    else
      suffixb[i] = suffixb[i + 1];
  }
  total = prefixb[n - 1];
  ans = prefixb[n - 1];
  for (i = 0; i < n; i++) {
    ans = max(ans, total - 2 * prefixb[i] + prefix[i]);
  }
  for (i = n - 1; i >= 0; i--) {
    ans = max(ans, total - 2 * suffixb[i] + suffix[i]);
  }
  printf("%lld\n", ans);
  return 0;
}
