#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int arr[5 * 100000 + 10] = {0};
  char input[5 * 100000 + 10] = {0};
  long long total = 0;
  long long flip = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  scanf("%s", input);
  for (int i = 0; i < n; i++)
    if (input[i] == 'B') total += arr[i];
  long long ans = total;
  flip = total;
  for (int i = 0; i < n; i++) {
    if (input[i] == 'B') {
      flip -= arr[i];
    } else {
      flip += arr[i];
    }
    if (ans < flip) ans = flip;
  }
  flip = total;
  for (int i = n - 1; i >= 0; i--) {
    if (input[i] == 'B') {
      flip -= arr[i];
    } else {
      flip += arr[i];
    }
    if (ans < flip) ans = flip;
  }
  printf("%lld\n", ans);
  return 0;
}
