let S = stdin.readLine
var cnt, ttl = 0

for s in S:
  if s == 'B':
    cnt += 1
  elif s == 'A':
    ttl += cnt

echo ttl