#include <bits/stdc++.h>
using namespace std;
long long arr[500005];
char st[500005];
int main() {
  long long n;
  scanf("%I64d", &n);
  for (long long i = 0; i < n; i++) scanf("%I64d", arr + i);
  scanf("%s", st);
  long long ans = 0;
  long long ori = 0;
  for (long long i = 0; i < n; i++) {
    if (st[i] == 'B') ori += arr[i];
  }
  long long run = ori;
  ans = max(ans, ori);
  for (long long i = 0; i < n; i++) {
    if (st[i] == 'A')
      run += arr[i];
    else
      run -= arr[i];
    ans = max(run, ans);
  }
  run = ori;
  for (long long i = n - 1; i >= 0; i--) {
    if (st[i] == 'A')
      run += arr[i];
    else
      run -= arr[i];
    ans = max(run, ans);
  }
  printf("%I64d\n", ans);
}
