Buggy python submission (verdict: Time Limit Exceeded):
import sys

s =  [0] + [ord(i) for i in sys.stdin.readline()] + [0, 0]

ret = 0
i = 0

while i < len(s) :
    if s[i] == 65 and s[i+1] == 66 and s[i+2] == 67 :
        j = 0
        while s[i-j-1] == 65 :
            s[i-j+1] = 65
            j += 1
        s[i-j+1] = 66

        s[i+2] = 65
        i += 2
        ret += 1 + j
        
    else :
        i += 1

print(ret)


Fixed submission:
s =  list(input())

ret = 0
i = 0
a = 0
bc = 0

while True :
    while i < len(s) and s[i] == 'A' :
        a += 1
        i += 1

    while i < len(s) - 1 and s[i:i+2] == ['B', 'C']  :
        bc += 1
        i += 2

    ret += a * bc

    bc = 0

    if i < len(s) and s[i] != 'A' :
        a = 0
        
    while i < len(s) and s[i] != 'A' :
        i += 1

    if i >= len(s) - 1 :
        break
    

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s =  [0] + [ord(i) for i in sys.stdin.readline()] + [0, 0]

ret = 0
i = 0

while i < len(s) :
    if s[i] == 65 and s[i+1] == 66 and s[i+2] == 67 :
        if s[i - 1] == 65 :
            s[i] += 1
            s[i+1] += 1
            s[i+2] -= 2
            i -= 1
        else :
            s[i+2] -= 2
            i += 2
        ret += 1
        
    else :
        i += 1

print(ret)


Fixed submission:
s =  list(input())

ret = 0
i = 0
a = 0
bc = 0

while True :
    while i < len(s) and s[i] == 'A' :
        a += 1
        i += 1

    while i < len(s) - 1 and s[i:i+2] == ['B', 'C']  :
        bc += 1
        i += 2

    ret += a * bc

    bc = 0

    if i < len(s) and s[i] != 'A' :
        a = 0
        
    while i < len(s) and s[i] != 'A' :
        i += 1

    if i >= len(s) - 1 :
        break
    

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s =  [0] + [ord(i) for i in sys.stdin.readline()] + [0, 0]

ret = 0
i = 0

while i < len(s) :
    if s[i] == 65 and s[i+1] == 66 and s[i+2] == 67 :
        s[i] += 1
        s[i+1] += 1
        s[i+2] -= 2

        ret += 1
        i -= 1
    else :
        i += 1

print(ret)


Fixed submission:
s =  list(input())

ret = 0
i = 0
a = 0
bc = 0

while True :
    while i < len(s) and s[i] == 'A' :
        a += 1
        i += 1

    while i < len(s) - 1 and s[i:i+2] == ['B', 'C']  :
        bc += 1
        i += 2

    ret += a * bc

    bc = 0

    if i < len(s) and s[i] != 'A' :
        a = 0
        
    while i < len(s) and s[i] != 'A' :
        i += 1

    if i >= len(s) - 1 :
        break
    

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
s =  [0] + [ord(i) for i in input()]

ret = 0
i = 0

while i < len(s) :
    if s[i:i+3] == [65, 66, 67] :
        s[i:i+3] = [66, 67, 65]
        ret += 1
        i -= 1
    else :
        i += 1

print(ret)

Fixed submission:
s =  list(input())

ret = 0
i = 0
a = 0
bc = 0

while True :
    while i < len(s) and s[i] == 'A' :
        a += 1
        i += 1

    while i < len(s) - 1 and s[i:i+2] == ['B', 'C']  :
        bc += 1
        i += 2

    ret += a * bc

    bc = 0

    if i < len(s) and s[i] != 'A' :
        a = 0
        
    while i < len(s) and s[i] != 'A' :
        i += 1

    if i >= len(s) - 1 :
        break
    

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
s =  ['Z'] + list(input())

ret = 0
i = 0

while i < len(s) :
    if s[i:i+3] == ['A', 'B', 'C'] :
        s[i:i+3] = ['B', 'C', 'A']
        ret += 1
        i -= 1
    else :
        i += 1

print(ret)

Fixed submission:
s =  list(input())

ret = 0
i = 0
a = 0
bc = 0

while True :
    while i < len(s) and s[i] == 'A' :
        a += 1
        i += 1

    while i < len(s) - 1 and s[i:i+2] == ['B', 'C']  :
        bc += 1
        i += 2

    ret += a * bc

    bc = 0

    if i < len(s) and s[i] != 'A' :
        a = 0
        
    while i < len(s) and s[i] != 'A' :
        i += 1

    if i >= len(s) - 1 :
        break
    

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
import re

s =  input()

ret = 0
t = re.subn('ABC', 'BCA', s)

while t[1] :
    ret += t[1]
    t = re.subn('ABC', 'BCA', t[0])

print(ret)

Fixed submission:
s =  list(input())

ret = 0
i = 0
a = 0
bc = 0

while True :
    while i < len(s) and s[i] == 'A' :
        a += 1
        i += 1

    while i < len(s) - 1 and s[i:i+2] == ['B', 'C']  :
        bc += 1
        i += 2

    ret += a * bc

    bc = 0

    if i < len(s) and s[i] != 'A' :
        a = 0
        
    while i < len(s) and s[i] != 'A' :
        i += 1

    if i >= len(s) - 1 :
        break
    

print(ret)

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

ret = 0
while True :
    tmp = 0
    i = 0
    while i < len(s) :
        if s[i:i+3] != ['A', 'B', 'C'] :
            i += 1
            continue
        else :
            s[i:i+3] = ['B', 'C', 'A']
            i += 3
            tmp += 1
    if tmp :
        ret += tmp
    else :
        break

print(ret)

Fixed submission:
s =  list(input())

ret = 0
i = 0
a = 0
bc = 0

while True :
    while i < len(s) and s[i] == 'A' :
        a += 1
        i += 1

    while i < len(s) - 1 and s[i:i+2] == ['B', 'C']  :
        bc += 1
        i += 2

    ret += a * bc

    bc = 0

    if i < len(s) and s[i] != 'A' :
        a = 0
        
    while i < len(s) and s[i] != 'A' :
        i += 1

    if i >= len(s) - 1 :
        break
    

print(ret)

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

ret = 0
while True :
    t = s.count('ABC')

    if t :
        ret += t
        s = s.replace('ABC', 'BCA')
    else :
        break

print(ret)

Fixed submission:
s =  list(input())

ret = 0
i = 0
a = 0
bc = 0

while True :
    while i < len(s) and s[i] == 'A' :
        a += 1
        i += 1

    while i < len(s) - 1 and s[i:i+2] == ['B', 'C']  :
        bc += 1
        i += 2

    ret += a * bc

    bc = 0

    if i < len(s) and s[i] != 'A' :
        a = 0
        
    while i < len(s) and s[i] != 'A' :
        i += 1

    if i >= len(s) - 1 :
        break
    

print(ret)

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

ret = 0
while 'ABC' in s :
    s = s.replace('ABC', 'BCA', 1)
    ret += 1

print(ret)

Fixed submission:
s =  list(input())

ret = 0
i = 0
a = 0
bc = 0

while True :
    while i < len(s) and s[i] == 'A' :
        a += 1
        i += 1

    while i < len(s) - 1 and s[i:i+2] == ['B', 'C']  :
        bc += 1
        i += 2

    ret += a * bc

    bc = 0

    if i < len(s) and s[i] != 'A' :
        a = 0
        
    while i < len(s) and s[i] != 'A' :
        i += 1

    if i >= len(s) - 1 :
        break
    

print(ret)