x = 0 ans = 0 for s in input(): if x: if s == 'A': ans += x else: x += 1 else: if s == 'B': x += 1 print(ans)