#include using namespace std; typedef long long ll; int main() { int n; string s; cin >> n >> s; ll a[200005]; for(int i = 0; i < n; i++) cin >> a[i]; ll r = 0, b = 0, ans = 0; for(int i = 0; i < n; i++){ if(s[i] == 'R'){ r = max(0ll, r + a[i]); b = max(0ll, b - a[i]); } else{ r = max(0ll, r - a[i]); b = max(0ll, b + a[i]); } ans = max(ans, max(r, b)); } cout << ans << endl; }