You are given a string consisting of 'A', 'B', and 'C'. Perform the following operation as many times as possible: Choose a contiguous substring that reads 'ABC' and replace it with 'BCA'. Find the maximum possible number of operations. Constraints: 1 ≤ |s| ≤ 200000, where |s| is the length of the string. Each character of the string is 'A', 'B', or 'C'. Input is given as the string 's'. Output the maximum possible number of operations. Example: Input: ABCABC, Output: 3 (e.g., ABCABC → BCAABC → BCABCA → BCBCAA).

# Buggy version:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()

    # AがBCを乗り越えて右に進むイメージ
    # それぞれのAに対して右側に連続したBCがいくつあるか
    ans = 0
    len_s = len(s)
    for i in range(len_s):
        cnt = 0
        if s[i] == 'A':
            cnt += 1
        elif i + 1 < len_s and s[i] == 'B' and s[i+1] == 'C':
            ans += cnt
        else:
            cnt = 0
            
    print(ans)

if __name__ == '__main__':
    resolve()


# Fixed version:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()

    # AがBCを乗り越えて右に進むイメージ
    # それぞれのAに対して右側に連続したBCがいくつあるか
    ans = 0
    len_s = len(s)
    cnt = 0
    i = 0
    while i < len_s:
        # print(s[i], cnt)
        if s[i] == 'A':
            cnt += 1
            i += 1
        elif i + 1 < len_s and s[i] == 'B' and s[i+1] == 'C':
            ans += cnt
            i += 2
        else:
            cnt = 0
            i += 1
            
    print(ans)

if __name__ == '__main__':
    resolve()

# Buggy version:
s=input()
l=s.replace('BC','D')
a=0
ans=0
for i in range(len(l)):
  if s[i]=='A':
    a+=1
  elif s[i]=='D':
    ans+=a
  else:
    a=0
print(ans)

# Fixed version:
s = input().replace('BC','a')

ans, cnta = 0, 0
for i in range(len(s)):
    if s[i] == 'A':
        cnta += 1
    elif s[i] == 'a':
        ans += cnta
    else:
        cnta = 0
print(ans)

# Buggy version:
s=input()
n=len(s)

cnt=0
ans=0

for i in range(n-2):
    if s[i]=="A":
        cnt+=1
    elif s[i:i+2]=="BC":
        ans+=cnt
    elif i>0 and s[i-1:i+1]=="BC":
        pass
    else:
        cnt=0

print(ans)
    

# Fixed version:
s=input()
n=len(s)

cnt=0
ans=0

for i in range(n-1):
    if s[i]=="A":
        cnt+=1
    elif s[i:i+2]=="BC":
        ans+=cnt
    elif i>0 and s[i-1:i+1]=="BC":
        pass
    else:
        cnt=0

print(ans)

# Buggy version:
def sol(S):
  N = len(S)
  nums = [0 for _ in range(N+1)]
  i = N-1
  while i >= 0:
    if S[i-1:i+1] == 'BC':
      nums[i-1] = nums[i+1] + 1
      nums[i] = nums[i+1] + 1
      i -= 2
    else:
      nums[i] = nums[i+1]
      i -= 1
  ans = 0
  for i, s in enumerate(S):
    if s == 'A':
      ans += nums[i]
  return ans

S = input()
ans = 0
N = len(S)
si, i = 0, 0
while i < N:
  if S[i] == 'A':
    i += 1
  elif S[i:i+2] == 'BC':
    i += 2
  else:
    ans += sol(S[si:i+1])
    si = i + 1
    i += 1
print(ans)

# Fixed version:
def sol(S):
  N = len(S)
  nums = [0 for _ in range(N+1)]
  i = N-1
  while i >= 0:
    if S[i-1:i+1] == 'BC':
      nums[i-1] = nums[i+1] + 1
      nums[i] = nums[i+1] + 1
      i -= 2
    else:
      nums[i] = nums[i+1]
      i -= 1
  ans = 0
  for i, s in enumerate(S):
    if s == 'A':
      ans += nums[i]
  return ans

S = input()
ans = 0
N = len(S)
si, i = 0, 0
while i < N:
  if S[i] == 'A':
    i += 1
  elif S[i:i+2] == 'BC':
    i += 2
  else:
    ans += sol(S[si:i+1])
    si = i + 1
    i += 1
ans += sol(S[si:])
print(ans)

# Buggy version:
s = input()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_bc = 0

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if pos+1 < str_len and s[pos] == "B" and s[pos + 1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos + 1] == "C":
                seq_bc += 1
                pos += 1
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)


