Buggy python submission (verdict: Runtime Error):
s = list(input())
n = len(s)
s = s+['z','z']
mem = []
c = 0
run = 0
i=0
while(i<n):
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
        c+=1
        s[i] = 'B'
        s[i + 1] = 'C'
        s[i + 2] = 'A'
        mem.append(i+2)
        run=1
        i+=3
    else:
        i+=1
        if s[i]=='A':
            mem.append(i)

while(run):
    run = 0
    m = -1
    for i in range(len(mem)):
        idex = mem[i]
        if s[idex] == 'A' and s[idex + 1] == 'B' and s[idex + 2] == 'C' and i>m:
            c += 1
            s[idex] = 'B'
            s[idex + 1] = 'C'
            s[idex + 2] = 'A'
            mem.append(i + 2)
            run = 1
            mem[i]= idex+2
            m=idex+2
print(c)

Fixed submission:
s = input()
s= s.replace('BC','D')
a=0
d=0
ans=0
t=''
for i in range(len(s)):
    if s[i] =='A':
        a+=1
    elif s[i]=='D':
        ans+=a
    else:
        a=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
n = len(s)
s = s+['z','z']
mem = []
c = 0
run = 0
i=0
while(i<n):
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
        c+=1
        s[i] = 'B'
        s[i + 1] = 'C'
        s[i + 2] = 'A'
        mem.append(i+2)
        run=1
        i+=3
    else:
        i+=1
        if s[i]=='A':
            mem.append(i)

while(run):
    run = 0
    m = -1
    for i in range(len(mem)):
        idex = mem[i]
        if s[idex] == 'A' and s[idex + 1] == 'B' and s[idex + 2] == 'C' and i>m:
            c += 1
            s[idex] = 'B'
            s[idex + 1] = 'C'
            s[idex + 2] = 'A'
            mem.append(i + 2)
            run = 1
            mem[i]= idex+2
            m=idex+2
print(c)

Fixed submission:
s = input()
s= s.replace('BC','D')
a=0
d=0
ans=0
t=''
for i in range(len(s)):
    if s[i] =='A':
        a+=1
    elif s[i]=='D':
        ans+=a
    else:
        a=0
print(ans)

Buggy python submission (verdict: Runtime Error):
s = list(input())
n = len(s)
s = s+['z','z']
mem = []
c = 0
run = 0
i=0
while(i<n):
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
        c+=1
        s[i] = 'B'
        s[i + 1] = 'C'
        s[i + 2] = 'A'
        mem.append(i+2)
        run=1
        i+=3
    else:
        i+=1
        if s[i]=='A':
            mem.append(i)

while(run):
    run = 0
    m = -1
    for i in range(len(mem)):
        idex = mem[i]
        if s[idex] == 'A' and s[idex + 1] == 'B' and s[idex + 2] == 'C' and i>m:
            c += 1
            s[idex] = 'B'
            s[idex + 1] = 'C'
            s[idex + 2] = 'A'
            mem.append(i + 2)
            run = 1
            mem[i]= idex+2
            m=idex+2
print(c)

Fixed submission:
s = input()
s= s.replace('BC','D')
a=0
d=0
ans=0
t=''
for i in range(len(s)):
    if s[i] =='A':
        a+=1
    elif s[i]=='D':
        ans+=a
    else:
        a=0
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
n = len(s)
s = s+['z','z']
mem = []
c = 0
run = 0
i=0
while(i<n):
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
        c+=1
        s[i] = 'B'
        s[i + 1] = 'C'
        s[i + 2] = 'A'
        mem.append(i+2)
        run=1
        i+=3
    else:
        i+=1
        if s[i]=='A':
            mem.append(i)

while(run):
    run = 0
    m = -1
    for i in range(len(mem)):
        idex = mem[i]
        if s[idex] == 'A' and s[idex + 1] == 'B' and s[idex + 2] == 'C' and i>m:
            c += 1
            s[idex] = 'B'
            s[idex + 1] = 'C'
            s[idex + 2] = 'A'
            mem.append(i + 2)
            run = 1
            mem[i]= idex+2
            m=idex+2
print(c)

Fixed submission:
s = input()
s= s.replace('BC','D')
a=0
d=0
ans=0
t=''
for i in range(len(s)):
    if s[i] =='A':
        a+=1
    elif s[i]=='D':
        ans+=a
    else:
        a=0
print(ans)

Buggy python submission (verdict: Runtime Error):
s = list(input())
n = len(s)
s = s+['z','z']
mem = []
c = 0
run = 0
i=0
while(i<n):
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
        c+=1
        s[i] = 'B'
        s[i + 1] = 'C'
        s[i + 2] = 'A'
        mem.append(i+2)
        run=1
        i+=3
    else:
        i+=1
        if s[i]=='A':
            mem.append(i)
while(run):
    run = 0
    for i in range(len(mem)):
        idex = mem[i]
        if s[idex] == 'A' and s[idex + 1] == 'B' and s[idex + 2] == 'C':
            c += 1
            s[idex] = 'B'
            s[idex + 1] = 'C'
            s[idex + 2] = 'A'
            mem.append(i + 2)
            run = 1
            mem[i]= idex+2
print(c)

Fixed submission:
s = input()
s= s.replace('BC','D')
a=0
d=0
ans=0
t=''
for i in range(len(s)):
    if s[i] =='A':
        a+=1
    elif s[i]=='D':
        ans+=a
    else:
        a=0
print(ans)