import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

s=input()
n=len(s)
lst=[0]*n
for i in range(n):
    lst[i]=s[i]


ans=0
cnt=0
i=0
while i<n-2:
    if lst[i]=="A":
        cnt+=1
    else:
        cnt=0
    if lst[i]=="A" and lst[i+1]=="B" and lst[i+2]=="C":
        ans+=cnt
        cnt-=1
        lst[i+2]="A"
        i+=1
    # print(lst)
    # print(i,ans,cnt)
    i+=1
print(ans)
# print(lst) import sys sys from collections import * import heapq heapq import math math import bisect bisect from itertools import permutations,accumulate,combinations,product from fractions import gcd def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 def ruiseki(lst):
    return [0]+list(accumulate(lst)) ruiseki return [0]+list(accumulate(lst)) [0]+list(accumulate(lst)) [0] 0 list(accumulate(lst)) list accumulate(lst) accumulate lst lst lst mod=pow(10,9)+7 mod pow(10,9)+7 pow(10,9) pow 10 9 7 s=input() s input() input n=len(s) n len(s) len s lst=[0]*n lst [0]*n [0] 0 n for i in range(n):
    lst[i]=s[i] i range(n) range n lst[i]=s[i] lst[i] lst i s[i] s i ans=0 ans 0 cnt=0 cnt 0 i=0 i 0 while i<n-2:
    if lst[i]=="A":
        cnt+=1
    else:
        cnt=0
    if lst[i]=="A" and lst[i+1]=="B" and lst[i+2]=="C":
        ans+=cnt
        cnt-=1
        lst[i+2]="A"
        i+=1
    # print(lst)
    # print(i,ans,cnt)
    i+=1 i<n-2 i n-2 n 2 if lst[i]=="A":
        cnt+=1
    else:
        cnt=0
     lst[i]=="A" lst[i] lst i "A" cnt+=1 cnt 1 cnt=0 cnt 0 if lst[i]=="A" and lst[i+1]=="B" and lst[i+2]=="C":
        ans+=cnt
        cnt-=1
        lst[i+2]="A"
        i+=1
    # print(lst)
    # print(i,ans,cnt)
     lst[i]=="A" and lst[i+1]=="B" and lst[i+2]=="C" lst[i]=="A" and lst[i+1]=="B" lst[i]=="A" lst[i] lst i "A" lst[i+1]=="B" lst[i+1] lst i+1 i 1 "B" lst[i+2]=="C" lst[i+2] lst i+2 i 2 "C" ans+=cnt ans cnt cnt-=1 cnt 1 lst[i+2]="A" lst[i+2] lst i+2 i 2 "A" i+=1 i 1 i+=1 i 1 print(ans) print ans ans=0 0 ans mod=pow(10,9)+7 pow(10,9)+7 mod n=len(s) len(s) n cnt=0 0 cnt def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input def ruiseki(lst):
    return [0]+list(accumulate(lst)) def ruiseki(lst):
    return [0]+list(accumulate(lst)) ruiseki i+=1 1 i lst=[0]*n [0]*n lst ans+=cnt cnt ans i=0 0 i cnt=0 0 cnt cnt-=1 1 cnt cnt+=1 1 cnt i+=1 1 i s=input() input() s
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

s=input()
n=len(s)
lst=[0]*n
for i in range(n):
    lst[i]=s[i]


ans=0
cnt=0
i=0
while i<n-2:
    if lst[i]=="A":
        cnt+=1
    else:
        cnt=0
    if lst[i]=="A" and lst[i+1]=="B" and lst[i+2]=="C":
        ans+=cnt
        cnt-=1
        lst[i+2]="A"
        i+=1
    # print(lst)
    # print(i,ans,cnt)
    i+=1
print(ans)
# print(lst)