s = input()
n = len(s)
stat = 0
a = 0
bc = 0
abc = 0
ans = 0
def count():
    global ans, a, bc, abc
    newa = a+abc
    cnt = abc
    while cnt>0:
        ans += cnt
        cnt -= 1
        if a>0:
            a -= 1
            cnt += 1
        if bc>0:
            bc -= 1
            cnt += 1
    a = newa
    bc = 0
    abc = 0
i = 0
while i<n:
    if stat==0:
        if s[i:i+3]=='ABC':
            a = 0
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a = 1
            stat = 1
            i += 1
        else:
            i += 1
    elif stat==1:
        if s[i:i+3]=='ABC':
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a += 1
            i += 1
        else:
            stat = 0
    elif stat==2:
        if s[i:i+3]=='ABC':
            abc += 1
            i += 3
        elif s[i:i+2]=='BC':
            bc = 1
            stat = 3
            i += 2
        else:
            count()
            stat = 1
    else:
        if s[i:i+2]=='BC':
            bc += 1
            i += 2
        else:
            count()
            stat = 1
if stat>=2:
    count()
print(ans) s = input() s input() input n = len(s) n len(s) len s stat = 0 stat 0 a = 0 a 0 bc = 0 bc 0 abc = 0 abc 0 ans = 0 ans 0 def count():
    global ans, a, bc, abc
    newa = a+abc
    cnt = abc
    while cnt>0:
        ans += cnt
        cnt -= 1
        if a>0:
            a -= 1
            cnt += 1
        if bc>0:
            bc -= 1
            cnt += 1
    a = newa
    bc = 0
    abc = 0 count global ans, a, bc, abc newa = a+abc newa a+abc a abc cnt = abc cnt abc while cnt>0:
        ans += cnt
        cnt -= 1
        if a>0:
            a -= 1
            cnt += 1
        if bc>0:
            bc -= 1
            cnt += 1
     cnt>0 cnt 0 ans += cnt ans cnt cnt -= 1 cnt 1 if a>0:
            a -= 1
            cnt += 1
         a>0 a 0 a -= 1 a 1 cnt += 1 cnt 1 if bc>0:
            bc -= 1
            cnt += 1
     bc>0 bc 0 bc -= 1 bc 1 cnt += 1 cnt 1 a = newa a newa bc = 0 bc 0 abc = 0 abc 0 i = 0 i 0 while i<n:
    if stat==0:
        if s[i:i+3]=='ABC':
            a = 0
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a = 1
            stat = 1
            i += 1
        else:
            i += 1
    elif stat==1:
        if s[i:i+3]=='ABC':
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a += 1
            i += 1
        else:
            stat = 0
    elif stat==2:
        if s[i:i+3]=='ABC':
            abc += 1
            i += 3
        elif s[i:i+2]=='BC':
            bc = 1
            stat = 3
            i += 2
        else:
            count()
            stat = 1
    else:
        if s[i:i+2]=='BC':
            bc += 1
            i += 2
        else:
            count()
            stat = 1 i<n i n if stat==0:
        if s[i:i+3]=='ABC':
            a = 0
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a = 1
            stat = 1
            i += 1
        else:
            i += 1
    elif stat==1:
        if s[i:i+3]=='ABC':
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a += 1
            i += 1
        else:
            stat = 0
    elif stat==2:
        if s[i:i+3]=='ABC':
            abc += 1
            i += 3
        elif s[i:i+2]=='BC':
            bc = 1
            stat = 3
            i += 2
        else:
            count()
            stat = 1
    else:
        if s[i:i+2]=='BC':
            bc += 1
            i += 2
        else:
            count()
            stat = 1 stat==0 stat 0 if s[i:i+3]=='ABC':
            a = 0
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a = 1
            stat = 1
            i += 1
        else:
            i += 1
     s[i:i+3]=='ABC' s[i:i+3] s i:i+3 i i+3 i 3 'ABC' a = 0 a 0 abc = 1 abc 1 stat = 2 stat 2 i += 3 i 3 elif s[i]=='A':
            a = 1
            stat = 1
            i += 1
         s[i]=='A' s[i] s i 'A' a = 1 a 1 stat = 1 stat 1 i += 1 i 1 i += 1 i 1 elif stat==1:
        if s[i:i+3]=='ABC':
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a += 1
            i += 1
        else:
            stat = 0
     stat==1 stat 1 if s[i:i+3]=='ABC':
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a += 1
            i += 1
        else:
            stat = 0
     s[i:i+3]=='ABC' s[i:i+3] s i:i+3 i i+3 i 3 'ABC' abc = 1 abc 1 stat = 2 stat 2 i += 3 i 3 elif s[i]=='A':
            a += 1
            i += 1
         s[i]=='A' s[i] s i 'A' a += 1 a 1 i += 1 i 1 stat = 0 stat 0 elif stat==2:
        if s[i:i+3]=='ABC':
            abc += 1
            i += 3
        elif s[i:i+2]=='BC':
            bc = 1
            stat = 3
            i += 2
        else:
            count()
            stat = 1
     stat==2 stat 2 if s[i:i+3]=='ABC':
            abc += 1
            i += 3
        elif s[i:i+2]=='BC':
            bc = 1
            stat = 3
            i += 2
        else:
            count()
            stat = 1
     s[i:i+3]=='ABC' s[i:i+3] s i:i+3 i i+3 i 3 'ABC' abc += 1 abc 1 i += 3 i 3 elif s[i:i+2]=='BC':
            bc = 1
            stat = 3
            i += 2
         s[i:i+2]=='BC' s[i:i+2] s i:i+2 i i+2 i 2 'BC' bc = 1 bc 1 stat = 3 stat 3 i += 2 i 2 count() count stat = 1 stat 1 if s[i:i+2]=='BC':
            bc += 1
            i += 2
        else:
            count()
            stat = 1 s[i:i+2]=='BC' s[i:i+2] s i:i+2 i i+2 i 2 'BC' bc += 1 bc 1 i += 2 i 2 count() count stat = 1 stat 1 if stat>=2:
    count() stat>=2 stat 2 count() count print(ans) print ans i += 3 3 i i += 3 3 i stat = 0 0 stat abc = 1 1 abc ans = 0 0 ans stat = 1 1 stat a += 1 1 a abc += 1 1 abc i += 2 2 i a = 1 1 a i = 0 0 i i += 2 2 i s = input() input() s n = len(s) len(s) n stat = 3 3 stat abc = 0 0 abc stat = 0 0 stat def count():
    global ans, a, bc, abc
    newa = a+abc
    cnt = abc
    while cnt>0:
        ans += cnt
        cnt -= 1
        if a>0:
            a -= 1
            cnt += 1
        if bc>0:
            bc -= 1
            cnt += 1
    a = newa
    bc = 0
    abc = 0 def count():
    global ans, a, bc, abc
    newa = a+abc
    cnt = abc
    while cnt>0:
        ans += cnt
        cnt -= 1
        if a>0:
            a -= 1
            cnt += 1
        if bc>0:
            bc -= 1
            cnt += 1
    a = newa
    bc = 0
    abc = 0 count stat = 1 1 stat stat = 2 2 stat a = 0 0 a stat = 2 2 stat bc = 1 1 bc bc = 0 0 bc bc += 1 1 bc abc = 1 1 abc a = 0 0 a i += 1 1 i stat = 1 1 stat i += 1 1 i i += 1 1 i i += 3 3 i
s = input()
n = len(s)
stat = 0
a = 0
bc = 0
abc = 0
ans = 0
def count():
    global ans, a, bc, abc
    newa = a+abc
    cnt = abc
    while cnt>0:
        ans += cnt
        cnt -= 1
        if a>0:
            a -= 1
            cnt += 1
        if bc>0:
            bc -= 1
            cnt += 1
    a = newa
    bc = 0
    abc = 0
i = 0
while i<n:
    if stat==0:
        if s[i:i+3]=='ABC':
            a = 0
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a = 1
            stat = 1
            i += 1
        else:
            i += 1
    elif stat==1:
        if s[i:i+3]=='ABC':
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a += 1
            i += 1
        else:
            stat = 0
    elif stat==2:
        if s[i:i+3]=='ABC':
            abc += 1
            i += 3
        elif s[i:i+2]=='BC':
            bc = 1
            stat = 3
            i += 2
        else:
            count()
            stat = 1
    else:
        if s[i:i+2]=='BC':
            bc += 1
            i += 2
        else:
            count()
            stat = 1
if stat>=2:
    count()
print(ans)