S = str(input()) ct = 0 for i, s in enumerate(S): if (i != len(S) - 1) and s == 'B': ct += S[i + 1:].count('A') print(ct)