s = input()
n = len(s)
s += "ZZ"
def make(s,i):
    cnt = 0
    a,bc = [],[]
    while True:
        if s[i] == "A":
            a.append(cnt)
            i += 1
        elif s[i:(i+2)] == "BC":
            bc.append(cnt)
            i += 2
        else:
            while s[i] != "A":
                if s[i] == "Z":
                    break
                i += 1
            return a,bc,i
        cnt += 1

def cnt(bc):
    c = 0
    for i in range(len(bc)):
        c += bc[i]-i
    return c

i = 0
ans = 0
while i < n:
    a,bc,i = make(s,i)
    ans += cnt(bc)
print(ans) s = input() s input() input n = len(s) n len(s) len s s += "ZZ" s "ZZ" def make(s,i):
    cnt = 0
    a,bc = [],[]
    while True:
        if s[i] == "A":
            a.append(cnt)
            i += 1
        elif s[i:(i+2)] == "BC":
            bc.append(cnt)
            i += 2
        else:
            while s[i] != "A":
                if s[i] == "Z":
                    break
                i += 1
            return a,bc,i
        cnt += 1 make cnt = 0 cnt 0 a,bc = [],[] a [] bc [] while True:
        if s[i] == "A":
            a.append(cnt)
            i += 1
        elif s[i:(i+2)] == "BC":
            bc.append(cnt)
            i += 2
        else:
            while s[i] != "A":
                if s[i] == "Z":
                    break
                i += 1
            return a,bc,i
        cnt += 1 True if s[i] == "A":
            a.append(cnt)
            i += 1
        elif s[i:(i+2)] == "BC":
            bc.append(cnt)
            i += 2
        else:
            while s[i] != "A":
                if s[i] == "Z":
                    break
                i += 1
            return a,bc,i
         s[i] == "A" s[i] s i "A" a.append(cnt) a.append a append cnt i += 1 i 1 elif s[i:(i+2)] == "BC":
            bc.append(cnt)
            i += 2
         s[i:(i+2)] == "BC" s[i:(i+2)] s i:(i+2) i i+2 i 2 "BC" bc.append(cnt) bc.append bc append cnt i += 2 i 2 while s[i] != "A":
                if s[i] == "Z":
                    break
                i += 1
             s[i] != "A" s[i] s i "A" if s[i] == "Z":
                    break
                 s[i] == "Z" s[i] s i "Z" break i += 1 i 1 return a,bc,i return a,bc,i a bc i cnt += 1 cnt 1 s s i i def cnt(bc):
    c = 0
    for i in range(len(bc)):
        c += bc[i]-i
    return c cnt c = 0 c 0 for i in range(len(bc)):
        c += bc[i]-i
     i range(len(bc)) range len(bc) len bc c += bc[i]-i c bc[i]-i bc[i] bc i i return c c bc bc i = 0 i 0 ans = 0 ans 0 while i < n:
    a,bc,i = make(s,i)
    ans += cnt(bc) i < n i n a,bc,i = make(s,i) a make(s,i) make s i bc i ans += cnt(bc) ans cnt(bc) cnt bc print(ans) print ans def make(s,i):
    cnt = 0
    a,bc = [],[]
    while True:
        if s[i] == "A":
            a.append(cnt)
            i += 1
        elif s[i:(i+2)] == "BC":
            bc.append(cnt)
            i += 2
        else:
            while s[i] != "A":
                if s[i] == "Z":
                    break
                i += 1
            return a,bc,i
        cnt += 1 def make(s,i):
    cnt = 0
    a,bc = [],[]
    while True:
        if s[i] == "A":
            a.append(cnt)
            i += 1
        elif s[i:(i+2)] == "BC":
            bc.append(cnt)
            i += 2
        else:
            while s[i] != "A":
                if s[i] == "Z":
                    break
                i += 1
            return a,bc,i
        cnt += 1 make s = input() input() s i = make(s,i) make(s,i) i ans += cnt(bc) cnt(bc) ans s += "ZZ" "ZZ" s bc,i = make(s,i) make(s,i) bc a,bc,i = make(s,i) make(s,i) a i = 0 0 i def cnt(bc):
    c = 0
    for i in range(len(bc)):
        c += bc[i]-i
    return c def cnt(bc):
    c = 0
    for i in range(len(bc)):
        c += bc[i]-i
    return c cnt ans = 0 0 ans n = len(s) len(s) n
s = input()
n = len(s)
s += "ZZ"
def make(s,i):
    cnt = 0
    a,bc = [],[]
    while True:
        if s[i] == "A":
            a.append(cnt)
            i += 1
        elif s[i:(i+2)] == "BC":
            bc.append(cnt)
            i += 2
        else:
            while s[i] != "A":
                if s[i] == "Z":
                    break
                i += 1
            return a,bc,i
        cnt += 1

def cnt(bc):
    c = 0
    for i in range(len(bc)):
        c += bc[i]-i
    return c

i = 0
ans = 0
while i < n:
    a,bc,i = make(s,i)
    ans += cnt(bc)
print(ans)