Buggy python submission (verdict: Time Limit Exceeded):
s = input()
 
ans = 0
s = s.replace("BC","D")
 
while "AD" in s:
    cnt = s.count("AD")
    s = s.replace("AD","DA",cnt)
    ans += cnt
    
print(ans)

Fixed submission:
s = input()
 
ans = 0
s = s.replace("BC","D")
cnt_A = 0
 

for i in s:
    if i == "A":
        cnt_A += 1
    elif i == "D":
        ans += cnt_A
    else:
        cnt_A = 0

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
 
ans = 0
s = s.replace("BC","D")
 
while "AD" in s:
    cnt = s.count("AD")
    s = s.replace("AD","DA",cnt)
    ans += cnt
    
print(ans)

Fixed submission:
s = input()
 
ans = 0
s = s.replace("BC","D")
cnt_A = 0
 

for i in s:
    if i == "A":
        cnt_A += 1
    elif i == "D":
        ans += cnt_A
    else:
        cnt_A = 0

print(ans)

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

ans = 0

while "ABC" in s:
    cnt = s.count("ABC")
    s = s.replace("ABC","BCA")
    ans += cnt
    
print(ans)

Fixed submission:
s = input()
 
ans = 0
s = s.replace("BC","D")
cnt_A = 0
 

for i in s:
    if i == "A":
        cnt_A += 1
    elif i == "D":
        ans += cnt_A
    else:
        cnt_A = 0

print(ans)

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

ans = 0

while "ABC" in s:
    cnt = s.count("ABC")
    s = s.replace("ABC","BCA",cnt)
    ans += cnt
    
print(ans)

Fixed submission:
s = input()
 
ans = 0
s = s.replace("BC","D")
cnt_A = 0
 

for i in s:
    if i == "A":
        cnt_A += 1
    elif i == "D":
        ans += cnt_A
    else:
        cnt_A = 0

print(ans)

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

ans = 0

while "ABC" in s:
    cnt = s.count("ABC")
    s = s.replace("ABC","BCA",cnt)
    ans += cnt
    
print(ans)

Fixed submission:
s = input()
 
ans = 0
s = s.replace("BC","D")
cnt_A = 0
 

for i in s:
    if i == "A":
        cnt_A += 1
    elif i == "D":
        ans += cnt_A
    else:
        cnt_A = 0

print(ans)

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

ans = 0

while "ABC" in s:
    s = s.replace("ABC","BCA",1)
    ans += 1
    
print(ans)

Fixed submission:
s = input()
 
ans = 0
s = s.replace("BC","D")
cnt_A = 0
 

for i in s:
    if i == "A":
        cnt_A += 1
    elif i == "D":
        ans += cnt_A
    else:
        cnt_A = 0

print(ans)

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

ans = 0
tmp = 0
length = len(li)
n = 0

while "ABC" in s:
    for i in range(n,length+1):
        if tmp == 0:
            if li[i] == "A":
                tmp += 1
                continue
            else:
                continue
        elif tmp == 1:
            if li[i] == "B":
                tmp += 1
                continue
            elif li[i] == "A":
                continue
            else:
                tmp = 0
                continue
        elif tmp == 2:
            if li[i] == "C":
                li[i] = "A"
                li[i-1] = "C"
                li[i-2] = "B"
                ans += 1
                s = "".join(li)
                tmp = 0
                n = i - 5
                break
            else:
                continue
print(ans)

Fixed submission:
s = input()
 
ans = 0
s = s.replace("BC","D")
cnt_A = 0
 

for i in s:
    if i == "A":
        cnt_A += 1
    elif i == "D":
        ans += cnt_A
    else:
        cnt_A = 0

print(ans)

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

ans = 0
tmp = 0

while "ABC" in s:
    for i in range(len(li)):
        if tmp == 0:
            if li[i] == "A":
                tmp += 1
                continue
            else:
                continue
        elif tmp == 1:
            if li[i] == "B":
                tmp += 1
                continue
            elif li[i] == "A":
                continue
            else:
                tmp = 0
                continue
        elif tmp == 2:
            if li[i] == "C":
                li[i] = "A"
                li[i-1] = "C"
                li[i-2] = "B"
                ans += 1
                s = "".join(li)
                tmp = 0
                break
            else:
                continue
print(ans)

Fixed submission:
s = input()
 
ans = 0
s = s.replace("BC","D")
cnt_A = 0
 

for i in s:
    if i == "A":
        cnt_A += 1
    elif i == "D":
        ans += cnt_A
    else:
        cnt_A = 0

print(ans)