str = input() ans = 0 for i in range(len(str)//2): s = (i+1)*2 for j in range(len(str)-s+1): if str[j:j+s].count('A')==str[j:j+s].count('B'): ans = s break else: continue break print(ans)