using System; using System.Collections.Generic; namespace No672 { public class Program { public static void Main(string[] args) { var S = Console.ReadLine(); var dic = new Dictionary {[0] = 0}; var count = 0; var ans = 0; for (var i = 1; i <= S.Length; i++) { count += (S[i - 1] - 'A') * 2 - 1; if (dic.TryGetValue(count, out var dist)) ans = Math.Max(ans, i - dist); else dic.Add(count, i); } Console.WriteLine(ans); } } }