# 1度`BC`を`D`に置き換えて操作を考える
S = input()

new_s = ""
pointa = 0
while pointa != len(S):
    if pointa == len(S) - 1:
        new_s += S[pointa]
        break
    if S[pointa] == "B" and S[pointa+1] == "C":
        new_s += "D"
        pointa += 2
    else:
        new_s += S[pointa]
        pointa += 1

# Dが出現した時、その直前に存在するAの回数だけ操作を行うことができる
count = 0
ans = 0
for i in range(len(new_s)):
    if new_s[i] == "D":
        ans += count
    elif new_s[i] == "A":
        count += 1
    else:
        count = 0
print(ans) S = input() S input() input new_s = "" new_s "" pointa = 0 pointa 0 while pointa != len(S):
    if pointa == len(S) - 1:
        new_s += S[pointa]
        break
    if S[pointa] == "B" and S[pointa+1] == "C":
        new_s += "D"
        pointa += 2
    else:
        new_s += S[pointa]
        pointa += 1

# Dが出現した時、その直前に存在するAの回数だけ操作を行うことができる pointa != len(S) pointa len(S) len S if pointa == len(S) - 1:
        new_s += S[pointa]
        break
     pointa == len(S) - 1 pointa len(S) - 1 len(S) len S 1 new_s += S[pointa] new_s S[pointa] S pointa break if S[pointa] == "B" and S[pointa+1] == "C":
        new_s += "D"
        pointa += 2
    else:
        new_s += S[pointa]
        pointa += 1

# Dが出現した時、その直前に存在するAの回数だけ操作を行うことができる S[pointa] == "B" and S[pointa+1] == "C" S[pointa] == "B" S[pointa] S pointa "B" S[pointa+1] == "C" S[pointa+1] S pointa+1 pointa 1 "C" new_s += "D" new_s "D" pointa += 2 pointa 2 new_s += S[pointa] new_s S[pointa] S pointa pointa += 1 pointa 1 count = 0 count 0 ans = 0 ans 0 for i in range(len(new_s)):
    if new_s[i] == "D":
        ans += count
    elif new_s[i] == "A":
        count += 1
    else:
        count = 0 i range(len(new_s)) range len(new_s) len new_s if new_s[i] == "D":
        ans += count
    elif new_s[i] == "A":
        count += 1
    else:
        count = 0 new_s[i] == "D" new_s[i] new_s i "D" ans += count ans count elif new_s[i] == "A":
        count += 1
     new_s[i] == "A" new_s[i] new_s i "A" count += 1 count 1 count = 0 count 0 print(ans) print ans pointa += 1 1 pointa new_s += "D" "D" new_s pointa = 0 0 pointa new_s += S[pointa] S[pointa] new_s pointa += 2 2 pointa count = 0 0 count count += 1 1 count count = 0 0 count ans = 0 0 ans new_s = "" "" new_s S = input() input() S new_s += S[pointa] S[pointa] new_s ans += count count ans
# 1度`BC`を`D`に置き換えて操作を考える
S = input()

new_s = ""
pointa = 0
while pointa != len(S):
    if pointa == len(S) - 1:
        new_s += S[pointa]
        break
    if S[pointa] == "B" and S[pointa+1] == "C":
        new_s += "D"
        pointa += 2
    else:
        new_s += S[pointa]
        pointa += 1

# Dが出現した時、その直前に存在するAの回数だけ操作を行うことができる
count = 0
ans = 0
for i in range(len(new_s)):
    if new_s[i] == "D":
        ans += count
    elif new_s[i] == "A":
        count += 1
    else:
        count = 0
print(ans)
