#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5 + 10;
long long arr[MAX];
string s;
long long a[MAX], b[MAX];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int(i) = (1); (i) < (n + 1); (i)++) cin >> arr[i];
  cin >> s;
  for (int(i) = (1); (i) < (n + 1); (i)++) {
    if (s[i - 1] == 'A')
      a[i] += arr[i];
    else
      b[i] += arr[i];
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }
  long long ans = 0;
  ans = max(ans, a[n]);
  ans = max(ans, b[n]);
  for (int(i) = (1); (i) < (n); (i)++) {
    ans = max(ans, b[i] + (a[n] - a[i]));
    ans = max(ans, a[i] + (b[n] - b[i]));
  }
  cout << (ans) << "\n";
  ;
}
