S = input()
ans, b = 0, 0
for c in S:
    if c == 'B':
        b += 1
    if c == 'A':
        ans += b
print(ans)