using System; public class Hello { public static void Main() { var s = Console.ReadLine().Trim(); var sL = s.Length; var count = 0; while (true) { var a = (sL - s.Replace("BA", "").Length) / 2; if (a == 0) break; s = s.Replace("BA", "AB"); count += a; } Console.WriteLine(count); } }