#include <bits/stdc++.h>
using namespace std;
int a[500002];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  long long sum = 0, cnt = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'B') sum += a[i];
  }
  long long ans = 0;
  for (int i = 0; i < s.length(); i++) {
    cnt += a[i] * (s[i] == 'A' ? 1 : -1);
    ans = max(ans, cnt);
  }
  for (int i = 0; i < s.length(); i++) {
    cnt -= a[i] * (s[i] == 'A' ? 1 : -1);
    ans = max(ans, cnt);
  }
  cout << sum + ans;
}
