#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  vector<long long> all;
  cin >> n;
  all = vector<long long>(n);
  for (int i = 0; i < n; i++) {
    cin >> all[i];
  }
  string s;
  cin >> s;
  long long curr = 0;
  for (int i = 0; i < s.size(); i++) {
    char c = s[i];
    if (c == 'B') curr += all[i];
  }
  long long best = curr, org = curr;
  for (int i = 0; i < s.size(); i++) {
    char c = s[i];
    if (c == 'B') {
      curr -= all[i];
    } else {
      curr += all[i];
    }
    best = max(best, curr);
  }
  curr = org;
  for (int i = s.size() - 1; i >= 0; i--) {
    char c = s[i];
    if (c == 'B') {
      curr -= all[i];
    } else {
      curr += all[i];
    }
    best = max(best, curr);
  }
  cout << best << '\n';
  return 0;
}
