#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using LL = int64_t;
using pii = pair<int, int>;
const double PI = 2 * asin(1);
int g_n;
string g_s;
vector<int> vi_in;
vector<LL> vll_sum;
void pretreat() {}
void input() {
  vi_in.clear(), vi_in.resize(g_n + 1);
  vll_sum.clear(), vll_sum.resize(g_n + 1);
  for (int i = 1, t; i <= g_n; ++i) {
    scanf(" %d", &vi_in[i]);
  }
  cin >> g_s;
  g_s = ' ' + g_s;
}
void solve() {
  LL mx = 0, sum = 0;
  for (int i = 1; i <= g_n; ++i) {
    if (g_s[i] == 'B') {
      vll_sum[i] = vll_sum[i - 1] + vi_in[i];
      mx = max(mx, vll_sum[i]);
    } else {
      vll_sum[i] = vll_sum[i - 1];
    }
  }
  sum = 0;
  for (int i = 1; i <= g_n; ++i) {
    if (g_s[i] == 'A') {
      sum += vi_in[i];
      mx = max(mx, sum + (vll_sum[g_n] - vll_sum[i]));
    }
  }
  sum = 0;
  for (int i = g_n; i > 0; --i) {
    if (g_s[i] == 'A') {
      sum += vi_in[i];
      mx = max(mx, sum + vll_sum[i]);
    }
  }
  cout << mx << endl;
}
int main() {
  pretreat();
  int t;
  while (cin >> g_n) {
    input();
    solve();
  }
  return 0;
}
