#include <bits/stdc++.h>
using namespace std;
long long n, sum, sumb, mx;
const long long N = 1000100;
long long a[N];
char c;
string s;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c;
    if (c == 'B') sumb += a[i];
    s += c;
  }
  if (sumb > mx) mx = sumb;
  sum = sumb;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B')
      sum -= a[i];
    else
      sum += a[i];
    if (sum > mx) mx = sum;
  }
  sum = sumb;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'B')
      sum -= a[i];
    else
      sum += a[i];
    if (sum > mx) mx = sum;
  }
  cout << mx << endl;
}
