s = input() result = 0 for i in range(len(s)-1): if s[i] == "B": result += s[i+1:].count("A") print(result)