Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
s=list(input().replace("BC","Z"))
ans=0

def seisan(list):
    count=0
    N=len(list)-1
    for index,content in enumerate(list):
        if content=="A":
            count+=(N-index)
            N-=1
    return count

temp=[]
while s:
    this=s.pop(0)
    if this=="B" or this=="C":
        ans+=seisan(temp)
        temp.clear()
    else:
        temp.append(this)

print(ans+seisan(temp))


Fixed submission:
# coding: utf-8
# Your code here!
s=list(input().replace("BC","Z"))[::-1]
ans=0

def seisan(list):
    count=0
    N=len(list)-1
    for index,content in enumerate(list):
        if content=="A":
            count+=(N-index)
            N-=1
    return count

temp=[]
while s:
    this=s.pop(-1)
    if this=="B" or this=="C":
        ans+=seisan(temp)
        temp.clear()
    else:
        temp.append(this)

print(ans+seisan(temp))
#ちょくだいさん連投ゆるして

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
s=input()
s=list(s.replace('BC','Z'))
ans=0
 
def seisan(list):
    count=0
    N=len(list)-1
    for index,content in enumerate(list):
        if content=="A":
            count+=(N-index)
            N-=1
    return count

temp=[]
while s:
    this=s.pop(0)
    if this=="B" or this=="C":
        ans+=seisan(temp)
        temp.clear()
    else:
        temp.append(this)

print(ans+seisan(temp))


Fixed submission:
# coding: utf-8
# Your code here!
s=list(input().replace("BC","Z"))[::-1]
ans=0

def seisan(list):
    count=0
    N=len(list)-1
    for index,content in enumerate(list):
        if content=="A":
            count+=(N-index)
            N-=1
    return count

temp=[]
while s:
    this=s.pop(-1)
    if this=="B" or this=="C":
        ans+=seisan(temp)
        temp.clear()
    else:
        temp.append(this)

print(ans+seisan(temp))
#ちょくだいさん連投ゆるして

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
s=list(input())

temp=0
ans=0
next="Z"
while s:
    this=s.pop(0)#正直一個前の値をthatに入れてもよかったと思う
    if this == "A":
        temp+=1
    elif this == "B":
        if len(s)==0:#s.popできるか調べる
            break
        next=s.pop(0)
        if next=="C":
            ans+=temp
            s=["A"]*temp+s
        elif next=="A":#ここ繋ぎがうまく作れんかった
            temp=1
            continue
        temp=0
    elif this == "C":#虚無
        temp=0

print(ans)
    
    



Fixed submission:
# coding: utf-8
# Your code here!
s=list(input().replace("BC","Z"))[::-1]
ans=0

def seisan(list):
    count=0
    N=len(list)-1
    for index,content in enumerate(list):
        if content=="A":
            count+=(N-index)
            N-=1
    return count

temp=[]
while s:
    this=s.pop(-1)
    if this=="B" or this=="C":
        ans+=seisan(temp)
        temp.clear()
    else:
        temp.append(this)

print(ans+seisan(temp))
#ちょくだいさん連投ゆるして

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
s=input()

temp=0
ans=0
while s:
    if len(s)>=3:
        if s[0]+s[1]+s[2]=='ABC':#ABCABCをBCBCAAに変換したい
            temp+=1
            del s[0:2]
            continue
    
    ans+=(temp*(temp+1))/2#上の清算をする
    temp=0
    
    s_chi=s.pop(0)
    if s_chi="A":#AABCをBCAAに変換したい
        if 
        temp+=1
    elif s_chi="B":
        if 
    elif s_chi="C":
        


Fixed submission:
# coding: utf-8
# Your code here!
s=list(input().replace("BC","Z"))[::-1]
ans=0

def seisan(list):
    count=0
    N=len(list)-1
    for index,content in enumerate(list):
        if content=="A":
            count+=(N-index)
            N-=1
    return count

temp=[]
while s:
    this=s.pop(-1)
    if this=="B" or this=="C":
        ans+=seisan(temp)
        temp.clear()
    else:
        temp.append(this)

print(ans+seisan(temp))
#ちょくだいさん連投ゆるして