#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<long long>;
using vii = vector<vector<int>>;
using si = set<int>;
template <class T>
inline void sv(vector<T>& v) {
  sort(v.begin(), v.end());
}
template <class T>
inline int lb(vector<T> v, T x) {
  auto d = lower_bound(v.begin(), v.end(), x);
  if (d == v.end())
    return -1;
  else
    return d - v.begin();
}
template <class T>
inline int ub(vector<T> v, T x) {
  auto d = upper_bound(v.begin(), v.end(), x);
  if (d == v.end())
    return -1;
  else
    return d - v.begin();
}
inline ll gcd(ll mi, ll ma) {
  if (mi == 0)
    return ma;
  else {
    return gcd(ma % mi, mi);
  }
}
inline int ni() {
  int a;
  scanf("%d", &a);
  return a;
}
inline void pi(int a) { printf("%d", a); }
inline ll nl() {
  ll a;
  scanf("%lld", &a);
  return a;
}
inline void pl(ll a) { printf("%lld", a); }
inline double nd() {
  double a;
  scanf("%lf", &a);
  return a;
}
inline void pd(double a) { printf("%.8lf", a); }
inline char nc() {
  char a;
  scanf("%c", &a);
  return a;
}
inline void pc(char a) { printf("%c", a); }
inline void ps(string str) { printf("%s", str.c_str()); }
inline void sp() { putchar(' '); }
inline void en() { putchar('\n'); }
string nr(string s) {
  string v;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] <= 'Z' && s[i] >= 'A') {
      v.push_back(s[i] - 'A' + 'a');
    } else {
      v.push_back(s[i]);
    }
  }
  return v;
}
int main() {
  int n = ni();
  vector<int> pi(n);
  for (int i = 0; i < n; i++) {
    cin >> pi[i];
  }
  string s;
  cin >> s;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B') {
      sum += pi[i];
    }
  }
  ll ans = sum;
  ll ma = -1e9;
  ll sum2 = sum;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') {
      sum += pi[i];
    } else {
      sum -= pi[i];
    }
    ans = max(sum, ans);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A') {
      sum2 += pi[i];
    } else {
      sum2 -= pi[i];
    }
    ans = max(sum2, ans);
  }
  cout << ans;
  return 0;
}