# Fixed version:
s = input()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_bc = 0

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if pos + 1 < str_len and s[pos] == "B" and s[pos+1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos+1] == "C":
                seq_bc += 1
                pos += 2
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)

# Buggy version:
s=list(input())
l=[]
f=0
for i in range(len(s)-1):
    if s[i]=="A":
        l.append("A")
        f=0
    elif s[i]=="B":
        if s[i+1]=="C":
            l.append("D")
            f=1
        else:
            l.append("B")
            f=0
    else:
        if f:
            f=0
            continue
        else:
            l.append("C")
ac=0
ans=0
print("".join(l))
for i in range(len(l)):
    if l[i]=="A":
        ac+=1
    elif l[i]=="D":
        ans+=ac
    else:
        ac=0
print(ans)


# Fixed version:
s=list(input())
l=[]
f=0
for i in range(len(s)-1):
    if s[i]=="A":
        l.append("A")
        f=0
    elif s[i]=="B":
        if s[i+1]=="C":
            l.append("D")
            f=1
        else:
            l.append("B")
            f=0
    else:
        if f:
            f=0
            continue
        else:
            l.append("C")
ac=0
ans=0
for i in range(len(l)):
    if l[i]=="A":
        ac+=1
    elif l[i]=="D":
        ans+=ac
    else:
        ac=0
print(ans)

# Buggy version:
s=list(input())
count=0
for i in range(len(s)-3):
    if s[i:i+3]==['A','B','C']:
        count+=1
        s[i]='B'
        s[i+1]='C'
        s[i+2]='A'
        for j in range(1,len(s)):
            if i-j<0:
                break
            if s[i-j]=='A':
                count+=1
                s[i-j]='B'
                s[i-j+1]='C'
                s[i-j+1]='A'
                
            
            else:
                break
        
print(count)


        
    
        

        
    


# Fixed version:
s=list(input())
count=0
count1=0
for i in range(len(s)-2):
    if s[i:i+3]==['A','B','C']:
        count+=1
        s[i]='B'
        s[i+1]='C'
        s[i+2]='A'

            
        for j in range(1,len(s)):
            if i-j<0:
                count+=count1
                break
            if s[i-j]=='A':
                count1+=1
            else:
                count+=count1
                break
            
    if s[i:i+3]==['A','A','A'] or s[i:i+3]==['A','A','B'] or s[i:i+3]==['C','A','A'] or s[i:i+3]==['C','A','B'] or s[i:i+3]==['B','C','A']:
        continue
    else:
        count1=0


print(count)

# Buggy version:
S = input()
idx = 0
a_cnt = 0
cnt = 0
len_s = len(S)
while idx < len_s:
  if S[idx:idx+3] == 'ABC':
    cnt += 1 + a_cnt
    idx += 3
    a_cnt = 0
    bc_cnt = 0
    while idx < len(S):
      if S[idx:idx+2] == 'BC':
        bc_cnt += 1
        idx += 2
      else:
        break
    cnt += bc_cnt
  else:
    if S[idx] == 'A':
      a_cnt += 1
    idx += 1
print(cnt)

# Fixed version:
S = input()
idx = 0
a_cnt = 0
cnt = 0
len_s = len(S)
while idx < len_s:
  if S[idx:idx+3] == 'ABC':
    cnt += 1 + a_cnt
    idx += 3
    a_cnt += 1
    bc_cnt = 0
    while idx < len(S):
      if S[idx:idx+2] == 'BC':
        cnt += a_cnt
        idx += 2
      else:
        break
  else:
    if S[idx] == 'A':
      a_cnt += 1
    else:
      a_cnt = 0
    idx += 1
print(cnt)

# Buggy version:
s = input()
s = s.split('BC')
count = [0]
count_all = 0
Icount = 0

for i in range(0,len(s)-1):
    Icount = 0
    j = 1
    while(j<=len(s[i]) and s[i][-j]=='A'):
        Icount = Icount + 1
        j = j + 1
        
    if (s[i]=='' or s[i]=='A'*len(s[i])):
        Icount = Icount + count[-1]
   
    count.append(Icount)
  
        
count_all = sum(count)  
print(count)
print(count_all)

# Fixed version:
s = input()
s = s.split('BC')
count = [0]
count_all = 0
Icount = 0

for i in range(0,len(s)-1):
    Icount = 0
    j = 1
    while(j<=len(s[i]) and s[i][-j]=='A'):
        Icount = Icount + 1
        j = j + 1
        
    if (s[i]=='' or s[i]=='A'*len(s[i])):
        Icount = Icount + count[-1]
   
    count.append(Icount)
  
        
count_all = sum(count)  
print(count_all)

# Buggy version:
s=list(input())

