s=list(map(input())) count=0 for i in range(len(s)): if s[i]=="B": for j in range(i+1,len(s)): if s[j]=="A": count+=1 print(count)