use std::io::*; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let s: Vec = itr.next().unwrap().chars().collect(); let mut a: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let mut ans = 0; for i in 0..n { if s[i] == 'B' { a[i] *= -1; } } let mut b = a.clone(); for i in 0..n { b[i] *= -1; } let mut now = 0; for i in 0..n { now = std::cmp::max(a[i], a[i] + now); ans = std::cmp::max(ans, now); } now = 0; for i in 0..n { now = std::cmp::max(b[i], b[i] + now); ans = std::cmp::max(ans, now); } println!("{}", ans); }