i=0
j=0
ans=0
z=[]
while i!=len(s)-2:
    try:
        if s[i]=="B" and s[i+1]=="C":
            z.append(1)
            i=i+2

        else:
            if s[i]=="A":
                z.append(2)
                i=i+1

            else:
                z.append(0)
                i=i+1

    except:
      break

ans=0
i=0
r1=0


#print(z)
#ｚ＝判定数列

while i!=len(z):
    if z[i]==2:#"A"
         r1=r1+1

    elif z[i]==1:#"BC"
        ans=ans+r1

    else:#"gomi"
        r1 = 0


    i=i+1
print(ans)

# Fixed version:
s=list(input())

i=0
j=0
ans=0
z=[]
while i!=len(s)-1:
    try:
        if s[i]=="B" and s[i+1]=="C":
            z.append(1)
            i=i+2

        else:
            if s[i]=="A":
                z.append(2)
                i=i+1

            else:
                z.append(0)
                i=i+1

    except:
      break

ans=0
i=0
r1=0


#print(z)
#ｚ＝判定数列

while i!=len(z):
    if z[i]==2:#"A"
         r1=r1+1

    elif z[i]==1:#"BC"
        ans=ans+r1

    else:#"gomi"
        r1 = 0


    i=i+1
print(ans)

# Buggy version:
def f(ss):
  n=len(ss)
  ct,res=0,0
  for i in range(n):
    if ss[i]=="x":
      ct+=1
    else:
      res+=ct
  return res
s=input()
s=s.replace("BC","y")
s=s.replace("A","x")
ans=0
chk=""
for i in range(len(s)):
  if s[i]=="x" or s[i]=="y":
    chk+=s[i]
  else:
    ans+=f(chk)
    chk=""
print(ans)


# Fixed version:
def f(ss):
  n=len(ss)
  ct,res=0,0
  for i in range(n):
    if ss[i]=="x":
      ct+=1
    else:
      res+=ct
  return res
s=input()
s=s.replace("BC","y")
s=s.replace("A","x")
s+="z"
ans=0
chk=""
for i in range(len(s)):
  if s[i]=="x" or s[i]=="y":
    chk+=s[i]
  else:
    ans+=f(chk)
    chk=""
print(ans)

# Buggy version:
s = list(input())

cnt = 0
# print(s, cnt)

i = 0
while i < len(s)-2:
    # print(i)
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        s[i] = 'B'
        s[i+1] = 'C'
        s[i+2] = 'A'
        cnt = cnt + 1
        i = i - 1
        if i < 0:
            i = 0
        print(i, s, cnt)
    else:
        i = i + 1

print(cnt)

# Fixed version:
s = list(input())

cnt = 0
cnA = 0
i = 0
while i < len(s) - 1:
    #print(i, cnA)
    if s[i:i + 2] == ["B", "C"]:
        cnt += cnA
        i += 1
    elif s[i] == "A":
        cnA += 1
    else:
        cnA = 0
    i += 1

print(cnt)

# Buggy version:
s=input()
ans=0
a=[0 for i in range(len(s))]
bc=[0 for i in range(len(s))]
if len(s)<3:
  print(0)
else:
  for i in range(len(s)):
    if s[i]=="A":
      a[i]=1
  for i in range(len(s)-1):
    if s[i]=="B" and s[i+1]=="C":
      bc[i]=1
  for i in range(len(s)-2,-1,-1):
    if bc[i-2]>0:
      bc[i-2]+=bc[i]
      bc[i]=0
  for i in range(len(s)-2):
    if a[i]>0 and bc[i+1]>0:
      a[i+2]=1
  for i in range(len(s)-1):
    if a[i+1]>0:
      a[i+1]+=a[i]
      a[i]=0
  
  for i in range(len(s)-2):
    if a[i]>0 and bc[i+1]>0:
      ans+=a[i]*bc[i+1]
  print(ans)
  

# Fixed version:
s=input()
ans=0
a=[0 for i in range(len(s))]
bc=[0 for i in range(len(s))]
if len(s)<3:
  print(0)
else:
  for i in range(len(s)-2):
    if s[i]=="A":
      a[i]+=1
    if s[i+1]=="B" and s[i+2]=="C":
      a[i+2]+=a[i]
    if s[i+1]=="A":
      a[i+1]+=a[i]
      
  for i in range(len(s)-1):
    if s[i]=="B" and s[i+1]=="C":
      bc[i]=1
  #for i in range(len(s)-1):
   # if a[i+1]>0:
    #  a[i+1]+=a[i]
     # a[i]=0
  #for i in range(len(s)-2):
   # if a[i]>0 and bc[i+1]>0:
    #  a[i+2]=a[i]
  #for i in range(len(s)-2,-1,-1):
   # if bc[i-2]>0:
    #  bc[i-2]+=bc[i]
     # bc[i]=0
  #for i in range(len(s)-1):
   # if a[i+1]>0:
    #  a[i+1]+=a[i]
     # a[i]=0
  
  for i in range(len(s)-2):
    if a[i]>0 and bc[i+1]>0:
      ans+=a[i]*bc[i+1]
  print(ans)

