Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    li = []
    li_append = li.append
    is_A = False
    now_state = 0
    for ind,s in enumerate(S):
        if(is_A):
            if(now_state==1):
                now_state = 0
                continue
            else:
                if(s=='A'):
                    li[-1] += 'A'
                elif(S[ind:ind+2]=='BC'):
                    li[-1] += 'B'
                    now_state = 1
                else:
                    is_A = False
        elif(s=='A'):
            is_A = True
            now_state = 0
            li_append('A')
    cnt = 0
    for i in li:
        cntb = i.count('B')
        for ind,s in enumerate(i):
            if(s=='A'):
                cnt += cntb
            elif(s=='B'):
                cntb -= 1
    print(cnt)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    S = input()
    li = []
    li_append = li.append
    is_A = False
    now_state = 0
    for ind,s in enumerate(S):
        if(is_A):
            if(now_state==1):
                now_state = 0
                continue
            else:
                if(s=='A'):
                    li[-1].append(0)
                elif(S[ind:ind+2]=='BC'):
                    li[-1][-1] += 1
                    now_state = 1
                else:
                    is_A = False
        elif(s=='A'):
            is_A = True
            now_state = 0
            li_append([0])
    cnt = 0
    for i in li:
        cnt_b = sum(i)
        for j in i:
            cnt += cnt_b
            cnt_b -= j
            
    print(cnt)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
li = []
is_A = False
now_state = 0
for ind,s in enumerate(S):
    if(is_A):
        if(now_state==1):
            now_state = 0
            continue
        else:
            if(s=='A'):
                li[-1] += 'A'
            elif(S[ind:ind+2]=='BC'):
                li[-1] += 'B'
                now_state = 1
            else:
                is_A = False
    elif(s=='A'):
        is_A = True
        now_state = 0
        li.append('A')
cnt = 0
for i in li:
    for ind,s in enumerate(i):
        if(s=='A'):
            cnt += i[ind+1:].count('B')

print(cnt)


Fixed submission:
def main():
    S = input()
    li = []
    li_append = li.append
    is_A = False
    now_state = 0
    for ind,s in enumerate(S):
        if(is_A):
            if(now_state==1):
                now_state = 0
                continue
            else:
                if(s=='A'):
                    li[-1].append(0)
                elif(S[ind:ind+2]=='BC'):
                    li[-1][-1] += 1
                    now_state = 1
                else:
                    is_A = False
        elif(s=='A'):
            is_A = True
            now_state = 0
            li_append([0])
    cnt = 0
    for i in li:
        cnt_b = sum(i)
        for j in i:
            cnt += cnt_b
            cnt_b -= j
            
    print(cnt)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
li = []
is_A = False
now_state = 0
for ind,s in enumerate(S):
    if(is_A):
        if(now_state==1):
            now_state = 0
            continue
        else:
            if(s=='A'):
                li[-1] += 'A'
            elif(S[ind:ind+2]=='BC'):
                li[-1] += 'B'
                now_state = 1
            else:
                is_A = False
    elif(s=='A'):
        is_A = True
        now_state = 0
        li.append('A')
cnt = 0
for i in li:
    for ind,s in enumerate(i):
        if(s=='A'):
            cnt += i[ind+1:].count('B')

print(cnt)


Fixed submission:
def main():
    S = input()
    li = []
    li_append = li.append
    is_A = False
    now_state = 0
    for ind,s in enumerate(S):
        if(is_A):
            if(now_state==1):
                now_state = 0
                continue
            else:
                if(s=='A'):
                    li[-1].append(0)
                elif(S[ind:ind+2]=='BC'):
                    li[-1][-1] += 1
                    now_state = 1
                else:
                    is_A = False
        elif(s=='A'):
            is_A = True
            now_state = 0
            li_append([0])
    cnt = 0
    for i in li:
        cnt_b = sum(i)
        for j in i:
            cnt += cnt_b
            cnt_b -= j
            
    print(cnt)

if __name__ == '__main__':
    main()