Buggy python submission (verdict: Runtime Error):
s=input()
s+="Z"
S=""
F=0
for i in range(len(s)):
    if F==0:
        if s[i]=="B":
            F=1
        else:
            S+=s[i]
    else:
        if s[i]=="C":
            S+="D"
            F=0
        elif s[i]=="B":
            S+="B"
        else:
            S+=s[i]
            F=0
if S[len(S)-1]=="Z":
    S=S[:len(S)-1]
#print(S)
S=S[::-1]
L=[]
if S[0]=="D":
    L.append(1)
else:
    L.append(0)
for i in range(1,len(S)):
    if S[i]=="D":
        L.append(L[i-1]+1)
    elif S[i]=="A":
        L.append(L[i-1])
    else:
        L.append(0)
L=L[::-1]
S=S[::-1]
#print(S)
#print(L)
ANS=0
for i in range(len(S)):
    if S[i]=="A":
        ANS+=L[i]
print(ANS)
        

Fixed submission:
s=input()

S=[s[0]]

for i in range(1,len(s)):
    if S[len(S)-1]=="B" and s[i]=="C":
        S[len(S)-1]="D"
    else:
        S.append(s[i])
#print(S)

L=[]
if S[len(S)-1]=="D":
    L.append(1)
else:
    L.append(0)
    
for i in range(1,len(S)):
    if S[len(S)-1-i]=="D":
        L.append(L[len(L)-1]+1)
    elif S[len(S)-1-i]=="A":
        L.append(L[len(L)-1])
    else:
        L.append(0)
L=L[::-1]
#print(L)
ANS=0
for i in range(len(S)):
    if S[i]=="A":
        ANS+=L[i]
print(ANS)

Buggy python submission (verdict: Runtime Error):
s=input()
s+="Z"
S=""
F=0
for i in range(len(s)):
    if F==0:
        if s[i]=="B":
            F=1
        else:
            S+=s[i]
    else:
        if s[i]=="C":
            S+="D"
            F=0
        elif s[i]=="B":
            S+="B"
        else:
            S+=s[i]
            F=0
if S[len(S)-1]=="Z":
    S=S[:len(S)-1]
#print(S)
S=S[::-1]
L=[]
if S[0]=="D":
    L.append(1)
else:
    L.append(0)
for i in range(1,len(S)):
    if S[i]=="D":
        L.append(L[i-1]+1)
    elif S[i]=="A":
        L.append(L[i-1])
    else:
        L.append(0)
L=L[::-1]
S=S[::-1]
#print(S)
#print(L)
ANS=0
for i in range(len(S)):
    if S[i]=="A":
        ANS+=L[i]
print(ANS)
        

Fixed submission:
s=input()

S=[s[0]]

for i in range(1,len(s)):
    if S[len(S)-1]=="B" and s[i]=="C":
        S[len(S)-1]="D"
    else:
        S.append(s[i])
#print(S)

L=[]
if S[len(S)-1]=="D":
    L.append(1)
else:
    L.append(0)
    
for i in range(1,len(S)):
    if S[len(S)-1-i]=="D":
        L.append(L[len(L)-1]+1)
    elif S[len(S)-1-i]=="A":
        L.append(L[len(L)-1])
    else:
        L.append(0)
L=L[::-1]
#print(L)
ANS=0
for i in range(len(S)):
    if S[i]=="A":
        ANS+=L[i]
print(ANS)

Buggy python submission (verdict: Runtime Error):
s=input()
s+="Z"
S=""
F=0
for i in range(len(s)):
    if F==0:
        if s[i]=="B":
            F=1
        else:
            S+=s[i]
    else:
        if s[i]=="C":
            S+="D"
            F=0
        elif s[i]=="B":
            S+="B"
        else:
            S+=s[i]
            F=0
S=S[:len(S)-1]
#print(S)
S=S[::-1]
L=[]
if S[0]=="D":
    L.append(1)
else:
    L.append(0)
for i in range(1,len(S)):
    if S[i]=="D":
        L.append(L[i-1]+1)
    elif S[i]=="A":
        L.append(L[i-1])
    else:
        L.append(0)
L=L[::-1]
S=S[::-1]
#print(S)
#print(L)
ANS=0
for i in range(len(S)):
    if S[i]=="A":
        ANS+=L[i]
print(ANS)
        

Fixed submission:
s=input()

S=[s[0]]

for i in range(1,len(s)):
    if S[len(S)-1]=="B" and s[i]=="C":
        S[len(S)-1]="D"
    else:
        S.append(s[i])
#print(S)

L=[]
if S[len(S)-1]=="D":
    L.append(1)
else:
    L.append(0)
    
for i in range(1,len(S)):
    if S[len(S)-1-i]=="D":
        L.append(L[len(L)-1]+1)
    elif S[len(S)-1-i]=="A":
        L.append(L[len(L)-1])
    else:
        L.append(0)
L=L[::-1]
#print(L)
ANS=0
for i in range(len(S)):
    if S[i]=="A":
        ANS+=L[i]
print(ANS)