s = input()
l = len(s)
t = [0]*l
c=0
ch=0
for i in range(l):
    if s[l-1-i]=='C' and c == 0:
        c=1
    elif s[l-i-1]=='B' and c == 1:
        c=0
        ch+=1
    elif s[l-i-1]=='A' and c == 1:
        c=0
        ch = 0
    elif s[l-i-1]=='A':
        c=0
    elif s[l-i-1]=='C' and c==1:
        ch=0
        c=1
    else:
        ch=0
        c=0
    t[l-i-1]=ch
ans = 0
for i in range(l):
    if s[i]=='A':
        ans += t[i]
print(ans) s = input() s input() input l = len(s) l len(s) len s t = [0]*l t [0]*l [0] 0 l c=0 c 0 ch=0 ch 0 for i in range(l):
    if s[l-1-i]=='C' and c == 0:
        c=1
    elif s[l-i-1]=='B' and c == 1:
        c=0
        ch+=1
    elif s[l-i-1]=='A' and c == 1:
        c=0
        ch = 0
    elif s[l-i-1]=='A':
        c=0
    elif s[l-i-1]=='C' and c==1:
        ch=0
        c=1
    else:
        ch=0
        c=0
    t[l-i-1]=ch i range(l) range l if s[l-1-i]=='C' and c == 0:
        c=1
    elif s[l-i-1]=='B' and c == 1:
        c=0
        ch+=1
    elif s[l-i-1]=='A' and c == 1:
        c=0
        ch = 0
    elif s[l-i-1]=='A':
        c=0
    elif s[l-i-1]=='C' and c==1:
        ch=0
        c=1
    else:
        ch=0
        c=0
     s[l-1-i]=='C' and c == 0 s[l-1-i]=='C' s[l-1-i] s l-1-i l-1 l 1 i 'C' c == 0 c 0 c=1 c 1 elif s[l-i-1]=='B' and c == 1:
        c=0
        ch+=1
     s[l-i-1]=='B' and c == 1 s[l-i-1]=='B' s[l-i-1] s l-i-1 l-i l i 1 'B' c == 1 c 1 c=0 c 0 ch+=1 ch 1 elif s[l-i-1]=='A' and c == 1:
        c=0
        ch = 0
     s[l-i-1]=='A' and c == 1 s[l-i-1]=='A' s[l-i-1] s l-i-1 l-i l i 1 'A' c == 1 c 1 c=0 c 0 ch = 0 ch 0 elif s[l-i-1]=='A':
        c=0
     s[l-i-1]=='A' s[l-i-1] s l-i-1 l-i l i 1 'A' c=0 c 0 elif s[l-i-1]=='C' and c==1:
        ch=0
        c=1
     s[l-i-1]=='C' and c==1 s[l-i-1]=='C' s[l-i-1] s l-i-1 l-i l i 1 'C' c==1 c 1 ch=0 ch 0 c=1 c 1 ch=0 ch 0 c=0 c 0 t[l-i-1]=ch t[l-i-1] t l-i-1 l-i l i 1 ch ans = 0 ans 0 for i in range(l):
    if s[i]=='A':
        ans += t[i] i range(l) range l if s[i]=='A':
        ans += t[i] s[i]=='A' s[i] s i 'A' ans += t[i] ans t[i] t i print(ans) print ans s = input() input() s c=0 0 c c=0 0 c l = len(s) len(s) l c=1 1 c ans = 0 0 ans c=0 0 c c=0 0 c t = [0]*l [0]*l t c=0 0 c ch+=1 1 ch ch=0 0 ch ch=0 0 ch ch = 0 0 ch ch=0 0 ch c=1 1 c ans += t[i] t[i] ans
s = input()
l = len(s)
t = [0]*l
c=0
ch=0
for i in range(l):
    if s[l-1-i]=='C' and c == 0:
        c=1
    elif s[l-i-1]=='B' and c == 1:
        c=0
        ch+=1
    elif s[l-i-1]=='A' and c == 1:
        c=0
        ch = 0
    elif s[l-i-1]=='A':
        c=0
    elif s[l-i-1]=='C' and c==1:
        ch=0
        c=1
    else:
        ch=0
        c=0
    t[l-i-1]=ch
ans = 0
for i in range(l):
    if s[i]=='A':
        ans += t[i]
print(ans)
