s = input() c = 0 for i in range(11): if 'BA' in s: c += s.count('BA') s = s.replace('BA', 'AB') print(c)