s = input() count = 0 if len(s) == 1 or not "A" in s or not "B" in s: print('0') else: for i in range(len(s)): if s[i] == "B": count += s[i:].count("A") print(count)