s = input() c = 0 while(s.count("BA")>0): print(s) s = s.replace("BA","AB",1) c += 1 print(c)