#!/usr/bin/env python3
##### Binary Indexed Tree #####
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i+1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key])

# 転倒数
def mergecount(A: list):
    if not A:
        return 0
    bit = Bit(max(A) + 1)
    cnt = 0
    for i, a in enumerate(A):
        cnt += i - bit.sum(a+1)
        bit.add(a, 1)
    return cnt

import re
print(sum(mergecount([*map(int, i)]) for i in re.split("[BC]", input().replace("A", "1").replace("BC", "0")))) class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i+1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key])

# 転倒数 Bit def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)

     __init__ self.size = n self.size self size n self.tree = [0]*(n+1) self.tree self tree [0]*(n+1) [0] 0 n+1 n 1 self self n n def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i+1)
            yield csum - psum
            psum = csum
        raise StopIteration()

     __iter__ psum = 0 psum 0 for i in range(self.size):
            csum = self.sum(i+1)
            yield csum - psum
            psum = csum
         i range(self.size) range self.size self size csum = self.sum(i+1) csum self.sum(i+1) self.sum self sum i+1 i 1 yield csum - psum csum - psum csum psum psum = csum psum csum raise StopIteration() StopIteration() StopIteration self self def __str__(self):  # O(nlogn)
        return str(list(self))

     __str__ return str(list(self)) str(list(self)) str list(self) list self self self def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

     sum if not (0 <= i <= self.size): raise ValueError("error!")
         not (0 <= i <= self.size) 0 <= i <= self.size 0 <= i 0 i self.size self size s = 0 s 0 while i>0:
            s += self.tree[i]
            i -= i & -i
         i>0 i 0 s += self.tree[i] s self.tree[i] self.tree self tree i i -= i & -i i i & -i i -i i return s s self self i i def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

     add if not (0 <= i < self.size): raise ValueError("error!")
         not (0 <= i < self.size) 0 <= i < self.size 0 <= i 0 i self.size self size i += 1 i 1 while i <= self.size:
            self.tree[i] += x
            i += i & -i

     i <= self.size i self.size self size self.tree[i] += x self.tree[i] self.tree self tree i x i += i & -i i i & -i i -i i self self i i x x def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

     __getitem__ if not (0 <= key < self.size): raise IndexError("error!")
         not (0 <= key < self.size) 0 <= key < self.size 0 <= key 0 key self.size self size return self.sum(key+1) - self.sum(key) self.sum(key+1) - self.sum(key) self.sum(key+1) self.sum self sum key+1 key 1 self.sum(key) self.sum self sum key self self key key def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key])

# 転倒数 __setitem__ if not (0 <= key < self.size): raise IndexError("error!")
         not (0 <= key < self.size) 0 <= key < self.size 0 <= key 0 key self.size self size self.add(key, value - self[key]) self.add self add key value - self[key] value self[key] self key self self key key value value def mergecount(A: list):
    if not A:
        return 0
    bit = Bit(max(A) + 1)
    cnt = 0
    for i, a in enumerate(A):
        cnt += i - bit.sum(a+1)
        bit.add(a, 1)
    return cnt mergecount if not A:
        return 0
     not A A return 0 0 bit = Bit(max(A) + 1) bit Bit(max(A) + 1) Bit max(A) + 1 max(A) max A 1 cnt = 0 cnt 0 for i, a in enumerate(A):
        cnt += i - bit.sum(a+1)
        bit.add(a, 1)
     i a enumerate(A) enumerate A cnt += i - bit.sum(a+1) cnt i - bit.sum(a+1) i bit.sum(a+1) bit.sum bit sum a+1 a 1 bit.add(a, 1) bit.add bit add a 1 return cnt cnt A: list A import re re print(sum(mergecount([*map(int, i)]) for i in re.split("[BC]", input().replace("A", "1").replace("BC", "0")))) print sum(mergecount([*map(int, i)]) for i in re.split("[BC]", input().replace("A", "1").replace("BC", "0"))) sum mergecount([*map(int, i)]) mergecount [*map(int, i)] *map(int, i) map(int, i) map int i def mergecount(A: list):
    if not A:
        return 0
    bit = Bit(max(A) + 1)
    cnt = 0
    for i, a in enumerate(A):
        cnt += i - bit.sum(a+1)
        bit.add(a, 1)
    return cnt def mergecount(A: list):
    if not A:
        return 0
    bit = Bit(max(A) + 1)
    cnt = 0
    for i, a in enumerate(A):
        cnt += i - bit.sum(a+1)
        bit.add(a, 1)
    return cnt mergecount class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i+1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key])

# 転倒数 class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i+1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key])

# 転倒数 Bit
#!/usr/bin/env python3
##### Binary Indexed Tree #####
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)

    def __iter__(self):
        psum = 0
        for i in range(self.size):
            csum = self.sum(i+1)
            yield csum - psum
            psum = csum
        raise StopIteration()

    def __str__(self):  # O(nlogn)
        return str(list(self))

    def sum(self, i):
        # [0, i) の要素の総和を返す
        if not (0 <= i <= self.size): raise ValueError("error!")
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        if not (0 <= i < self.size): raise ValueError("error!")
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def __getitem__(self, key):
        if not (0 <= key < self.size): raise IndexError("error!")
        return self.sum(key+1) - self.sum(key)

    def __setitem__(self, key, value):
        # 足し算と引き算にはaddを使うべき
        if not (0 <= key < self.size): raise IndexError("error!")
        self.add(key, value - self[key])

# 転倒数
def mergecount(A: list):
    if not A:
        return 0
    bit = Bit(max(A) + 1)
    cnt = 0
    for i, a in enumerate(A):
        cnt += i - bit.sum(a+1)
        bit.add(a, 1)
    return cnt

import re
print(sum(mergecount([*map(int, i)]) for i in re.split("[BC]", input().replace("A", "1").replace("BC", "0"))))