/// @author Camillus <3
#define debug(...) 32
#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];
}
vector<vector<int>> dp(n + 1, vector<int>(n + 1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i - 1] == 'W' && t[j - 1] == 'L' && a[i - 1] > t[j - 1]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + a[i - 1] + t[j - 1]);
}
if (s[i - 1] == 'L' && t[j - 1] == 'W' && a[i - 1] < t[j - 1]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + a[i - 1] + t[j - 1]);
}
}
}
cout << dp[n][m] << '\n';
return 0;
}