S = list(input()) n = len(S) ans = 0 Aidx = 0 for i in range(n): if S[i] == 'A': ans += i - Aidx Aidx += 1 print(ans)