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