S = input() c = 0 while 'BA' in S: c += S.count('BA') T = S.replace('BA', 'AB') S = T print(c)