Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import floor

a, b, x = map(int, readline().split())
memo = floor(x / a) - 1
if memo >= 10 ** 9:
    print(10 ** 9)
    exit()
elif memo < 0:
    print(0)
    exit()
dg = len(str(memo))
for i in range(memo + 10 ** 5, 0, -1):
    if x - a * i >= b * dg:
        print(i)
        exit()
print(0)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
ab = [list(map(int, readline().split())) for i in range(n - 1)]
gragh = [[] for j in range(n + 1)]
for a, b in ab:
    gragh[a].append(b)
    gragh[b].append(a)
root = 1
parent = [0] * (n + 1)
stack = [root]
order = []

while stack:
    x = stack.pop()
    order.append(x)
    for y in gragh[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)
color = [-1] * (n + 1)

for x in order:
    ng = color[x]
    cnt = 1
    for y in gragh[x]:
        if y == parent[x]:
            continue
        if cnt == ng:
            cnt += 1
        color[y] = cnt
        cnt += 1

ans = []
append = ans.append
for a, b in ab:
    if parent[a] == b:
        append(color[a])
    else:
        append(color[b])
print(max(ans))
print('\n'.join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
s = readline().rstrip().decode()[::-1]
index = 0
ans = []
for i in range(n):
    for j in range(m, 0, -1):
        if index + j >= n:
            ans = [n - index] + ans
            print(*ans)
            exit()
        if s[index + j] == '0':
            ans = [j] + ans
            index += j
            break
    else:
        print(-1)
        exit()


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import deque

n, m = map(int, readline().split())
s = readline().rstrip().decode()[::-1]
index = 0
ans = deque([])
for i in range(n):
    for j in range(m, 0, -1):
        if index + j >= n:
            ans.appendleft(n - index)
            print(*ans)
            exit()
        if s[index + j] == '0':
            ans.appendleft(j)
            index += j
            break
    else:
        print(-1)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


n = int(readline())
memo = prime_decomposition(n)
ans = float('inf')
if len(memo) == 1:
    print(memo[0] - 1)
else:
    len_memo = len(memo)
    bit = list(itertools.product([0, 1], repeat=len_memo))
    for i in range(2 ** len_memo):
        x, y = 1, 1
        for j in range(len_memo):
            if bit[i][j] == 0:
                x *= memo[j]
            else:
                y *= memo[j]
        if ans > x + y - 2:
            ans = x + y - 2
    print(ans)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ans = float('inf')
for i in range(1, int(n ** 0.5) + 1):
    x, y = divmod(n, i)
    if y == 0:
        ans = min(ans, x + i)
print(ans - 2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


n = int(readline())
memo = prime_decomposition(n)
ans = float('inf')
if len(memo) == 1:
    print(memo[0] - 1)
else:
    bit = list(itertools.product([0, 1], repeat=len(memo)))
    for i in range(2 ** len(memo)):
        x, y = 1, 1
        for j in range(len(memo)):
            if bit[i][j] == 0:
                x *= memo[j]
            else:
                y *= memo[j]
        if ans > x + y - 2:
            ans = x + y - 2
    print(ans)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ans = float('inf')
for i in range(1, int(n ** 0.5) + 1):
    x, y = divmod(n, i)
    if y == 0:
        ans = min(ans, x + i)
print(ans - 2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import atan, tan, pi

a, b, x = map(int, readline().split())


def max_v(si):
    si = si / 180 * pi
    if si < atan(b / a):
        area = a * b - a ** 2 * tan(si) / 2
    else:
        area = b * (b / tan(si) / 2)
    return area * a


low = 0
high = 90
while high - low > 1e-7:
    mid = (low + high) // 2
    if max_v(mid) <= x:
        high = mid
    else:
        low = mid
print((high + low) / 2)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import atan, tan, pi

a, b, x = map(int, readline().split())


def max_v(si):
    si = si / 180 * pi
    if si < atan(b / a):
        area = a * b - a ** 2 * tan(si) / 2
    else:
        area = b * (b / tan(si) / 2)
    return area * a


low = 0
high = 90
while high - low > 1e-7:
    mid = (low + high) / 2
    if max_v(mid) <= x:
        high = mid
    else:
        low = mid
print((high + low) / 2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import atan, tan, pi

a, b, x = map(int, readline().split())


def max_v(si):
    si = si / 180 * pi
    if si < atan(b / a):
        area = a * b - a ** 2 * tan(si) / 2
    else:
        area = b * (b / tan(si) / 2)
    return area * a


low = 0
high = 90
while high - low > 1e-7:
    mid = (low + high) // 2
    if max_v(mid) <= x:
        high = mid
    else:
        low = mid
print((high + low) / 2)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import atan, tan, pi

a, b, x = map(int, readline().split())


def max_v(si):
    si = si / 180 * pi
    if si < atan(b / a):
        area = a * b - a ** 2 * tan(si) / 2
    else:
        area = b * (b / tan(si) / 2)
    return area * a


low = 0
high = 90
while high - low > 1e-7:
    mid = (low + high) / 2
    if max_v(mid) <= x:
        high = mid
    else:
        low = mid
print((high + low) / 2)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w, a, b = map(int, readline().split())
x_cnt = [0] * h
y_cnt = [0] * w
ans = [''] * h
if h == 1:
    print('1' * a + '0' * (w - a))
elif w == 1:
    for i in range(b):
        print('1')
    for i in range(h - b):
        print('0')
else:
    for i in range(h):
        for j in range(w):
            print(ans)
            if y_cnt[j] < b and x_cnt[i] < a:
                y_cnt[j] += 1
                x_cnt[i] += 1
                ans[i] += '1'
            else:
                ans[i] += '0'
        if a != 0:
            if x_cnt[i] != a:
                print('No')
                exit()
    if b != 0:
        for i in range(w):
            if y_cnt[i] != b:
                print('No')
                exit()
    for i in range(h):
        print(ans[i])


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w, a, b = map(int, readline().split())
ans_1 = '1' * a + '0' * (w - a)
ans_2 = '0' * a + '1' * (w - a)
for i in range(b):
    print(ans_1)
for i in range(h - b):
    print(ans_2)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def Z_algo(S):
    LCP = [0] * n
    c = 0  # 最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        # i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i + LCP[i - c] < c + LCP[c]:
            LCP[i] = LCP[i - c]
        else:
            j = max(0, c + LCP[c] - i)
            while i + j < n and S[j] == S[i + j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP


n = int(readline())
s = read().rstrip().decode()
ans = 0
for i in range(n):
    m = Z_algo(s[i:])[1:] + [0] * 1
    ans = max(ans, max(m[n // 2 - i:]))
print(ans)


Fixed submission:
def Z_algo(S):
    n = len(S)
    LCP = [0] * n
    c = 0  # 最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        # i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i + LCP[i - c] < c + LCP[c]:
            LCP[i] = LCP[i - c]
        else:
            j = max(0, c + LCP[c] - i)
            while i + j < n and S[j] == S[i + j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP


n = int(input())
s = input()
ans = 0
for i in range(n):
    lcp = Z_algo(s[i:])
    for j, p in enumerate(lcp):
        tmp = min(j, p)
        ans = max(ans, tmp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def Z_algo(S):
    n = len(S)
    LCP = [0] * n
    i = 1
    j = 0
    c = 0  # 最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        # i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i + LCP[i - c] < c + LCP[c]:
            LCP[i] = LCP[i - c]
        else:
            j = max(0, c + LCP[c] - i)
            while i + j < n and S[j] == S[i + j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP


n = int(input())
s = input()
ans = 0
for i in range(n):
    lcp = Z_algo(s[i:])
    for j in range(len(lcp)):
        tmp = min(j, lcp[j])
        ans = max(ans, tmp)
print(ans)


Fixed submission:
def Z_algo(S):
    n = len(S)
    LCP = [0] * n
    c = 0  # 最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        # i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i + LCP[i - c] < c + LCP[c]:
            LCP[i] = LCP[i - c]
        else:
            j = max(0, c + LCP[c] - i)
            while i + j < n and S[j] == S[i + j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP


n = int(input())
s = input()
ans = 0
for i in range(n):
    lcp = Z_algo(s[i:])
    for j, p in enumerate(lcp):
        tmp = min(j, p)
        ans = max(ans, tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = [list(map(int, readline().split())) for _ in range(n)]
for cnt in range(n ** 2):
    check = []
    flag = True
    for i in range(n):
        if a[i]:
            flag = False
            if a[a[i][0] - 1][0] == i + 1:
                check.append(i)
    if flag:
        print(cnt)
        break
    if check:
        for v in check:
            a[v].pop(0)
    else:
        print(-1)
        break


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = [list(map(int, readline().split())) for _ in range(n)]
q = list(range(n))
for cnt in range(1, n ** 2 + 2):
    qq = set()
    while q:
        x = q.pop()
        if a[a[x][0] - 1][0] == x + 1:
            qq.add(x)
            qq.add(a[x][0] - 1)
    if qq:
        for x in qq:
            a[x].pop(0)
            if a[x]:
                q.append(x)
    else:
        print(-1)
        break
    if not q:
        print(cnt)
        break

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = [list(map(int, readline().split())) for _ in range(n)]
for cnt in range(n ** 2):
    check = []
    flag = True
    for i in range(n):
        if a[i]:
            flag = False
            if a[a[i][0] - 1][0] == i + 1:
                check.append(i)
    if flag:
        print(cnt)
        break
    if check:
        for v in check:
            a[v].pop(0)
    else:
        print(-1)
        break


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = [list(map(int, readline().split())) for _ in range(n)]
q = list(range(n))
for cnt in range(1, n ** 2 + 2):
    qq = set()
    while q:
        x = q.pop()
        if a[a[x][0] - 1][0] == x + 1:
            qq.add(x)
            qq.add(a[x][0] - 1)
    if qq:
        for x in qq:
            a[x].pop(0)
            if a[x]:
                q.append(x)
    else:
        print(-1)
        break
    if not q:
        print(cnt)
        break
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
w = list(input().split())
ans = ['TAKAHASHIKUN', 'Takahashikun', 'takahashikun']
cnt = 0
w[n - 1] = w[n - 1].rstrip('.')
for i in range(n):
    if len(w[i]) == 12 and w[i] in ans:
        cnt += 1

print(cnt)


Fixed submission:
s = input()
memo = ''
len_s = len(s)
cnt = 0
ans = 0

for i in range(2 * 10 ** 5):
    ans += 1
    if memo == s[cnt]:
        if cnt == len_s - 1:
            ans -= 1
        memo = s[cnt:cnt + 2]
        cnt += 2
    else:
        memo = s[cnt]
        cnt += 1
    if cnt > len_s - 1:
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


n = int(readline())
a = list(map(int, readline().split()))
a = a[::-1]
cnt = [0] * n
ans = []
for i in range(n):
    if cnt[n - i - 1] % 2 != a[i]:
        ans.append(n - i)
        memo = make_divisors(n - i)
        for j in range(len(memo)):
            cnt[memo[j] - 1] += 1
print(len(ans))
print(*ans[::-1])


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


n = int(readline())
a = list(map(int, readline().split()))
a = a[::-1]
cnt = [0] * n
ans = []
for i in range(n):
    if cnt[n - i - 1] % 2 != a[i]:
        ans.append(n - i)
        memo = make_divisors(n - i)
        for j in range(len(memo)):
            cnt[memo[j] - 1] += 1
print(len(ans))
print(*ans[::-1])
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

n = int(readline())
xy = [list(map(int, readline().split())) for _ in range(n)]
dict = defaultdict(int)
for i, check in enumerate(xy):
    for dxy in xy[i + 1:]:
        y, x = check[0], check[1]
        dy, dx = dxy[0], dxy[1]
        dict[(y - dy, x - dx)] += 1
print(n - max(dict.values()))


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

n = int(readline())
xy = [tuple(map(int, readline().split())) for _ in range(n)]
dict = defaultdict(int)
dict[0] = 0
for i, check in enumerate(xy):
    for dxy in xy[i + 1:]:
        y, x = check[0], check[1]
        dy, dx = dxy[0], dxy[1]
        dict[(y - dy, x - dx)] += 1
        dict[(dy - y, dx - x)] += 1
print(n - max(dict.values()))
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_right

n = int(readline())
a = list(map(int, readline().split()))
a.sort()
if a[0] <= 0 and a[-1] >= 0:
    print(sum(map(lambda x: abs(int(x)), a)))
    idx = bisect_right(a, 0)
    x = a[0]
    y = a[idx]
    for aa in a[1:idx]:
        print(y, aa)
        y -= aa
    for aa in a[idx + 1:]:
        print(x, aa)
        x -= aa
    print(y, x)
else:
    if a[0] < 0:
        print(-sum(a) + 2 * a[-1])
        a = a[::-1]
    else:
        print(sum(a) - 2 * a[0])
    x = a[0]
    y = a[-1]
    for aa in a[1:-1]:
        print(x, aa)
        x -= aa
    if a[0] < 0:
        y, x = x, y
    print(y, x)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_right

n = int(readline())
a = list(map(int, readline().split()))
a.sort()
if a[0] <= 0 and a[-1] >= 0:
    print(sum(map(lambda x: abs(int(x)), a)))
    idx = bisect_right(a, 0)
    idx -= 1 if idx == n else 0
    x = a[0]
    y = a[idx]
    for aa in a[1:idx]:
        print(y, aa)
        y -= aa
    for aa in a[idx + 1:]:
        print(x, aa)
        x -= aa
    print(y, x)
else:
    if a[0] < 0:
        print(-sum(a) + 2 * a[-1])
        a = a[::-1]
    else:
        print(sum(a) - 2 * a[0])
    x = a[0]
    y = a[-1]
    for aa in a[1:-1]:
        print(x, aa)
        x -= aa
    if a[0] < 0:
        y, x = x, y
    print(y, x)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy

h, w = map(int, readline().split())
s = [input() for _ in range(h)]
cnt_x = [[0] * w for _ in range(h)]
cnt_y = deepcopy(cnt_x)
for i in range(h):
    memo = 0
    for j in range(w):
        if s[i][j] == '.':
            memo += 1
            cnt_x[i][j] = memo
        else:
            memo = 0
    for j in range(w - 1, 0, -1):
        if s[i][j - 1] == '.':
            cnt_x[i][j - 1] = max(cnt_x[i][j - 1], cnt_x[i][j])
for i in range(w):
    memo = 0
    for j in range(h):
        if s[j][i] == '.':
            memo += 1
            cnt_y[j][i] = memo
        else:
            memo = 0
    for j in range(h - 1, 0, -1):
        if s[j - 1][i] == '.':
            cnt_y[j - 1][i] = max(cnt_y[j - 1][i], cnt_y[j][i])
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, cnt_x[i][j] + cnt_y[i][j] - 1)
print(ans)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy

h, w = map(int, readline().split())
s = [input() for _ in range(h)]
cnt_x = [[0] * w for _ in range(h)]
cnt_y = deepcopy(cnt_x)
for i in range(h):
    memo = 0
    for j in range(w):
        if s[i][j] == '.':
            memo += 1
            cnt_x[i][j] = memo
        else:
            memo = 0
    for j in range(w - 1, 0, -1):
        if s[i][j - 1] == '.':
            if cnt_x[i][j - 1] < cnt_x[i][j]:
                cnt_x[i][j - 1] = cnt_x[i][j]
for i in range(w):
    memo = 0
    for j in range(h):
        if s[j][i] == '.':
            memo += 1
            cnt_y[j][i] = memo
        else:
            memo = 0
    for j in range(h - 1, 0, -1):
        if s[j - 1][i] == '.':
            cnt_y[j - 1][i] = max(cnt_y[j - 1][i], cnt_y[j][i])
            if cnt_y[j - 1][i] < cnt_y[j][i]:
                cnt_y[j - 1][i] = cnt_y[j][i]
ans = 0
for i in range(h):
    for j in range(w):
        v = cnt_x[i][j] + cnt_y[i][j] - 1
        if ans < v:
            ans = v
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import re

s = input()
s = s[::-1]
ans = 0
if s.count('CBA') != 0:
    for i in range(s.count('A')):
        if s.find('CBA') < s.find('A'):
            a = re.search('(CB)+A', s)
            ans += (a.end()-a.start()-1)//2
        s = s.replace('A', '', 1)
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

s = input()
s = s[::-1]
ans = 0
a = -1
s = (s.replace('CB', 'D').replace('C', '\t').replace('B', '\t')).split()
for i in range(len(s)):
    for j in range(s[i].count('A')):
        a = s[i].find('A',a+1)
        ans += a-j
    a = -1
print(ans)

Buggy python submission (verdict: Runtime Error):
import re

s = input()
s = s[::-1]
ans = 0
for i in range(s.count('A')):
    a = re.search('(CB)+A', s)
    ans += (a.end()-a.start()-1)//2
    s = s.replace('A', '', 1)
    print((a.end()-a.start()),s,ans)
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

s = input()
s = s[::-1]
ans = 0
a = -1
s = (s.replace('CB', 'D').replace('C', '\t').replace('B', '\t')).split()
for i in range(len(s)):
    for j in range(s[i].count('A')):
        a = s[i].find('A',a+1)
        ans += a-j
    a = -1
print(ans)