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