Buggy python submission (verdict: Time Limit Exceeded):
s = input()
def getScore(arr):
    total = 0
    minus = 0
    start = 0
    while 0 in arr[start:]:
        total += arr.index(0, start)
        total -= minus
        minus += 1
        start = arr.index(0, start) + 1

    return total

total = 0
data = []
toInt = {'A':1, 'B':2, 'C':2}
i = 0
while i < len(s)-1:
    # BC=>0
    if s[i] == 'B' and s[i+1] == 'C':
        data.append(0)
        i += 1
    elif s[i] == 'A':
        data.append(toInt[s[i]])
    else:
        if len(data) > 0:
            total += getScore(data)
            data = []
    i+=1

if len(data) > 0:
    total += getScore(data)
    data = []
    
print(total)

Fixed submission:
s = input()
total = 0
i = 0
inRange = False
range_start = 0
range_minus = 0
range_cnt = 0

while i < len(s)-1:
    # BC=>0
    if s[i] == 'B' and s[i+1] == 'C':
        if inRange:
            total += (range_cnt - range_minus)
            range_cnt += 1
            range_minus += 1
        i += 1
    elif s[i] == 'A':
        inRange = True
        range_cnt += 1
    else:
        inRange = False
        range_start = 0
        range_minus = 0
        range_cnt = 0
    i+=1
    
print(total)

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

data = []
toInt = {'A':1, 'B':2, 'C':2}
i = 0
while i < len(s)-1:
    # BC=>0
    if s[i] == 'B' and s[i+1] == 'C':
        data.append(0)
        i += 1
    else:
        data.append(toInt[s[i]])
    i+=1

if i < len(s):
    data.append(toInt[s[i]])


def getScore(s):
    total = 0
    minus = 0
    start = 0
    while 0 in arr[start:]:
        total += arr.index(0, start)
        total -= minus
        minus += 1
        start = arr.index(0, start) + 1

    return total


# Calculate score
total = 0
start = 0 
while start < len(data):
    end = start
    while end < len(data) and not data[end] == 2:
        end += 1
    arr= data[start:end]
    total += getScore(arr)
    start = end + 1
    
print(total)

Fixed submission:
s = input()
total = 0
i = 0
inRange = False
range_start = 0
range_minus = 0
range_cnt = 0

while i < len(s)-1:
    # BC=>0
    if s[i] == 'B' and s[i+1] == 'C':
        if inRange:
            total += (range_cnt - range_minus)
            range_cnt += 1
            range_minus += 1
        i += 1
    elif s[i] == 'A':
        inRange = True
        range_cnt += 1
    else:
        inRange = False
        range_start = 0
        range_minus = 0
        range_cnt = 0
    i+=1
    
print(total)

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

data = []
toInt = {'A':1, 'B':2, 'C':2}
i = 0
while i < len(s)-1:
    # BC=>0
    if s[i] == 'B' and s[i+1] == 'C':
        data.append(0)
        i += 1
    else:
        data.append(toInt[s[i]])
    i+=1

if i < len(s):
    data.append(toInt[s[i]])


def getScore(s):
    total = 0
    minus = 0
    start = 0
    while 0 in arr[start:]:
        total += arr.index(0, start)
        total -= minus
        minus += 1
        start = arr.index(0, start) + 1

    return total


# Calculate score
total = 0
start = 0 
while start < len(data):
    end = start
    while end < len(data) and not data[end] == 2:
        end += 1
    arr= data[start:end]
    total += getScore(arr)
    start = end + 1
    
print(total)

Fixed submission:
s = input()
total = 0
i = 0
inRange = False
range_start = 0
range_minus = 0
range_cnt = 0

while i < len(s)-1:
    # BC=>0
    if s[i] == 'B' and s[i+1] == 'C':
        if inRange:
            total += (range_cnt - range_minus)
            range_cnt += 1
            range_minus += 1
        i += 1
    elif s[i] == 'A':
        inRange = True
        range_cnt += 1
    else:
        inRange = False
        range_start = 0
        range_minus = 0
        range_cnt = 0
    i+=1
    
print(total)