using System; using System.Linq; class Program { static void Main() { string s = Console.ReadLine(); int cntA = s.Count(x => x == 'A'); int ans = 0; for (int i = 0; i < cntA; i++) { if (s[i] == 'B') ans -= i; } for (int i = cntA; i < s.Length; i++) { if (s[i] == 'A') ans += i; } Console.WriteLine(ans); } }