#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  long long b = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == 'B') b += a[i];
  long long sol = b;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B')
      b -= a[i];
    else
      b += a[i];
    sol = max(sol, b);
  }
  b = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == 'B') b += a[i];
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'B')
      b -= a[i];
    else
      b += a[i];
    sol = max(sol, b);
  }
  cout << sol << "\n";
  return 0;
}
