Buggy python submission (verdict: Time Limit Exceeded):
s=list(map(ord,list(input())))

c=0
for i in range(len(s)):
    if s[i:i+3]==[65,66,67]:
        j=1
        ci=1
        while s[i-j]==65:
            ci+=1
            j+=1
            if i-j<0:
                break
        s[i-j+1]=66
        s[i-j+2]=67
        s[i-j+3:i+3]=[65 for i in range(j)]
        c+=ci        

print(c)


Fixed submission:
s=input()

s=s.replace("BC","D")

count=0

c=0
while c<len(s):
    if s[c]=="A" or s[c]=="D":
        d=c
        while s[d]=="A" or s[d]=="D":
            d+=1
            if d==len(s):
                break
        an=0
        for i in range(c,d):
            if s[i]=="A":
                an+=1
            else:
                count+=an
        c=d
    else:
        c+=1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())

c=0
for i in range(len(s)):
    if s[i:i+3]==["A","B","C"]:
        j=1
        ci=1
        while s[i-j]=="A":
            ci+=1
            j+=1
            if i-j<0:
                break
        s[i-j+1]="B"
        s[i-j+2]="C"
        s[i-j+3:i+3]=["A" for i in range(j)]
        c+=ci        

print(c)


Fixed submission:
s=input()

s=s.replace("BC","D")

count=0

c=0
while c<len(s):
    if s[c]=="A" or s[c]=="D":
        d=c
        while s[d]=="A" or s[d]=="D":
            d+=1
            if d==len(s):
                break
        an=0
        for i in range(c,d):
            if s[i]=="A":
                an+=1
            else:
                count+=an
        c=d
    else:
        c+=1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())

c=0
for i in range(len(s)):
    if s[i:i+3]==["A","B","C"]:
        j=1
        ci=1
        while s[i-j]=="A":
            ci+=1
            j+=1
            if i-j<0:
                break
        s[i-j+1]="B"
        s[i-j+2]="C"
        s[i-j+3:i+3]=["A" for i in range(j)]
        c+=ci        

print(c)

Fixed submission:
s=input()

s=s.replace("BC","D")

count=0

c=0
while c<len(s):
    if s[c]=="A" or s[c]=="D":
        d=c
        while s[d]=="A" or s[d]=="D":
            d+=1
            if d==len(s):
                break
        an=0
        for i in range(c,d):
            if s[i]=="A":
                an+=1
            else:
                count+=an
        c=d
    else:
        c+=1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())

c=0
for i in range(len(s)):
    j=i
    while s[j:j+3]==["A","B","C"]:
        s[j:j+3]=["B","C","A"]
        c+=1
        j-=1
        if j==-1:
            break

print(c)

Fixed submission:
s=input()

s=s.replace("BC","D")

count=0

c=0
while c<len(s):
    if s[c]=="A" or s[c]=="D":
        d=c
        while s[d]=="A" or s[d]=="D":
            d+=1
            if d==len(s):
                break
        an=0
        for i in range(c,d):
            if s[i]=="A":
                an+=1
            else:
                count+=an
        c=d
    else:
        c+=1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())

c=0
for i in range(len(s)):
    j=i
    while s[j:j+3]==["A","B","C"]:
        s[j:j+3]=["B","C","A"]
        c+=1
        j-=1
        if j==-1:
            break

print(c)


Fixed submission:
s=input()

s=s.replace("BC","D")

count=0

c=0
while c<len(s):
    if s[c]=="A" or s[c]=="D":
        d=c
        while s[d]=="A" or s[d]=="D":
            d+=1
            if d==len(s):
                break
        an=0
        for i in range(c,d):
            if s[i]=="A":
                an+=1
            else:
                count+=an
        c=d
    else:
        c+=1

print(count)