S = input() N = len(S) ans = 0 for i, s in enumerate(S): if s == 'B': ans += S[i:].count('A') print(ans)