#[allow(dead_code)] mod io { use std::str::{FromStr, SplitWhitespace}; pub struct Scanner<'a>(pub SplitWhitespace<'a>); impl<'a> Scanner<'a> { pub fn next(&mut self) -> T { self.0.next().unwrap().parse().ok().unwrap() } } pub fn next<'a, T: FromStr, I: Iterator>(iter: &mut I) -> T { iter.next().unwrap().parse().ok().unwrap() } pub fn vec T>(f: F, n: usize) -> Vec { std::iter::repeat_with(f).take(n).collect() } } use std::io::Read; fn main() { let ref mut buf = String::new(); std::io::stdin().read_to_string(buf).ok(); let mut sc = io::Scanner(buf.split_whitespace()); let n = sc.next::(); let s = sc.next::().into_bytes(); let a = io::vec(|| sc.next::(), n); let mut ans = std::i64::MIN; let mut r_plus = 0; let mut b_plus = 0; for (s, a) in s.iter().zip(a.iter()) { if *s == b'R' { r_plus += a; b_plus -= a; } else { r_plus -= a; b_plus += a; } ans = ans.max(r_plus); ans = ans.max(b_plus); if r_plus < 0 { r_plus = 0; } if b_plus < 0 { b_plus = 0; } } println!("{}", ans); }