class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.k_init = 2 ** (self.n - 1).bit_length()

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i


def get_invnum(li):
    n = len(li)
    t = FenwickTree(2)
    res = 0
    for i in range(n):
        if li[i] == "A":
            t.add(2, 1)
        else:
            res += t.sum(2)
    return res


S = input()
S = list(S.replace("BC", "D"))
N = len(S)
li = []
ans = 0
for c in S + ["B"]:
    if c not in ("A", "D"):
        ans += get_invnum(li)
        li = []
    else:
        li.append(c)
print(ans) class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.k_init = 2 ** (self.n - 1).bit_length()

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i FenwickTree def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.k_init = 2 ** (self.n - 1).bit_length()

     __init__ self.n = n self.n self n n self.data = [0] * (n + 1) self.data self data [0] * (n + 1) [0] 0 n + 1 n 1 self.k_init = 2 ** (self.n - 1).bit_length() self.k_init self k_init 2 ** (self.n - 1).bit_length() 2 (self.n - 1).bit_length() self.n - 1).bit_length self.n - 1 self.n self n 1 bit_length self self n n def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

     sum s = 0 s 0 while i > 0:
            s += self.data[i]
            i -= i & -i
         i > 0 i 0 s += self.data[i] s self.data[i] self.data self data i i -= i & -i i i & -i i -i i return s s self self i i def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i add while i <= self.n:
            self.data[i] += x
            i += i & -i i <= self.n i self.n self n self.data[i] += x self.data[i] self.data self data i x i += i & -i i i & -i i -i i self self i i x x def get_invnum(li):
    n = len(li)
    t = FenwickTree(2)
    res = 0
    for i in range(n):
        if li[i] == "A":
            t.add(2, 1)
        else:
            res += t.sum(2)
    return res get_invnum n = len(li) n len(li) len li t = FenwickTree(2) t FenwickTree(2) FenwickTree 2 res = 0 res 0 for i in range(n):
        if li[i] == "A":
            t.add(2, 1)
        else:
            res += t.sum(2)
     i range(n) range n if li[i] == "A":
            t.add(2, 1)
        else:
            res += t.sum(2)
     li[i] == "A" li[i] li i "A" t.add(2, 1) t.add t add 2 1 res += t.sum(2) res t.sum(2) t.sum t sum 2 return res res li li S = input() S input() input S = list(S.replace("BC", "D")) S list(S.replace("BC", "D")) list S.replace("BC", "D") S.replace S replace "BC" "D" N = len(S) N len(S) len S li = [] li [] ans = 0 ans 0 for c in S + ["B"]:
    if c not in ("A", "D"):
        ans += get_invnum(li)
        li = []
    else:
        li.append(c) c S + ["B"] S ["B"] "B" if c not in ("A", "D"):
        ans += get_invnum(li)
        li = []
    else:
        li.append(c) c not in ("A", "D") c ("A", "D") "A" "D" ans += get_invnum(li) ans get_invnum(li) get_invnum li li = [] li [] li.append(c) li.append li append c print(ans) print ans S = input() input() S N = len(S) len(S) N ans = 0 0 ans ans += get_invnum(li) get_invnum(li) ans li = [] [] li class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.k_init = 2 ** (self.n - 1).bit_length()

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.k_init = 2 ** (self.n - 1).bit_length()

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i FenwickTree S = list(S.replace("BC", "D")) list(S.replace("BC", "D")) S def get_invnum(li):
    n = len(li)
    t = FenwickTree(2)
    res = 0
    for i in range(n):
        if li[i] == "A":
            t.add(2, 1)
        else:
            res += t.sum(2)
    return res def get_invnum(li):
    n = len(li)
    t = FenwickTree(2)
    res = 0
    for i in range(n):
        if li[i] == "A":
            t.add(2, 1)
        else:
            res += t.sum(2)
    return res get_invnum li = [] [] li
class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.k_init = 2 ** (self.n - 1).bit_length()

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i


def get_invnum(li):
    n = len(li)
    t = FenwickTree(2)
    res = 0
    for i in range(n):
        if li[i] == "A":
            t.add(2, 1)
        else:
            res += t.sum(2)
    return res


S = input()
S = list(S.replace("BC", "D"))
N = len(S)
li = []
ans = 0
for c in S + ["B"]:
    if c not in ("A", "D"):
        ans += get_invnum(li)
        li = []
    else:
        li.append(c)
print(ans)
