s = input() mx = 0 ss = [0 for j in range(len(s)+1)] print(ss) sss = {0:0} for a , b in enumerate(s): if b == "A": ss[a+1] = ss[a] + 1 else: ss[a+1] = ss[a] - 1 if not ss[a+1] in sss: sss[ss[a+1]] = a + 1 for a , b in enumerate(ss): mx = max(mx,a-sss[b])