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 == b and a > ans: ans = a+b print(ans)