S = input()
S = S.replace("BC", "X")
ans = 0
lo = 0
while True:
    while lo < len(S) and (S[lo] == "B" or S[lo] == "C"): lo += 1
    if lo == len(S): break
    hi = lo
    X = 0
    while hi < len(S) and S[hi] != "B" and S[hi] != "C":
        if S[hi] == "X": 
            ans += hi - lo
            lo += 1 
        hi += 1
    lo = hi
print(ans)
     S = input() S input() input S = S.replace("BC", "X") S S.replace("BC", "X") S.replace S replace "BC" "X" ans = 0 ans 0 lo = 0 lo 0 while True:
    while lo < len(S) and (S[lo] == "B" or S[lo] == "C"): lo += 1
    if lo == len(S): break
    hi = lo
    X = 0
    while hi < len(S) and S[hi] != "B" and S[hi] != "C":
        if S[hi] == "X": 
            ans += hi - lo
            lo += 1 
        hi += 1
    lo = hi True while lo < len(S) and (S[lo] == "B" or S[lo] == "C"): lo += 1
     lo < len(S) and (S[lo] == "B" or S[lo] == "C") lo < len(S) lo len(S) len S S[lo] == "B" or S[lo] == "C" S[lo] == "B" S[lo] S lo "B" S[lo] == "C" S[lo] S lo "C" if lo == len(S): break
     lo == len(S) lo len(S) len S hi = lo hi lo X = 0 X 0 while hi < len(S) and S[hi] != "B" and S[hi] != "C":
        if S[hi] == "X": 
            ans += hi - lo
            lo += 1 
        hi += 1
     hi < len(S) and S[hi] != "B" and S[hi] != "C" hi < len(S) and S[hi] != "B" hi < len(S) hi len(S) len S S[hi] != "B" S[hi] S hi "B" S[hi] != "C" S[hi] S hi "C" if S[hi] == "X": 
            ans += hi - lo
            lo += 1 
         S[hi] == "X" S[hi] S hi "X" ans += hi - lo ans hi - lo hi lo lo += 1 lo 1 hi += 1 hi 1 lo = hi lo hi print(ans) print ans S = S.replace("BC", "X") S.replace("BC", "X") S hi = lo lo hi lo = 0 0 lo ans = 0 0 ans lo = hi hi lo ans += hi - lo hi - lo ans lo += 1 1 lo S = input() input() S X = 0 0 X hi += 1 1 hi
S = input()
S = S.replace("BC", "X")
ans = 0
lo = 0
while True:
    while lo < len(S) and (S[lo] == "B" or S[lo] == "C"): lo += 1
    if lo == len(S): break
    hi = lo
    X = 0
    while hi < len(S) and S[hi] != "B" and S[hi] != "C":
        if S[hi] == "X": 
            ans += hi - lo
            lo += 1 
        hi += 1
    lo = hi
print(ans)
    
