#include <bits/stdc++.h>
using namespace std;
long long a[600001];
long long pre[600001];
int main() {
  long long ans = 0;
  int n;
  cin >> n;
  pre[0] = 0;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  string x;
  cin >> x;
  for (int i = 1; i <= n; ++i) {
    pre[i] = pre[i - 1];
    if (x[i - 1] == 'A') pre[i] += a[i];
  }
  ans = pre[n];
  long long sm = 0;
  for (int i = 1; i <= n; ++i) {
    sm += a[i];
    ans = max(ans, pre[n] + sm - 2 * pre[i]);
  }
  sm = 0;
  for (int i = n; i >= 1; --i) {
    sm += a[i];
    ans = max(ans, 2 * pre[i - 1] + sm - pre[n]);
  }
  cout << ans << endl;
}
