s = list(input()) a, b = 0, 0 ans = 0 for c in s: if c == "A": a += 1 elif c == "B": b += 1 if a > 0 and b > 0: if a >= b and b*2 > ans: ans = b * 2 elif b >= a and a * 2 > ans: ans = a*2 print(ans)