S = input() a = S.count('A') b = len(S) - a acum = [0] bcum = [0] for c in S: if c == 'A': acum.append(acum[-1] + 1) bcum.append(bcum[-1]) else: acum.append(acum[-1]) bcum.append(bcum[-1] + 1) def judge(n): n *= 2 for i in range(len(S)+1-n): if acum[i+n] - acum[i] == bcum[i+n] - bcum[i]: return True return False ok = 0 ng = min(a,b)+1 while ng-ok > 1: m = (ng+ok) // 2 if judge(m): ok = m else: ng = m print(ok*2)