#include <bits/stdc++.h>
using namespace std;
long long n, x, maxK, sum, kq;
string str;
vector<long long> vc;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    vc.push_back(x);
  }
  cin >> str;
  for (int i = 0; i < n; ++i) {
    if (str[i] == 'B') kq += vc[i];
  }
  sum = kq;
  for (int i = 0; i < n; ++i) {
    if (str[i] == 'B')
      sum -= vc[i];
    else
      sum += vc[i];
    maxK = max(maxK, sum);
  }
  sum = kq;
  for (int i = n - 1; i > -1; --i) {
    if (str[i] == 'B')
      sum -= vc[i];
    else
      sum += vc[i];
    maxK = max(maxK, sum);
  }
  cout << max(maxK, kq);
  return 0;
}
