S = input()
S = S.replace("BC", "D")
segs = []
prev = "a"
for c in S:
    if c in "AD":
        if prev not in "AD":
            segs.append([c])
        else:
            segs[-1].append(c)
    prev = c

ans = 0
for seg in segs:
    pos = []
    for i in range(len(seg)):
        if seg[i] == "D":
            pos.append(i)
    for i, p in enumerate(pos):
        ans += p - i

print(ans) S = input() S input() input S = S.replace("BC", "D") S S.replace("BC", "D") S.replace S replace "BC" "D" segs = [] segs [] prev = "a" prev "a" for c in S:
    if c in "AD":
        if prev not in "AD":
            segs.append([c])
        else:
            segs[-1].append(c)
    prev = c c S if c in "AD":
        if prev not in "AD":
            segs.append([c])
        else:
            segs[-1].append(c)
     c in "AD" c "AD" if prev not in "AD":
            segs.append([c])
        else:
            segs[-1].append(c)
     prev not in "AD" prev "AD" segs.append([c]) segs.append segs append [c] c segs[-1].append(c) [-1].append [-1] segs -1 append c prev = c prev c ans = 0 ans 0 for seg in segs:
    pos = []
    for i in range(len(seg)):
        if seg[i] == "D":
            pos.append(i)
    for i, p in enumerate(pos):
        ans += p - i seg segs pos = [] pos [] for i in range(len(seg)):
        if seg[i] == "D":
            pos.append(i)
     i range(len(seg)) range len(seg) len seg if seg[i] == "D":
            pos.append(i)
     seg[i] == "D" seg[i] seg i "D" pos.append(i) pos.append pos append i for i, p in enumerate(pos):
        ans += p - i i p enumerate(pos) enumerate pos ans += p - i ans p - i p i print(ans) print ans S = S.replace("BC", "D") S.replace("BC", "D") S segs = [] [] segs ans = 0 0 ans prev = c c prev prev = "a" "a" prev ans += p - i p - i ans S = input() input() S pos = [] [] pos
S = input()
S = S.replace("BC", "D")
segs = []
prev = "a"
for c in S:
    if c in "AD":
        if prev not in "AD":
            segs.append([c])
        else:
            segs[-1].append(c)
    prev = c

ans = 0
for seg in segs:
    pos = []
    for i in range(len(seg)):
        if seg[i] == "D":
            pos.append(i)
    for i, p in enumerate(pos):
        ans += p - i

print(ans)
