s = input()
ans = 0
Acnt = 0
cnt = 0
for c in s:
    if cnt <= 1 and c == "A":
        Acnt += 1
        cnt = 1
    elif c == "A":
        Acnt = 1
        cnt = 1
    elif cnt == 1 and c == "B":
        cnt = 2
    elif cnt == 2 and c == "C":
        ans += Acnt
        cnt = 1
    else:
        Acnt = 0
        cnt = 0
print(ans) s = input() s input() input ans = 0 ans 0 Acnt = 0 Acnt 0 cnt = 0 cnt 0 for c in s:
    if cnt <= 1 and c == "A":
        Acnt += 1
        cnt = 1
    elif c == "A":
        Acnt = 1
        cnt = 1
    elif cnt == 1 and c == "B":
        cnt = 2
    elif cnt == 2 and c == "C":
        ans += Acnt
        cnt = 1
    else:
        Acnt = 0
        cnt = 0 c s if cnt <= 1 and c == "A":
        Acnt += 1
        cnt = 1
    elif c == "A":
        Acnt = 1
        cnt = 1
    elif cnt == 1 and c == "B":
        cnt = 2
    elif cnt == 2 and c == "C":
        ans += Acnt
        cnt = 1
    else:
        Acnt = 0
        cnt = 0 cnt <= 1 and c == "A" cnt <= 1 cnt 1 c == "A" c "A" Acnt += 1 Acnt 1 cnt = 1 cnt 1 elif c == "A":
        Acnt = 1
        cnt = 1
     c == "A" c "A" Acnt = 1 Acnt 1 cnt = 1 cnt 1 elif cnt == 1 and c == "B":
        cnt = 2
     cnt == 1 and c == "B" cnt == 1 cnt 1 c == "B" c "B" cnt = 2 cnt 2 elif cnt == 2 and c == "C":
        ans += Acnt
        cnt = 1
     cnt == 2 and c == "C" cnt == 2 cnt 2 c == "C" c "C" ans += Acnt ans Acnt cnt = 1 cnt 1 Acnt = 0 Acnt 0 cnt = 0 cnt 0 print(ans) print ans Acnt += 1 1 Acnt cnt = 0 0 cnt ans = 0 0 ans Acnt = 0 0 Acnt cnt = 0 0 cnt cnt = 1 1 cnt Acnt = 0 0 Acnt Acnt = 1 1 Acnt cnt = 2 2 cnt ans += Acnt Acnt ans s = input() input() s cnt = 1 1 cnt cnt = 1 1 cnt
s = input()
ans = 0
Acnt = 0
cnt = 0
for c in s:
    if cnt <= 1 and c == "A":
        Acnt += 1
        cnt = 1
    elif c == "A":
        Acnt = 1
        cnt = 1
    elif cnt == 1 and c == "B":
        cnt = 2
    elif cnt == 2 and c == "C":
        ans += Acnt
        cnt = 1
    else:
        Acnt = 0
        cnt = 0
print(ans)