Buggy python submission (verdict: Runtime Error):
S = list(input())
S = S[::-1]

t = 0
ans = 0
bc_score = 0
flag = 1

if len(S) <= 2:
    print(0)
    exit()

while t <= len(S)-1:
    if S[t]=="C" and S[t+1] == "B":
        bc_score = 0
        bc_score += 1
        t += 2
        flag = 1
        if t == len(S)-1:
            if S[t] == "A":
                ans += 1
            t += 1
        while flag == 1 and t < len(S) - 1:
            flag = 0
            if S[t]=="C" and S[t+1] == "B":
                bc_score += 1
                t += 2
                flag = 1
            if t <= len(S) - 1:
                if S[t] == "A":
                    ans += bc_score
                    t += 1
                    flag = 1
    else:
        t += 1

print(ans)

Fixed submission:
S = list(input())
S = S[::-1]

t = 0
ans = 0
bc_score = 0
flag = 1

if len(S) <= 2:
    print(0)
    exit()

while t <= len(S)-2:
    if S[t]=="C" and S[t+1] == "B":
        bc_score = 0
        bc_score += 1
        t += 2
        flag = 1
        if t == len(S)-1:
            if S[t] == "A":
                ans += 1
            t += 1
        while flag == 1 and t <= len(S) - 1:
            flag = 0
            if S[t]=="C" and S[t+1] == "B":
                bc_score += 1
                t += 2
                flag = 1
            if t <= len(S) - 1:
                if S[t] == "A":
                    ans += bc_score
                    t += 1
                    flag = 1
    else:
        t += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
S = S[::-1]

ans = 0
bc_score = 0
flag = 1

if len(S) <= 1:
    print(0)
    exit()

while len(S) != 0:
    if S[0]=="C" and S[1] == "B":
        bc_score = 0
        bc_score += 1
        S.pop(0)
        S.pop(0)
        flag = 1
        if len(S) == 1:
            if S[0] == "A":
                ans += 1
            S.pop(0)
        while flag == 1 and len(S) != 0:
            flag = 0
            if S[0]=="C" and S[1] == "B":
                bc_score += 1
                S.pop(0)
                S.pop(0)
                flag = 1
            if len(S) != 0:
                if S[0] == "A":
                    ans += bc_score
                    S.pop(0)
                    flag = 1
    else:
        S.pop(0)

print(ans)

Fixed submission:
S = list(input())
S = S[::-1]

t = 0
ans = 0
bc_score = 0
flag = 1

if len(S) <= 2:
    print(0)
    exit()

while t <= len(S)-2:
    if S[t]=="C" and S[t+1] == "B":
        bc_score = 0
        bc_score += 1
        t += 2
        flag = 1
        if t == len(S)-1:
            if S[t] == "A":
                ans += 1
            t += 1
        while flag == 1 and t <= len(S) - 1:
            flag = 0
            if S[t]=="C" and S[t+1] == "B":
                bc_score += 1
                t += 2
                flag = 1
            if t <= len(S) - 1:
                if S[t] == "A":
                    ans += bc_score
                    t += 1
                    flag = 1
    else:
        t += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
S = S[::-1]

ans = 0
bc_score = 0
flag = 1

if len(S) <= 1:
    print(0)
    exit()

while len(S) != 0:
    if S[0]=="C" and S[1] == "B":
        bc_score = 0
        bc_score += 1
        S.pop(0)
        S.pop(0)
        flag = 1
        if len(S) <= 1:
            if S[0] == "A":
                ans += 1
            S.pop(0)
        while flag == 1 and len(S) != 0:
            flag = 0
            if S[0]=="C" and S[1] == "B":
                bc_score += 1
                S.pop(0)
                S.pop(0)
                flag = 1
            if S[0] == "A":
                ans += bc_score
                S.pop(0)
                flag = 1
    else:
        S.pop(0)

print(ans)

Fixed submission:
S = list(input())
S = S[::-1]

t = 0
ans = 0
bc_score = 0
flag = 1

if len(S) <= 2:
    print(0)
    exit()

while t <= len(S)-2:
    if S[t]=="C" and S[t+1] == "B":
        bc_score = 0
        bc_score += 1
        t += 2
        flag = 1
        if t == len(S)-1:
            if S[t] == "A":
                ans += 1
            t += 1
        while flag == 1 and t <= len(S) - 1:
            flag = 0
            if S[t]=="C" and S[t+1] == "B":
                bc_score += 1
                t += 2
                flag = 1
            if t <= len(S) - 1:
                if S[t] == "A":
                    ans += bc_score
                    t += 1
                    flag = 1
    else:
        t += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
S = S[::-1]

ans = 0
bc_score = 0
flag = 1

if len(S) <= 1:
    print(0)
    exit()

while len(S) != 0:
    if S[0]=="C" and S[1] == "B":
        bc_score = 0
        bc_score += 1
        S.pop(0)
        S.pop(0)
        flag = 1
        while flag == 1 and len(S) != 0:
            flag = 0
            if S[0]=="C" and S[1] == "B":
                bc_score += 1
                S.pop(0)
                S.pop(0)
                flag = 1
            if S[0] == "A":
                ans += bc_score
                S.pop(0)
                flag = 1
    else:
        S.pop(0)

print(ans)

Fixed submission:
S = list(input())
S = S[::-1]

t = 0
ans = 0
bc_score = 0
flag = 1

if len(S) <= 2:
    print(0)
    exit()

while t <= len(S)-2:
    if S[t]=="C" and S[t+1] == "B":
        bc_score = 0
        bc_score += 1
        t += 2
        flag = 1
        if t == len(S)-1:
            if S[t] == "A":
                ans += 1
            t += 1
        while flag == 1 and t <= len(S) - 1:
            flag = 0
            if S[t]=="C" and S[t+1] == "B":
                bc_score += 1
                t += 2
                flag = 1
            if t <= len(S) - 1:
                if S[t] == "A":
                    ans += bc_score
                    t += 1
                    flag = 1
    else:
        t += 1

print(ans)