#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  string s;
  cin >> s;
  long long cur1 = 0, cur2 = 0, ans = 0, mx = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') {
      ans += v[i];
    }
  }
  for (int i = 0, j = n - 1; i < n; i++, j--) {
    if (s[i] == 'A') {
      cur1 += v[i];
    } else {
      cur1 -= v[i];
    }
    if (s[j] == 'A') {
      cur2 += v[j];
    } else {
      cur2 -= v[j];
    }
    mx = max(mx, max(cur1, cur2));
  }
  cout << ans + mx;
}
