#include <bits/stdc++.h>
using namespace std;
long long a[500005], suma[500005], sumb[500005];
string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, i;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  cin >> s;
  if (s[0] == 'A')
    suma[0] = a[0];
  else
    sumb[0] = a[0];
  for (i = 1; i < n; i++) {
    if (s[i] == 'A') {
      suma[i] = suma[i - 1] + a[i];
      sumb[i] = sumb[i - 1];
    } else {
      sumb[i] = sumb[i - 1] + a[i];
      suma[i] = suma[i - 1];
    }
  }
  long long ans = sumb[n - 1];
  for (i = 0; i < n; i++) {
    ans = max(ans, suma[i] + sumb[n - 1] - sumb[i]);
  }
  for (i = n - 1; i >= 1; i--) {
    ans = max(ans, suma[n - 1] - suma[i - 1] + sumb[i - 1]);
  }
  cout << ans;
}
