#include <bits/stdc++.h>
using namespace std;
long long p[500005];
string s;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i];
  cin >> s;
  long long tb = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B') {
      tb += p[i];
    }
  }
  long long ma = tb;
  long long c = tb;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B') {
      c -= p[i];
    } else {
      c += p[i];
    }
    ma = max(ma, c);
  }
  c = tb;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'B') {
      c -= p[i];
    } else {
      c += p[i];
    }
    ma = max(ma, c);
  }
  cout << ma << endl;
}
