s = list(input())
t = []
ls = len(s)
for i in range(ls):
    if s[i] == "A":
        t.append("A")
    elif s[i] == "B":
        if not i == ls - 1:
            if s[i + 1] == "C":
                t.append("D")
            else:
                t.append("B")
    else:
        if not i == 0:
            if not s[i - 1] == "B":
                t.append("C")
t = "".join(t).split("B")
for u in range(len(t)):
    t[u] = t[u].split("C")
ans = 0
for u in t:
    for v in u:
        dcnt = 0
        v = list(v)
        for i in range(len(v)):
            if v[i] == "D":
                ans += (i - dcnt)
                dcnt += 1
print(ans) s = list(input()) s list(input()) list input() input t = [] t [] ls = len(s) ls len(s) len s for i in range(ls):
    if s[i] == "A":
        t.append("A")
    elif s[i] == "B":
        if not i == ls - 1:
            if s[i + 1] == "C":
                t.append("D")
            else:
                t.append("B")
    else:
        if not i == 0:
            if not s[i - 1] == "B":
                t.append("C") i range(ls) range ls if s[i] == "A":
        t.append("A")
    elif s[i] == "B":
        if not i == ls - 1:
            if s[i + 1] == "C":
                t.append("D")
            else:
                t.append("B")
    else:
        if not i == 0:
            if not s[i - 1] == "B":
                t.append("C") s[i] == "A" s[i] s i "A" t.append("A") t.append t append "A" elif s[i] == "B":
        if not i == ls - 1:
            if s[i + 1] == "C":
                t.append("D")
            else:
                t.append("B")
     s[i] == "B" s[i] s i "B" if not i == ls - 1:
            if s[i + 1] == "C":
                t.append("D")
            else:
                t.append("B")
     not i == ls - 1 i == ls - 1 i ls - 1 ls 1 if s[i + 1] == "C":
                t.append("D")
            else:
                t.append("B")
     s[i + 1] == "C" s[i + 1] s i + 1 i 1 "C" t.append("D") t.append t append "D" t.append("B") t.append t append "B" if not i == 0:
            if not s[i - 1] == "B":
                t.append("C") not i == 0 i == 0 i 0 if not s[i - 1] == "B":
                t.append("C") not s[i - 1] == "B" s[i - 1] == "B" s[i - 1] s i - 1 i 1 "B" t.append("C") t.append t append "C" t = "".join(t).split("B") t "".join(t).split("B") "".join(t).split "".join(t) "".join "" join t split "B" for u in range(len(t)):
    t[u] = t[u].split("C") u range(len(t)) range len(t) len t t[u] = t[u].split("C") t[u] t u t[u].split("C") [u].split [u] t u split "C" ans = 0 ans 0 for u in t:
    for v in u:
        dcnt = 0
        v = list(v)
        for i in range(len(v)):
            if v[i] == "D":
                ans += (i - dcnt)
                dcnt += 1 u t for v in u:
        dcnt = 0
        v = list(v)
        for i in range(len(v)):
            if v[i] == "D":
                ans += (i - dcnt)
                dcnt += 1 v u dcnt = 0 dcnt 0 v = list(v) v list(v) list v for i in range(len(v)):
            if v[i] == "D":
                ans += (i - dcnt)
                dcnt += 1 i range(len(v)) range len(v) len v if v[i] == "D":
                ans += (i - dcnt)
                dcnt += 1 v[i] == "D" v[i] v i "D" ans += (i - dcnt) ans i - dcnt i dcnt dcnt += 1 dcnt 1 print(ans) print ans dcnt += 1 1 dcnt t = "".join(t).split("B") "".join(t).split("B") t ans = 0 0 ans ans += (i - dcnt) i - dcnt ans v = list(v) list(v) v t = [] [] t ls = len(s) len(s) ls dcnt = 0 0 dcnt s = list(input()) list(input()) s
s = list(input())
t = []
ls = len(s)
for i in range(ls):
    if s[i] == "A":
        t.append("A")
    elif s[i] == "B":
        if not i == ls - 1:
            if s[i + 1] == "C":
                t.append("D")
            else:
                t.append("B")
    else:
        if not i == 0:
            if not s[i - 1] == "B":
                t.append("C")
t = "".join(t).split("B")
for u in range(len(t)):
    t[u] = t[u].split("C")
ans = 0
for u in t:
    for v in u:
        dcnt = 0
        v = list(v)
        for i in range(len(v)):
            if v[i] == "D":
                ans += (i - dcnt)
                dcnt += 1
print(ans)