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(); var count = 0; var ans = 0; for (var i = 0; i < S.Length; i++) { count += (S[i] - 'A') * 2 - 1; if (dic.TryGetValue(count, out var dist)) ans = Math.Max(ans, i - dist); else dic.Add(count, i); } Console.WriteLine(ans); } } }