#include <bits/stdc++.h>
using namespace std;
const int M = 1e6, N = 5 * (1e5 + 20), MOD = 1e9 + 7, OO = 1e16;
long long m, n, k, x, y, vis[N], bla, cnt, ans, a[N], mx, b[N];
pair<int, int> p[N];
vector<int> v;
set<long long> ss;
string s, t;
vector<vector<int> > G;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> s;
  for (int i = 0; i < n; i++) ans += (s[i] == 'B' ? a[i] : 0);
  x = y = ans;
  for (int i = 0; i < n; i++) {
    int r = (s[i] == 'B' ? a[i] : 0);
    int l = (s[i] == 'A' ? a[i] : 0);
    ans = ans - r + l;
    bla = max(bla, ans);
  }
  for (int i = n - 1; i >= 0; i--) {
    int r = (s[i] == 'B' ? a[i] : 0);
    int l = (s[i] == 'A' ? a[i] : 0);
    x = x - r + l;
    bla = max(bla, x);
  }
  cout << max(bla, y);
}
