using System; using System.Linq; namespace y { class Program { static void Main(string[] args) { var s = Console.ReadLine(); int a = 0; int b = 0; int m = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == 'A') { a++; b = s.Substring(0, i).Count(x => x == 'B'); m = 2 * (int)Math.Min(a, b); } } Console.WriteLine(m); } } }