#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  long long bob = 0;
  long long answer1 = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == 'B') bob = bob + a[i];
  answer1 = bob;
  long long x = bob;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A')
      bob = bob + a[i];
    else
      bob = bob - a[i];
    answer1 = max(answer1, bob);
  }
  bob = x;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A')
      bob = bob + a[i];
    else
      bob = bob - a[i];
    answer1 = max(answer1, bob);
  }
  cout << answer1 << endl;
}
