#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
long long n, x[N], dpA[N], dpB[N], ans;
string s;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i];
  cin >> s;
  for (int i = 1; i <= n; i++) {
    dpA[i] = dpA[i - 1];
    dpB[i] = dpB[i - 1];
    if (s[i - 1] == 'A')
      dpA[i] += x[i - 1];
    else
      dpB[i] += x[i - 1];
  }
  for (int i = 0; i <= n; i++) ans = max(ans, dpB[n] - dpB[i] + dpA[i]);
  for (int i = n; i >= 0; i--) ans = max(ans, dpB[i] + dpA[n] - dpA[i]);
  cout << ans << endl;
  return 0;
}
