s = input()
ind = 0
len_s = len(s)
string = ""
cnt = 0
ans = 0
while ind < len_s:
    _s = s[ind]
    if _s == "A":
        cnt += 1
        ind += 1
    elif _s == "B" and ind + 1 < len_s and s[ind + 1] == "C":
        ind += 2
        ans += cnt
    else:
        cnt = 0
        ind += 1

print(ans) s = input() s input() input ind = 0 ind 0 len_s = len(s) len_s len(s) len s string = "" string "" cnt = 0 cnt 0 ans = 0 ans 0 while ind < len_s:
    _s = s[ind]
    if _s == "A":
        cnt += 1
        ind += 1
    elif _s == "B" and ind + 1 < len_s and s[ind + 1] == "C":
        ind += 2
        ans += cnt
    else:
        cnt = 0
        ind += 1 ind < len_s ind len_s _s = s[ind] _s s[ind] s ind if _s == "A":
        cnt += 1
        ind += 1
    elif _s == "B" and ind + 1 < len_s and s[ind + 1] == "C":
        ind += 2
        ans += cnt
    else:
        cnt = 0
        ind += 1 _s == "A" _s "A" cnt += 1 cnt 1 ind += 1 ind 1 elif _s == "B" and ind + 1 < len_s and s[ind + 1] == "C":
        ind += 2
        ans += cnt
     _s == "B" and ind + 1 < len_s and s[ind + 1] == "C" _s == "B" and ind + 1 < len_s _s == "B" _s "B" ind + 1 < len_s ind + 1 ind 1 len_s s[ind + 1] == "C" s[ind + 1] s ind + 1 ind 1 "C" ind += 2 ind 2 ans += cnt ans cnt cnt = 0 cnt 0 ind += 1 ind 1 print(ans) print ans cnt = 0 0 cnt s = input() input() s ind += 2 2 ind _s = s[ind] s[ind] _s ind = 0 0 ind string = "" "" string cnt += 1 1 cnt cnt = 0 0 cnt len_s = len(s) len(s) len_s ans += cnt cnt ans ind += 1 1 ind ans = 0 0 ans ind += 1 1 ind
s = input()
ind = 0
len_s = len(s)
string = ""
cnt = 0
ans = 0
while ind < len_s:
    _s = s[ind]
    if _s == "A":
        cnt += 1
        ind += 1
    elif _s == "B" and ind + 1 < len_s and s[ind + 1] == "C":
        ind += 2
        ans += cnt
    else:
        cnt = 0
        ind += 1

print(ans)