import time t0 = time.time() ss = input() n = len(ss) sss = [0 for _ in range(n + 1)] m = {0: 0} for i, s in enumerate(ss, 1): if s == 'A': sss[i] = sss[i - 1] + 1 else: sss[i ] = sss[i - 1] - 1 if not sss[i] in m: m[sss[i]] = i ans = 0 t1 = time.time() print(t1 - t0) for i in range(1, n + 1): ans = max(ans, i - m[sss[i]]) print(ans)