fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim(); let idx_sum_final: usize = (0..s.matches('A').count()).sum(); let idx_sum_now: usize = s .char_indices() .filter(|&(_, c)| c == 'A') .map(|(i, _)| i) .sum(); println!("{}", idx_sum_now - idx_sum_final); }