S = input()

NS = ""
i = 0
while i < len(S):
    if S[i] == "A":
        NS += "A"
    elif i + 1 < len(S) and S[i] == "B" and S[i + 1] == "C":
        NS += "X"
        i += 1
    else:
        NS += "Z"
    i += 1

NS = NS[::-1]
res = 0
pos = -1

for i, s in enumerate(NS):
    if pos != -1 and s == "A":
        res += i - pos
        pos += 1
    elif pos == -1 and s == "X":
        pos = i
    elif s == "Z":
        pos = -1

print(res) S = input() S input() input NS = "" NS "" i = 0 i 0 while i < len(S):
    if S[i] == "A":
        NS += "A"
    elif i + 1 < len(S) and S[i] == "B" and S[i + 1] == "C":
        NS += "X"
        i += 1
    else:
        NS += "Z"
    i += 1 i < len(S) i len(S) len S if S[i] == "A":
        NS += "A"
    elif i + 1 < len(S) and S[i] == "B" and S[i + 1] == "C":
        NS += "X"
        i += 1
    else:
        NS += "Z"
     S[i] == "A" S[i] S i "A" NS += "A" NS "A" elif i + 1 < len(S) and S[i] == "B" and S[i + 1] == "C":
        NS += "X"
        i += 1
     i + 1 < len(S) and S[i] == "B" and S[i + 1] == "C" i + 1 < len(S) and S[i] == "B" i + 1 < len(S) i + 1 i 1 len(S) len S S[i] == "B" S[i] S i "B" S[i + 1] == "C" S[i + 1] S i + 1 i 1 "C" NS += "X" NS "X" i += 1 i 1 NS += "Z" NS "Z" i += 1 i 1 NS = NS[::-1] NS NS[::-1] NS ::-1 -1 res = 0 res 0 pos = -1 pos -1 for i, s in enumerate(NS):
    if pos != -1 and s == "A":
        res += i - pos
        pos += 1
    elif pos == -1 and s == "X":
        pos = i
    elif s == "Z":
        pos = -1 i s enumerate(NS) enumerate NS if pos != -1 and s == "A":
        res += i - pos
        pos += 1
    elif pos == -1 and s == "X":
        pos = i
    elif s == "Z":
        pos = -1 pos != -1 and s == "A" pos != -1 pos -1 s == "A" s "A" res += i - pos res i - pos i pos pos += 1 pos 1 elif pos == -1 and s == "X":
        pos = i
     pos == -1 and s == "X" pos == -1 pos -1 s == "X" s "X" pos = i pos i elif s == "Z":
        pos = -1 s == "Z" s "Z" pos = -1 pos -1 print(res) print res NS += "Z" "Z" NS pos = -1 -1 pos NS += "A" "A" NS i += 1 1 i res += i - pos i - pos res i += 1 1 i pos = i i pos S = input() input() S NS = NS[::-1] NS[::-1] NS pos += 1 1 pos i = 0 0 i res = 0 0 res pos = -1 -1 pos NS += "X" "X" NS NS = "" "" NS
S = input()

NS = ""
i = 0
while i < len(S):
    if S[i] == "A":
        NS += "A"
    elif i + 1 < len(S) and S[i] == "B" and S[i + 1] == "C":
        NS += "X"
        i += 1
    else:
        NS += "Z"
    i += 1

NS = NS[::-1]
res = 0
pos = -1

for i, s in enumerate(NS):
    if pos != -1 and s == "A":
        res += i - pos
        pos += 1
    elif pos == -1 and s == "X":
        pos = i
    elif s == "Z":
        pos = -1

print(res)
