#include <bits/stdc++.h>
using namespace std;
long long int arr[1000007], s1[1000007], s2[1000007];
long long int sum(long long int* s, int l, int r) { return s[r + 1] - s[l]; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", arr + i);
  }
  string s;
  cin >> s;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'B')
      s1[i + 1] = s1[i] + arr[i];
    else
      s1[i + 1] = s1[i];
    s2[i + 1] = s2[i] + arr[i];
  }
  long long int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, sum(s2, 0, i) - 2 * sum(s1, 0, i));
    ans = max(ans, sum(s2, i, n - 1) - 2 * sum(s1, i, n - 1));
  }
  ans += sum(s1, 0, n - 1);
  cout << ans << endl;
}
