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