Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=input()
s=s.replace("BC","D")
s=deque(list( s ))
t=deque([]) #
cnt=0

#print(t,s)

while s!=deque([]):
  x=s.popleft()
  if t==deque([]):
    t.append(x)
  else:
    if t[-1]=="A" and x=="D":
      tmp=t.pop()
      s.appendleft(tmp)
      s.appendleft(x)
      cnt += 1
    else:
      t.append(x)
      
#print(t,s)        
print(cnt)

Fixed submission:
from collections import deque

s=input()
s=s.replace("BC","D")
N=len(s)

cnt=0
cntA=0
cntD=0

for i in range(N):
  if s[i]=="A":
    cntA += 1
  elif s[i]=="D":
    cnt += cntA
  else:
    cntA=0
    cntD=0
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=input()
s=s.replace("BC","D")
s=deque(list( s ))
t=deque([]) #
cnt=0

#print(t,s)

while s!=deque([]):
  x=s.popleft()
  if t==deque([]):
    t.append(x)
  else:
    if t[-1]=="A" and x=="D":
      tmp=t.pop()
      s.appendleft(tmp)
      s.appendleft(x)
      cnt += 1
    else:
      t.append(x)
      
#print(t,s)        
print(cnt)

Fixed submission:
from collections import deque

s=input()
s=s.replace("BC","D")
N=len(s)

cnt=0
cntA=0
cntD=0

for i in range(N):
  if s[i]=="A":
    cntA += 1
  elif s[i]=="D":
    cnt += cntA
  else:
    cntA=0
    cntD=0
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=deque(list( input() ))
t=deque([]) #

cnt=0

while s!=deque([]):
  x=s.popleft()
  if len(t)>=2 and x=="C":
    q=t.pop()
    p=t.pop()
    if p=="A" and q=="B":
      cnt += 1
      t.append("B")
      s.appendleft("A")
      s.appendleft("C")
    else:
      t.append(p)
      t.append(q)
      t.append(x)
      
  else:
    t.append(x)
        
#print(t,s)
print(cnt)

Fixed submission:
from collections import deque

s=input()
s=s.replace("BC","D")
N=len(s)

cnt=0
cntA=0
cntD=0

for i in range(N):
  if s[i]=="A":
    cntA += 1
  elif s[i]=="D":
    cnt += cntA
  else:
    cntA=0
    cntD=0
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=deque(list( input() ))
t=deque([]) #

cnt=0

while s!=deque([]):
  x=s.popleft()
  if len(t)>=2 and x=="C":
    q=t.pop()
    p=t.pop()
    if p=="A" and q=="B":
      cnt += 1
      t.append("B")
      s.appendleft("A")
      s.appendleft("C")
    else:
      t.append(p)
      t.append(q)
      t.append(x)
      
  else:
    t.append(x)
        
#print(t,s)
print(cnt)

Fixed submission:
from collections import deque

s=input()
s=s.replace("BC","D")
N=len(s)

cnt=0
cntA=0
cntD=0

for i in range(N):
  if s[i]=="A":
    cntA += 1
  elif s[i]=="D":
    cnt += cntA
  else:
    cntA=0
    cntD=0
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=deque(list( input() ))
t=deque([]) #

cnt=0
while s!=deque([]):
  x=s.popleft()
  if len(t)>=2 and x=="C":
    q=t.pop()
    p=t.pop()
    if p=="A" and q=="B":
      cnt += 1
      s.appendleft("A")
      s.appendleft("C")
      s.appendleft("B")
    else:
      t.append(p)
      t.append(q)
      t.append(x)
      
  else:
    t.append(x)
        
#print(t,s)
print(cnt)

Fixed submission:
from collections import deque

s=input()
s=s.replace("BC","D")
N=len(s)

cnt=0
cntA=0
cntD=0

for i in range(N):
  if s[i]=="A":
    cntA += 1
  elif s[i]=="D":
    cnt += cntA
  else:
    cntA=0
    cntD=0
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=deque(list( input() ))
t=deque([]) #

cnt=0
while s!=deque([]):
  x=s.popleft()
  if len(t)>=2 and x=="C":
    q=t.pop()
    p=t.pop()
    if p=="A" and q=="B":
      cnt += 1
      s.appendleft("A")
      s.appendleft("C")
      s.appendleft("B")
    else:
      t.append(p)
      t.append(q)
      t.append(x)
      
  else:
    t.append(x)
        
#print(t,s)
print(cnt)

Fixed submission:
from collections import deque

s=input()
s=s.replace("BC","D")
N=len(s)

cnt=0
cntA=0
cntD=0

for i in range(N):
  if s[i]=="A":
    cntA += 1
  elif s[i]=="D":
    cnt += cntA
  else:
    cntA=0
    cntD=0
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=deque(list( input() ))
t=deque([]) #

cnt=0
while s!=deque([]):
  x=s.popleft()
  if len(t)>=2 and x=="C":
    if t[-2]=="A" and t[-1]=="B":
      cnt += 1
      t.pop()
      t.pop()
      s.appendleft("A")
      s.appendleft("C")
      s.appendleft("B")
    else:
      t.append(x)
  else:
    t.append(x)
        
#print(t,s)
print(cnt)

Fixed submission:
from collections import deque

s=input()
s=s.replace("BC","D")
N=len(s)

cnt=0
cntA=0
cntD=0

for i in range(N):
  if s[i]=="A":
    cntA += 1
  elif s[i]=="D":
    cnt += cntA
  else:
    cntA=0
    cntD=0
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=deque(list( input() ))
t=deque([]) #

cnt=0
while len(s)>0:
  x=s.popleft()
  if len(t)>=2 and x=="C":
    if t[-2]=="A" and t[-1]=="B":
      cnt += 1
      t.pop()
      t.pop()
      s.appendleft("A")
      s.appendleft("C")
      s.appendleft("B")
    else:
      t.append(x)
  else:
    t.append(x)
        
#print(t,s)
print(cnt)

Fixed submission:
from collections import deque

s=input()
s=s.replace("BC","D")
N=len(s)

cnt=0
cntA=0
cntD=0

for i in range(N):
  if s[i]=="A":
    cntA += 1
  elif s[i]=="D":
    cnt += cntA
  else:
    cntA=0
    cntD=0
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=deque(list( input() ))
t=deque([]) #

#print(t,s)

cnt=0
while len(s)>0:
  x=s.popleft()
  if len(t)>=2 and x=="C":
    if t[-2]=="A" and t[-1]=="B":
      cnt += 1
      t.pop()
      t.pop()
      s.appendleft("A")
      s.appendleft("C")
      s.appendleft("B")
    else:
      t.append(x)
  else:
    t.append(x)
        
#print(t,s)
print(cnt)

Fixed submission:
from collections import deque

s=input()
s=s.replace("BC","D")
N=len(s)

cnt=0
cntA=0
cntD=0

for i in range(N):
  if s[i]=="A":
    cntA += 1
  elif s[i]=="D":
    cnt += cntA
  else:
    cntA=0
    cntD=0
    
print(cnt)