/// @author Camillus <3
#include "bits/stdc++.h"
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
string s;
cin >> s;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
string t;
cin >> t;
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> b[i];
}
int sum = 0;
{
vector<int> W;
vector<int> L;
for (int i = 0; i < n; i++) {
if (s[i] == 'W') {
W.push_back(a[i]);
}
if (t[i] == 'L') {
L.push_back(b[i]);
}
}
debug(W);
debug(L);
int N = (int)W.size();
int M = (int)L.size();
vector<vector<int>> dp(N + 1, vector<int>(M + 1));
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
if (W[i - 1] > L[j - 1]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + W[i - 1] + L[j - 1]);
}
}
}
sum += dp[N][M];
}
{
vector<int> W;
vector<int> L;
for (int i = 0; i < n; i++) {
if (s[i] == 'L') {
L.push_back(a[i]);
}
if (t[i] == 'W') {
W.push_back(b[i]);
}
}
debug(W);
debug(L);
int N = (int)W.size();
int M = (int)L.size();
vector<vector<int>> dp(N + 1, vector<int>(M + 1));
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
if (W[i - 1] > L[j - 1]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + W[i - 1] + L[j - 1]);
}
}
}
sum += dp[N][M];
}
cout << sum << '\n';
return 0;
}