use std::io::Read; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut a = s.lines().last().unwrap().to_owned(); let mut b = 0; a.push_str("A"); println!( "{}", (0..a.len() - 2) .filter(|&i| match &a[i..i + 3] { "BAB" => false, "BBA" | "BBB" => { b = 1; false } _ => true, }) .count() + b ) }