# Buggy version:
	S = list(input())
N = len(S)

ans = 0
flag = 0
ABCflag = 0

i = 0
while i < N-2:

    if S[i]+S[i+1]+S[i+2] == 'ABC':
        ans += 1
        if flag:
            ans += flag
        if ABCflag:
            ans += ABCflag
            ABCflag = 0
        i += 2
        ABCflag += 1

    elif S[i] == 'A':
        flag += 1

    else:
        flag = 0
        if S[i]+S[i+1] == 'BC':
            if ABCflag:
                ans += ABCflag
                ABCflag = 0
            i += 1
        else:
            ABCflag = 0
    i += 1

print(ans)


# Fixed version:
S = list(input())
N = len(S)

ans = 0
flag = 0
ABCflag = 0

i = 0
while i < N-2:

    if S[i]+S[i+1]+S[i+2] == 'ABC':
        if flag:
            ans += flag
        ans += 1
        S[i+2] = 'A'
        i += 1

    elif S[i] == 'A':
        flag += 1

    else:
        flag = 0

    i += 1
print(ans)

# Buggy version:
s = input().rstrip()

concurrent_BC_cnt = 0
old1 = ""
cnt = 0
for tmp in (reversed(s)):
	if tmp == "A"
		if old1 == "B":
			cnt += concurrent_BC_cnt
		else:
			concurrent_BC_cnt = 0
			old1 = "A"
		# if "A" not update old1
	else:
		if tmp == "B" and old1 == "C":
			concurrent_BC_cnt += 1
		elif tmp == "C" and old1 == "B":
			pass
		else:
			concurrent_BC_cnt = 0
			
		old1=tmp
	
print(cnt)

# Fixed version:
s = input().rstrip()

concurrent_BC_cnt = 0
old1 = ""
cnt = 0
for tmp in (reversed(s)):
	if tmp == "A":
		if old1 == "B":
			cnt += concurrent_BC_cnt
		else:
			concurrent_BC_cnt = 0
			old1 = "A"
		# if "A" not update old1
	else:
		if tmp == "B" and old1 == "C":
			concurrent_BC_cnt += 1
		elif tmp == "C" and old1 == "B":
			pass
		else:
			concurrent_BC_cnt = 0
			
		old1=tmp
	
print(cnt)

# Buggy version:
s=input()
a=0
r=0
for i in range(len(s)):
  if s[i]=="A":
    a=a+1
    if s[i+1]=="C":
      a=0
  elif s[i]=="B":
    if s[i+1]=="C":
      r=r+a
    else:
      a=0
print(r)

# Fixed version:
s=input()
a=0
r=0
for i in range(len(s)-1):
  if s[i]=="A":
    a=a+1
    if s[i+1]=="C":
      a=0
  elif s[i]=="B":
    if s[i+1]=="C":
      r=r+a
    else:
      a=0
  elif s[i]=="C":
    if s[i+1]=="C":
      a=0
print(int(r))

# Buggy version:
S = input()

WALL = 0
ACTIVATE = 1
CHANCE, BINGO = 2, 3

nBC = 0
score = 0
state = WALL
for c in reversed(S):
	if c == 'A' and state == BINGO:
		state = ACTIVATE
	elif c == 'B' and state == CHANCE:
		state = BINGO
	elif c == 'C':
		if state == CHANCE:
			nBC = 0
		state = CHANCE
	else:
		state = WALL
	
	if state == WALL:
		nBC = 0
	elif state == ACTIVATE:
		score += nBC
	elif state == BINGO:
		nBC += 1

print(score)


# Fixed version:
S = input()

WALL = 0
ACTIVATE = 1
CHANCE, BINGO = 2, 3

nBC = 0
score = 0
state = WALL
for c in reversed(S):
	if c == 'A' and (state == BINGO or state == ACTIVATE):
		state = ACTIVATE
	elif c == 'B' and state == CHANCE:
		state = BINGO
	elif c == 'C':
		if state == CHANCE:
			nBC = 0
		state = CHANCE
	else:
		state = WALL
	
	if state == WALL:
		nBC = 0
	elif state == ACTIVATE:
		score += nBC
	elif state == BINGO:
		nBC += 1

print(score)