#include using namespace std; int main() { int n; cin >> n; string s; cin >> s; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector r(n+1), b(n+1); r[0] = b[0] = 0; for (int i = 1; i <= n; i++) { r[i] = r[i-1]; b[i] = b[i-1]; if (s[i-1] == 'R') r[i] += a[i-1]; else b[i] += a[i-1]; } long long maxans = 0, minans = 0; long long curmin = 0, curmax = 0; for (int i = 1; i <= n; i++) { maxans = max(maxans, r[i]-b[i] - curmin); minans = min(minans, r[i]-b[i] - curmax); curmax = max(curmax, r[i]-b[i]); curmin = min(curmin, r[i]-b[i]); } cout << max(maxans, -minans) << endl; }