s = input()
ans = 0
L = []
flag = False
for i in range(len(s)):
    if not flag:
        if i != len(s)-1 and s[i] == 'B':
            flag = True
        else:
            L.append(s[i])
    else:
        if s[i] == 'C':
            L.append('D')
        else:
            L.append('B')
            L.append(s[i])
        flag = False
new = []
num = []
flag = False
L.append('B')
for i in range(len(L)):
    if L[i] == 'A' and flag == False:
        setnum = 1
        flag = True
        cur = ['A']
    else:
        if flag == False:
            None
        else:
            if L[i] == 'B' or L[i] == 'C':
                flag = False
                new.append(cur)
                num.append(setnum)
            else:
                if L[i] == 'A':
                    cur.append('A')
                    setnum += 1
                else:
                    cur.append('D')
for i in range(len(new)):
    T = new[i]
    add = num[i]
    cur = 0
    for j in range(len(T)):
        if T[len(T)-j-1] == 'D':
            cur += add
        else:
            add -= 1
    ans += cur
print(ans) s = input() s input() input ans = 0 ans 0 L = [] L [] flag = False flag False for i in range(len(s)):
    if not flag:
        if i != len(s)-1 and s[i] == 'B':
            flag = True
        else:
            L.append(s[i])
    else:
        if s[i] == 'C':
            L.append('D')
        else:
            L.append('B')
            L.append(s[i])
        flag = False i range(len(s)) range len(s) len s if not flag:
        if i != len(s)-1 and s[i] == 'B':
            flag = True
        else:
            L.append(s[i])
    else:
        if s[i] == 'C':
            L.append('D')
        else:
            L.append('B')
            L.append(s[i])
        flag = False not flag flag if i != len(s)-1 and s[i] == 'B':
            flag = True
        else:
            L.append(s[i])
     i != len(s)-1 and s[i] == 'B' i != len(s)-1 i len(s)-1 len(s) len s 1 s[i] == 'B' s[i] s i 'B' flag = True flag True L.append(s[i]) L.append L append s[i] s i if s[i] == 'C':
            L.append('D')
        else:
            L.append('B')
            L.append(s[i])
         s[i] == 'C' s[i] s i 'C' L.append('D') L.append L append 'D' L.append('B') L.append L append 'B' L.append(s[i]) L.append L append s[i] s i flag = False flag False new = [] new [] num = [] num [] flag = False flag False L.append('B') L.append L append 'B' for i in range(len(L)):
    if L[i] == 'A' and flag == False:
        setnum = 1
        flag = True
        cur = ['A']
    else:
        if flag == False:
            None
        else:
            if L[i] == 'B' or L[i] == 'C':
                flag = False
                new.append(cur)
                num.append(setnum)
            else:
                if L[i] == 'A':
                    cur.append('A')
                    setnum += 1
                else:
                    cur.append('D') i range(len(L)) range len(L) len L if L[i] == 'A' and flag == False:
        setnum = 1
        flag = True
        cur = ['A']
    else:
        if flag == False:
            None
        else:
            if L[i] == 'B' or L[i] == 'C':
                flag = False
                new.append(cur)
                num.append(setnum)
            else:
                if L[i] == 'A':
                    cur.append('A')
                    setnum += 1
                else:
                    cur.append('D') L[i] == 'A' and flag == False L[i] == 'A' L[i] L i 'A' flag == False flag False setnum = 1 setnum 1 flag = True flag True cur = ['A'] cur ['A'] 'A' if flag == False:
            None
        else:
            if L[i] == 'B' or L[i] == 'C':
                flag = False
                new.append(cur)
                num.append(setnum)
            else:
                if L[i] == 'A':
                    cur.append('A')
                    setnum += 1
                else:
                    cur.append('D') flag == False flag False None if L[i] == 'B' or L[i] == 'C':
                flag = False
                new.append(cur)
                num.append(setnum)
            else:
                if L[i] == 'A':
                    cur.append('A')
                    setnum += 1
                else:
                    cur.append('D') L[i] == 'B' or L[i] == 'C' L[i] == 'B' L[i] L i 'B' L[i] == 'C' L[i] L i 'C' flag = False flag False new.append(cur) new.append new append cur num.append(setnum) num.append num append setnum if L[i] == 'A':
                    cur.append('A')
                    setnum += 1
                else:
                    cur.append('D') L[i] == 'A' L[i] L i 'A' cur.append('A') cur.append cur append 'A' setnum += 1 setnum 1 cur.append('D') cur.append cur append 'D' for i in range(len(new)):
    T = new[i]
    add = num[i]
    cur = 0
    for j in range(len(T)):
        if T[len(T)-j-1] == 'D':
            cur += add
        else:
            add -= 1
    ans += cur i range(len(new)) range len(new) len new T = new[i] T new[i] new i add = num[i] add num[i] num i cur = 0 cur 0 for j in range(len(T)):
        if T[len(T)-j-1] == 'D':
            cur += add
        else:
            add -= 1
     j range(len(T)) range len(T) len T if T[len(T)-j-1] == 'D':
            cur += add
        else:
            add -= 1
     T[len(T)-j-1] == 'D' T[len(T)-j-1] T len(T)-j-1 len(T)-j len(T) len T j 1 'D' cur += add cur add add -= 1 add 1 ans += cur ans cur print(ans) print ans num = [] [] num setnum += 1 1 setnum T = new[i] new[i] T cur += add add cur flag = False False flag ans += cur cur ans flag = False False flag flag = True True flag L = [] [] L new = [] [] new cur = 0 0 cur flag = True True flag s = input() input() s add -= 1 1 add add = num[i] num[i] add setnum = 1 1 setnum cur = ['A'] ['A'] cur flag = False False flag ans = 0 0 ans flag = False False flag
s = input()
ans = 0
L = []
flag = False
for i in range(len(s)):
    if not flag:
        if i != len(s)-1 and s[i] == 'B':
            flag = True
        else:
            L.append(s[i])
    else:
        if s[i] == 'C':
            L.append('D')
        else:
            L.append('B')
            L.append(s[i])
        flag = False
new = []
num = []
flag = False
L.append('B')
for i in range(len(L)):
    if L[i] == 'A' and flag == False:
        setnum = 1
        flag = True
        cur = ['A']
    else:
        if flag == False:
            None
        else:
            if L[i] == 'B' or L[i] == 'C':
                flag = False
                new.append(cur)
                num.append(setnum)
            else:
                if L[i] == 'A':
                    cur.append('A')
                    setnum += 1
                else:
                    cur.append('D')
for i in range(len(new)):
    T = new[i]
    add = num[i]
    cur = 0
    for j in range(len(T)):
        if T[len(T)-j-1] == 'D':
            cur += add
        else:
            add -= 1
    ans += cur
print(ans)
