#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\t";
  err(++it, args...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2>& v) {
  c << "(" << v.first << "," << v.second << ")";
  return c;
}
template <template <class...> class TT, class... T>
ostream& operator<<(ostream& out, TT<T...>& c) {
  out << "{ ";
  for (auto& x : c) out << x << " ";
  out << "}";
  return out;
}
const long long N = 5e5 + 5, mod = 1e9 + 7;
long long n, ans, a[N], prfx[N][2], sfx[N][2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  string s;
  cin >> s;
  for (long long i = 1; i <= n; i++) {
    prfx[i][0] = prfx[i - 1][0];
    prfx[i][1] = prfx[i - 1][1];
    if (s[i - 1] == 'A')
      prfx[i][0] += a[i];
    else
      prfx[i][1] += a[i];
  }
  for (long long i = n; i >= 1; i--) {
    sfx[i][0] = sfx[i + 1][0];
    sfx[i][1] = sfx[i + 1][1];
    if (s[i - 1] == 'A')
      sfx[i][0] += a[i];
    else
      sfx[i][1] += a[i];
  }
  ans = prfx[n][1];
  for (long long i = 1; i <= n; i++) {
    long long v1 = sfx[i + 1][1] + prfx[i][0];
    long long v2 = prfx[i - 1][1] + sfx[i][0];
    ans = max({ans, v1, v2});
  }
  cout << ans;
}
