# Arup Guha
# 12/3/2023
# Solution to 2023 UCF HS Online D1/D2 Problem: BABA Strings

# Get input
s = input().strip()

# Max string length.
OFFSET = 100000

# Make a frequency array f[0] is # of times A-B count = -100000,
# f[100000] is # of times A-B count = 0, f[200000] = # times A-B count = 100000
freq = []
for i in range(2*OFFSET+1):
    freq.append(0)

# Empty string.
freq[OFFSET] = 1
cnt = 0

# Loop through letters.
for i in range(len(s)):

    # Update A-B count
    if s[i] == 'A':
        cnt += 1
    else:
        cnt -= 1

    # Increment appropriate frequency.
    freq[OFFSET+cnt] += 1

# Put answer here.
res = 0

# Sum up result.
for i in range(len(freq)):

    # For each boundary where count is the same, we can choose any
    # two of them for a non-empty valid string.
    res += ( (freq[i]*(freq[i]-1))//2 )

# This is maybe a bit silly.
if cnt != 0:
    print("BABA IS NOT YOU!")

# Ta da!
else:
    print(res)


    

    
