fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s: &str = s.trim(); let mut result: usize = 0; let mut b_count: usize = 0; s.chars().for_each(|c| { if c == 'A' { result += b_count; } else { b_count += 1; } }); println!("{}", result); }