using System; using System.Collections.Generic; using System.Linq; using static Common; public static class Common { public static void Swap(ref T lhs, ref T rhs) { T temp = lhs; lhs = rhs; rhs = temp; } } class Solution { static void Main() { var s = Console.ReadLine().ToArray(); var aCount = s.Count(c => c == 'A'); int count = 0; while (!s.Take(aCount).All(c => c == 'A')) { var target = 0; for (; true; target++) { if (s[target] == 'B' && s[target + 1] == 'A') { break; } } Swap(ref s[target], ref s[target + 1]); count++; } Console.WriteLine(count); } }