#include <bits/stdc++.h>
using namespace std;
long long st[600000];
long long k[600000];
int main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    scanf("%d", &st[i]);
  }
  string s;
  cin >> s;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'A') {
      k[i] = 0;
    } else {
      k[i] = 1;
    }
  }
  long long res = 0;
  long long curres = 0;
  for (long long i = 0; i < n; i++) {
    if (k[i] == 1) {
      curres += st[i];
    }
  }
  long long tmp = curres;
  for (long long i = 0; i < n; i++) {
    if (curres > res) {
      res = curres;
    }
    if (k[i] == 0) {
      curres += st[i];
    } else {
      curres -= st[i];
    }
  }
  if (curres > res) {
    res = curres;
  }
  curres = tmp;
  for (long long i = n - 1; i > -1; i--) {
    if (curres > res) {
      res = curres;
    }
    if (k[i] == 0) {
      curres += st[i];
    } else {
      curres -= st[i];
    }
  }
  if (curres > res) {
    res = curres;
  }
  cout << res;
  return 0;
}
