def main():
    S = input()
    # BC -> D に変換
    #     ABCACCBABCBCAABCB -> ADACCBADDAADB
    # 後ろから順にみてDからスタートしてB/Cが出てきたら区切る
    #     AD (ACCB) ADDAAD (B)
    # 各セクションでAの右側にあるDの数を足し合わせる
    #     1 + 3 + 1 + 1 = 6
    T = list()
    for ch in S:
        if len(T) > 0 and T[-1] == 'B' and ch == 'C':
            T[-1] = 'D'
            continue
        T.append(ch)
    T.reverse()
    ans, cnt_d = 0, 0
    for ch in T:
        if ch == 'A':
            ans += cnt_d
        elif ch in ['B', 'C']:
            cnt_d = 0
        else:  # ch == 'D'
            cnt_d += 1
    print(ans)


if __name__ == '__main__':
    main() def main():
    S = input()
    # BC -> D に変換
    #     ABCACCBABCBCAABCB -> ADACCBADDAADB
    # 後ろから順にみてDからスタートしてB/Cが出てきたら区切る
    #     AD (ACCB) ADDAAD (B)
    # 各セクションでAの右側にあるDの数を足し合わせる
    #     1 + 3 + 1 + 1 = 6
    T = list()
    for ch in S:
        if len(T) > 0 and T[-1] == 'B' and ch == 'C':
            T[-1] = 'D'
            continue
        T.append(ch)
    T.reverse()
    ans, cnt_d = 0, 0
    for ch in T:
        if ch == 'A':
            ans += cnt_d
        elif ch in ['B', 'C']:
            cnt_d = 0
        else:  # ch == 'D'
            cnt_d += 1
    print(ans) main S = input() S input() input T = list() T list() list for ch in S:
        if len(T) > 0 and T[-1] == 'B' and ch == 'C':
            T[-1] = 'D'
            continue
        T.append(ch)
     ch S if len(T) > 0 and T[-1] == 'B' and ch == 'C':
            T[-1] = 'D'
            continue
         len(T) > 0 and T[-1] == 'B' and ch == 'C' len(T) > 0 and T[-1] == 'B' len(T) > 0 len(T) len T 0 T[-1] == 'B' T[-1] T -1 'B' ch == 'C' ch 'C' T[-1] = 'D' T[-1] T -1 'D' continue T.append(ch) T.append T append ch T.reverse() T.reverse T reverse ans, cnt_d = 0, 0 ans 0 cnt_d 0 for ch in T:
        if ch == 'A':
            ans += cnt_d
        elif ch in ['B', 'C']:
            cnt_d = 0
        else:  # ch == 'D'
            cnt_d += 1
     ch T if ch == 'A':
            ans += cnt_d
        elif ch in ['B', 'C']:
            cnt_d = 0
        else:  # ch == 'D'
            cnt_d += 1
     ch == 'A' ch 'A' ans += cnt_d ans cnt_d elif ch in ['B', 'C']:
            cnt_d = 0
         ch in ['B', 'C'] ch ['B', 'C'] 'B' 'C' cnt_d = 0 cnt_d 0 cnt_d += 1 cnt_d 1 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    S = input()
    # BC -> D に変換
    #     ABCACCBABCBCAABCB -> ADACCBADDAADB
    # 後ろから順にみてDからスタートしてB/Cが出てきたら区切る
    #     AD (ACCB) ADDAAD (B)
    # 各セクションでAの右側にあるDの数を足し合わせる
    #     1 + 3 + 1 + 1 = 6
    T = list()
    for ch in S:
        if len(T) > 0 and T[-1] == 'B' and ch == 'C':
            T[-1] = 'D'
            continue
        T.append(ch)
    T.reverse()
    ans, cnt_d = 0, 0
    for ch in T:
        if ch == 'A':
            ans += cnt_d
        elif ch in ['B', 'C']:
            cnt_d = 0
        else:  # ch == 'D'
            cnt_d += 1
    print(ans) def main():
    S = input()
    # BC -> D に変換
    #     ABCACCBABCBCAABCB -> ADACCBADDAADB
    # 後ろから順にみてDからスタートしてB/Cが出てきたら区切る
    #     AD (ACCB) ADDAAD (B)
    # 各セクションでAの右側にあるDの数を足し合わせる
    #     1 + 3 + 1 + 1 = 6
    T = list()
    for ch in S:
        if len(T) > 0 and T[-1] == 'B' and ch == 'C':
            T[-1] = 'D'
            continue
        T.append(ch)
    T.reverse()
    ans, cnt_d = 0, 0
    for ch in T:
        if ch == 'A':
            ans += cnt_d
        elif ch in ['B', 'C']:
            cnt_d = 0
        else:  # ch == 'D'
            cnt_d += 1
    print(ans) main
def main():
    S = input()
    # BC -> D に変換
    #     ABCACCBABCBCAABCB -> ADACCBADDAADB
    # 後ろから順にみてDからスタートしてB/Cが出てきたら区切る
    #     AD (ACCB) ADDAAD (B)
    # 各セクションでAの右側にあるDの数を足し合わせる
    #     1 + 3 + 1 + 1 = 6
    T = list()
    for ch in S:
        if len(T) > 0 and T[-1] == 'B' and ch == 'C':
            T[-1] = 'D'
            continue
        T.append(ch)
    T.reverse()
    ans, cnt_d = 0, 0
    for ch in T:
        if ch == 'A':
            ans += cnt_d
        elif ch in ['B', 'C']:
            cnt_d = 0
        else:  # ch == 'D'
            cnt_d += 1
    print(ans)


if __name__ == '__main__':
    main()