import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def t(S):

    N = len(S)

    a = [0] * (N + 1)
    d = [0] * (N + 1)
    for i in range(N):
        if S[i] == 'A':
            a[i + 1] = 1
        else:
            d[i + 1] = 1

    for i in range(N):
        a[i + 1] += a[i]
        d[i + 1] += d[i]

    ans = 0
    for i in range(1, N):
        if S[i] == 'D':
            ans += a[i]

    return ans


def main():

    S = in_s()
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for ts in S.split():
        ans += t(ts)

    print(ans)


if __name__ == '__main__':
    main() import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline in_n = lambda: int(readline()) in_n lambda: int(readline()) int(readline()) int readline() readline in_nn = lambda: map(int, readline().split()) in_nn lambda: map(int, readline().split()) map(int, readline().split()) map int readline().split() ().split () readline split in_nl = lambda: list(map(int, readline().split())) in_nl lambda: list(map(int, readline().split())) list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split in_na = lambda: map(int, read().split()) in_na lambda: map(int, read().split()) map(int, read().split()) map int read().split() ().split () read split in_s = lambda: readline().rstrip().decode('utf-8') in_s lambda: readline().rstrip().decode('utf-8') readline().rstrip().decode('utf-8') ().rstrip().decode ().rstrip() ().rstrip () readline rstrip decode 'utf-8' def t(S):

    N = len(S)

    a = [0] * (N + 1)
    d = [0] * (N + 1)
    for i in range(N):
        if S[i] == 'A':
            a[i + 1] = 1
        else:
            d[i + 1] = 1

    for i in range(N):
        a[i + 1] += a[i]
        d[i + 1] += d[i]

    ans = 0
    for i in range(1, N):
        if S[i] == 'D':
            ans += a[i]

    return ans t N = len(S) N len(S) len S a = [0] * (N + 1) a [0] * (N + 1) [0] 0 N + 1 N 1 d = [0] * (N + 1) d [0] * (N + 1) [0] 0 N + 1 N 1 for i in range(N):
        if S[i] == 'A':
            a[i + 1] = 1
        else:
            d[i + 1] = 1

     i range(N) range N if S[i] == 'A':
            a[i + 1] = 1
        else:
            d[i + 1] = 1

     S[i] == 'A' S[i] S i 'A' a[i + 1] = 1 a[i + 1] a i + 1 i 1 1 d[i + 1] = 1 d[i + 1] d i + 1 i 1 1 for i in range(N):
        a[i + 1] += a[i]
        d[i + 1] += d[i]

     i range(N) range N a[i + 1] += a[i] a[i + 1] a i + 1 i 1 a[i] a i d[i + 1] += d[i] d[i + 1] d i + 1 i 1 d[i] d i ans = 0 ans 0 for i in range(1, N):
        if S[i] == 'D':
            ans += a[i]

     i range(1, N) range 1 N if S[i] == 'D':
            ans += a[i]

     S[i] == 'D' S[i] S i 'D' ans += a[i] ans a[i] a i return ans ans S S def main():

    S = in_s()
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for ts in S.split():
        ans += t(ts)

    print(ans) main S = in_s() S in_s() in_s S = S.replace('BC', 'D') S S.replace('BC', 'D') S.replace S replace 'BC' 'D' S = S.replace('B', ' ') S S.replace('B', ' ') S.replace S replace 'B' ' ' S = S.replace('C', ' ') S S.replace('C', ' ') S.replace S replace 'C' ' ' ans = 0 ans 0 for ts in S.split():
        ans += t(ts)

     ts S.split() S.split S split ans += t(ts) ans t(ts) t ts print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main in_s = lambda: readline().rstrip().decode('utf-8') lambda: readline().rstrip().decode('utf-8') in_s read = sys.stdin.buffer.read sys.stdin.buffer.read read readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline in_na = lambda: map(int, read().split()) lambda: map(int, read().split()) in_na def main():

    S = in_s()
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for ts in S.split():
        ans += t(ts)

    print(ans) def main():

    S = in_s()
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for ts in S.split():
        ans += t(ts)

    print(ans) main in_n = lambda: int(readline()) lambda: int(readline()) in_n def t(S):

    N = len(S)

    a = [0] * (N + 1)
    d = [0] * (N + 1)
    for i in range(N):
        if S[i] == 'A':
            a[i + 1] = 1
        else:
            d[i + 1] = 1

    for i in range(N):
        a[i + 1] += a[i]
        d[i + 1] += d[i]

    ans = 0
    for i in range(1, N):
        if S[i] == 'D':
            ans += a[i]

    return ans def t(S):

    N = len(S)

    a = [0] * (N + 1)
    d = [0] * (N + 1)
    for i in range(N):
        if S[i] == 'A':
            a[i + 1] = 1
        else:
            d[i + 1] = 1

    for i in range(N):
        a[i + 1] += a[i]
        d[i + 1] += d[i]

    ans = 0
    for i in range(1, N):
        if S[i] == 'D':
            ans += a[i]

    return ans t in_nn = lambda: map(int, readline().split()) lambda: map(int, readline().split()) in_nn in_nl = lambda: list(map(int, readline().split())) lambda: list(map(int, readline().split())) in_nl
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def t(S):

    N = len(S)

    a = [0] * (N + 1)
    d = [0] * (N + 1)
    for i in range(N):
        if S[i] == 'A':
            a[i + 1] = 1
        else:
            d[i + 1] = 1

    for i in range(N):
        a[i + 1] += a[i]
        d[i + 1] += d[i]

    ans = 0
    for i in range(1, N):
        if S[i] == 'D':
            ans += a[i]

    return ans


def main():

    S = in_s()
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for ts in S.split():
        ans += t(ts)

    print(ans)


if __name__ == '__main__':
    main()
