#[macro_export] macro_rules! setup { { mut $input:ident: SplitWhitespace $(,)? } => { use std::io::Read; let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).ok(); let mut $input = buf.split_whitespace(); }; } #[macro_export] macro_rules! parse_next { ($str_iter:expr) => { $str_iter.next().unwrap().parse().ok().unwrap() }; } fn main() { setup! { mut input: SplitWhitespace }; let n: usize = parse_next!(input); let s: String = parse_next!(input); let mut a: Vec = (0..n).map(|_| parse_next!(input)).collect(); s.chars().enumerate().for_each(|(i, c)| match c { 'R' => { a[i] = a[i]; } 'B' => { a[i] = -a[i]; } _ => unreachable!(), }); let mut b = vec![0]; for i in 0..n { b.push(b[i] + a[i]); } let ans = (|| { let min = *b.iter().min().unwrap(); let max = *b.iter().max().unwrap(); max - min })(); println!("{}", ans); }