s = input()
pos = 0
cnt = 0
acnt = 0
if len(s) < 3:
    print(0)
else:
    while(True):
        if s[pos:pos+2] == "BC" and acnt > 0:
            pos += 2
            cnt += acnt
            # print(s, s[pos:pos+2], cnt, pos)
        else:
            if s[pos] == "A":
                acnt += 1
            else:
                acnt = 0
            pos += 1
        if pos >= len(s)-1:
            break
    print(cnt)
 s = input() s input() input pos = 0 pos 0 cnt = 0 cnt 0 acnt = 0 acnt 0 if len(s) < 3:
    print(0)
else:
    while(True):
        if s[pos:pos+2] == "BC" and acnt > 0:
            pos += 2
            cnt += acnt
            # print(s, s[pos:pos+2], cnt, pos)
        else:
            if s[pos] == "A":
                acnt += 1
            else:
                acnt = 0
            pos += 1
        if pos >= len(s)-1:
            break
    print(cnt) len(s) < 3 len(s) len s 3 print(0) print 0 while(True):
        if s[pos:pos+2] == "BC" and acnt > 0:
            pos += 2
            cnt += acnt
            # print(s, s[pos:pos+2], cnt, pos)
        else:
            if s[pos] == "A":
                acnt += 1
            else:
                acnt = 0
            pos += 1
        if pos >= len(s)-1:
            break
     True if s[pos:pos+2] == "BC" and acnt > 0:
            pos += 2
            cnt += acnt
            # print(s, s[pos:pos+2], cnt, pos)
        else:
            if s[pos] == "A":
                acnt += 1
            else:
                acnt = 0
            pos += 1
         s[pos:pos+2] == "BC" and acnt > 0 s[pos:pos+2] == "BC" s[pos:pos+2] s pos:pos+2 pos pos+2 pos 2 "BC" acnt > 0 acnt 0 pos += 2 pos 2 cnt += acnt cnt acnt if s[pos] == "A":
                acnt += 1
            else:
                acnt = 0
             s[pos] == "A" s[pos] s pos "A" acnt += 1 acnt 1 acnt = 0 acnt 0 pos += 1 pos 1 if pos >= len(s)-1:
            break
     pos >= len(s)-1 pos len(s)-1 len(s) len s 1 break print(cnt) print cnt pos += 2 2 pos pos += 1 1 pos s = input() input() s pos = 0 0 pos acnt += 1 1 acnt acnt = 0 0 acnt acnt = 0 0 acnt cnt = 0 0 cnt cnt += acnt acnt cnt
s = input()
pos = 0
cnt = 0
acnt = 0
if len(s) < 3:
    print(0)
else:
    while(True):
        if s[pos:pos+2] == "BC" and acnt > 0:
            pos += 2
            cnt += acnt
            # print(s, s[pos:pos+2], cnt, pos)
        else:
            if s[pos] == "A":
                acnt += 1
            else:
                acnt = 0
            pos += 1
        if pos >= len(s)-1:
            break
    print(cnt)

