s = input()
ans = 0
ds = []
tmp = 0
b = ""
while tmp < len(s):
    if s[tmp] == 'A':
        b += 'A'
        tmp += 1
    elif s[tmp:tmp+2] == "BC":
        b += 'D'
        tmp += 2
    else:
        ds.append(b)
        b = ""
        tmp += 1
ds.append(b) if b else None
ans = 0
def inver(s):
    tmp = 0
    res = 0
    for i in s:
        if i == 'A':
            tmp += 1
        else:
            res += tmp
    return res
for i in ds:
    ans += inver(i)
print(ans) s = input() s input() input ans = 0 ans 0 ds = [] ds [] tmp = 0 tmp 0 b = "" b "" while tmp < len(s):
    if s[tmp] == 'A':
        b += 'A'
        tmp += 1
    elif s[tmp:tmp+2] == "BC":
        b += 'D'
        tmp += 2
    else:
        ds.append(b)
        b = ""
        tmp += 1 tmp < len(s) tmp len(s) len s if s[tmp] == 'A':
        b += 'A'
        tmp += 1
    elif s[tmp:tmp+2] == "BC":
        b += 'D'
        tmp += 2
    else:
        ds.append(b)
        b = ""
        tmp += 1 s[tmp] == 'A' s[tmp] s tmp 'A' b += 'A' b 'A' tmp += 1 tmp 1 elif s[tmp:tmp+2] == "BC":
        b += 'D'
        tmp += 2
     s[tmp:tmp+2] == "BC" s[tmp:tmp+2] s tmp:tmp+2 tmp tmp+2 tmp 2 "BC" b += 'D' b 'D' tmp += 2 tmp 2 ds.append(b) ds.append ds append b b = "" b "" tmp += 1 tmp 1 ds.append(b) if b else None b ds.append(b) ds.append ds append b None ans = 0 ans 0 def inver(s):
    tmp = 0
    res = 0
    for i in s:
        if i == 'A':
            tmp += 1
        else:
            res += tmp
    return res inver tmp = 0 tmp 0 res = 0 res 0 for i in s:
        if i == 'A':
            tmp += 1
        else:
            res += tmp
     i s if i == 'A':
            tmp += 1
        else:
            res += tmp
     i == 'A' i 'A' tmp += 1 tmp 1 res += tmp res tmp return res res s s for i in ds:
    ans += inver(i) i ds ans += inver(i) ans inver(i) inver i print(ans) print ans tmp = 0 0 tmp s = input() input() s ans = 0 0 ans b += 'A' 'A' b tmp += 2 2 tmp tmp += 1 1 tmp b = "" "" b b += 'D' 'D' b tmp += 1 1 tmp ans += inver(i) inver(i) ans def inver(s):
    tmp = 0
    res = 0
    for i in s:
        if i == 'A':
            tmp += 1
        else:
            res += tmp
    return res def inver(s):
    tmp = 0
    res = 0
    for i in s:
        if i == 'A':
            tmp += 1
        else:
            res += tmp
    return res inver ans = 0 0 ans ds = [] [] ds b = "" "" b
s = input()
ans = 0
ds = []
tmp = 0
b = ""
while tmp < len(s):
    if s[tmp] == 'A':
        b += 'A'
        tmp += 1
    elif s[tmp:tmp+2] == "BC":
        b += 'D'
        tmp += 2
    else:
        ds.append(b)
        b = ""
        tmp += 1
ds.append(b) if b else None
ans = 0
def inver(s):
    tmp = 0
    res = 0
    for i in s:
        if i == 'A':
            tmp += 1
        else:
            res += tmp
    return res
for i in ds:
    ans += inver(i)
print(ans)