Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
H, W, M = map(int, input().split())
count_row = Counter()
count_col = Counter()
count_point = Counter()
for i in range(M):
    h, w = map(int, input().split())
    count_row[h] += 1
    count_col[w] += 1
    count_point[(h, w)] += 1

max_h, max_count_row = count_row.most_common()[0]
max_w, max_count_col = count_col.most_common()[0]
row_iter = [(h, c) for h, c in count_row.most_common() if c == max_count_row]
col_iter = [(w, c) for w, c in count_col.most_common() if c == max_count_col]
ans = 0
for h, row_c in row_iter:
    for w, col_c in col_iter:
        ans = max(ans, row_c+col_c-count_point[(h, w)])
print(ans)


Fixed submission:
from collections import Counter
H, W, M = map(int, input().split())
count_row = Counter()
count_col = Counter()
count_point = Counter()
for i in range(M):
    h, w = map(int, input().split())
    count_row[h] += 1
    count_col[w] += 1
    count_point[(h, w)] += 1

max_h, max_count_row = count_row.most_common()[0]
max_w, max_count_col = count_col.most_common()[0]
row_iter = [h for h, c in count_row.most_common() if c == max_count_row]
col_iter = [w for w, c in count_col.most_common() if c == max_count_col]
ans = max_count_row + max_count_col - 1
flag = False
for h in row_iter:
    for w in col_iter:
        if count_point[(h, w)] == 1:
            continue
        ans += 1
        flag = True
        break
    if flag:
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
X, K, D = map(int, input().split())
if abs(X // D) >= K:
    ans = X - (D * K) * (X // abs(X))
    ans = abs(ans)
else:
    K -= X//D
    ans = X - (D * (X//D)) * (X // abs(X))
    if K % 2 == 0 and abs(ans) < D:
        ans = abs(ans)
    else:
        ans = min(abs(ans+D), abs(ans-D))
    # print((D * X//D) * (X // abs(X)))
print(ans)
# print(X // D, math.ceil(X / D))


Fixed submission:
import sys
import math
X, K, D = map(int, input().split())
if X == 0 and K % 2 == 0:
    print(X)
    sys.exit()
elif X == 0 and K % 2 == 1:
    print(D)
    sys.exit()

if abs(X // D) >= K:
    ans = X - (D * K) * (X // abs(X))
    ans = abs(ans)
else:
    K -= abs(X//D)
    ans = X - (D * abs(X//D)) * (X // abs(X))
    if K % 2 == 0 and K == 0:
        ans = abs(ans)
    elif K % 2 == 0 and K >= 2:
        ans = min([abs(ans), abs(ans-D*2), abs(ans+D*2)])
    else:
        ans = min(abs(ans+D), abs(ans-D))
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import Counter
N = int(input())
X = list(input())
revX = reversed(X)
count01 = Counter(X)
if count01['1'] == 0:
    for i in range(N):
        print(1)
    sys.exit()
m1 = count01['1']-1
p1 = count01['1']+1
powrem = []
m1rem = 0
p1rem = 0
basem1 = 1
basep1 = 1

for i, xi in enumerate(revX):
    # print(basep1)
    if xi == '0':
        powrem += [basep1 % p1]
    else:
        powrem += [basem1 % m1]
        m1rem = (m1rem + basem1) % m1
        p1rem = (p1rem + basep1) % p1
    basem1 = (basem1 * 2) % m1
    basep1 = (basep1 * 2) % p1
revpowrem = reversed(powrem)
# print(list(revpowrem))
for xi, rem in zip(X, revpowrem):
    c = 1
    if xi == '0':
        r = (p1rem+rem)%p1
    else:
        if m1 == 0:
            print(0)
            continue
        r = (m1rem-rem)%m1
    # print(r, xi, rem)
    while r != 0:
        p = bin(r).count('1')
        r = r % p
        c += 1
    print(c)

Fixed submission:
import sys
from collections import Counter
N = int(input())
X = list(input())
revX = reversed(X)
count01 = Counter(X)
if count01['1'] == 0:
    for i in range(N):
        print(1)
    sys.exit()
m1 = count01['1']-1
p1 = count01['1']+1
powrem = []
m1rem = 0
p1rem = 0
basem1 = 1
basep1 = 1
if m1 == 0:
    for i, xi in enumerate(revX):
    # print(basep1)
        if xi == '0':
            powrem += [basep1 % p1]
        else:
            powrem += [0]
            p1rem = (p1rem + basep1) % p1
        basep1 = (basep1 * 2) % p1
    revpowrem = reversed(powrem)
    # print(list(revpowrem))
    for xi, rem in zip(X, revpowrem):
        c = 1
        if xi == '0':
            r = (p1rem+rem)%p1
        else:
            print(0)
            continue
        # print(r, xi, rem)
        while r != 0:
            p = bin(r).count('1')
            r = r % p
            c += 1
        print(c)
    sys.exit()

for i, xi in enumerate(revX):
    # print(basep1)
    if xi == '0':
        powrem += [basep1 % p1]
    else:
        powrem += [basem1 % m1]
        m1rem = (m1rem + basem1) % m1
        p1rem = (p1rem + basep1) % p1
    basem1 = (basem1 * 2) % m1
    basep1 = (basep1 * 2) % p1
revpowrem = reversed(powrem)
# print(list(revpowrem))
for xi, rem in zip(X, revpowrem):
    c = 1
    if xi == '0':
        r = (p1rem+rem)%p1
    else:
        r = (m1rem-rem)%m1
    # print(r, xi, rem)
    while r != 0:
        p = bin(r).count('1')
        r = r % p
        c += 1
    print(c)
Buggy python submission (verdict: Runtime Error):
# import sys
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split())) + [10**13]
B = [0] + list(map(int, input().split())) + [10**13]
sum_t = 0
cumsumA = [0]
cumsumB = [0]
ansA = N
ansB = M
tmp = 0
for i in range(1, N+1):
    tmp = tmp + A[i]
    if tmp > K:
        ansA = i-1
        break
    cumsumA += [tmp]
tmp = 0
for i in range(1, M+1):
    tmp = tmp + B[i]
    if tmp > K:
        ansB = i-1
        break
    cumsumB += [tmp]

ans_t = cumsumA[ansA] + cumsumB[ansB]
ansAA = ansA
ansBB = ansB
ans = ansA + ansB
ans2 = max([ans, ansAA, ansBB])
visited_dict = {}
while K < ans_t:    
    ai, bi = A[ansA], B[ansB]
    if visited_dict.get((ai, bi)):
        break
    visited_dict[(ai, bi)] = 1
    if ai >= bi:
        ans_t -= ai
        ans -= 1
        ansA -= 1
        bi = B[ansB+1]
        while ans_t <= K:
            ans += 1
            ans_t += bi
            ansB += 1
            bi = B[ansB+1]
    else:
        ans_t -= bi
        ans -= 1
        ansB -= 1
        ai = A[ansA+1]
        while ans_t <= K:
            ans += 1
            ans_t += ai
            ansA += 1
            ai = A[ansA+1]
    
ans2 = max(ans-1, ans2)

print(ans2)
# print(ansA, ansB)

Fixed submission:
# import sys
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split())) + [10**13]
B = [0] + list(map(int, input().split())) + [10**13]
sum_t = 0
cumsumA = [0]
cumsumB = [0]
ansA = N
ansB = 0
tmp = 0
for i in range(1, N+1):
    tmp = tmp + A[i]
    if tmp > K:
        ansA = i-1
        break
    cumsumA += [tmp]
tmp = 0
for i in range(1, M+1):
    tmp = tmp + B[i]
    if tmp > K:
        break
    cumsumB += [tmp]
j = 0
ans = 0
for i in range(ansA, -1, -1):
    t = cumsumA[i] + cumsumB[j]
    while True:
        tmp = B[j+1]
        if tmp + t <= K:
            t += tmp
            j += 1
        else:
            break
    ans = max(ans, i + j)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
AB = []
for i in range(N):
    A, B = map(int, input().split())
    AB += [(A, B)]
sortA = sorted(AB, key=lambda x: x[0])
sortB = sorted(AB, key=lambda x: x[1])
if N % 2 == 0:
    mid = N//2-1
    A11,B11 = sortA[mid]
    A12,B12 = sortA[mid+1]
    # print(A11, B11)
    # print(A12, B12)
    A1 = (A11+A12) / 2
    B1 = (B11+B12) / 2
    A21,B21 = sortB[mid]
    A22,B22 = sortB[mid+1]
    A2 = (A21+A22) / 2
    B2 = (B21+B22) / 2
    # ans = (min(B1, B2) - max(A1, A2))*2 + 1
    ans = (B2 - A1)*2 + 1
    # print(B1, B2, A1, A2, ans)
    # if ans % 1 != 0:
    #     ans += 1
else:
    mid = (N+1)//2-1
    A1,B1 = sortA[mid]
    A2,B2 = sortB[mid]
    # print(A1, A1, B1, B2)
    ans = (B2 - A1) + 1

print(int(ans))


Fixed submission:
import math
def eratos(n):
    isprime = [True for i in range(n+1)]
    isprime[0] = False
    isprime[1] = False
    for i in range(2, int(math.sqrt(n))+13):
        if isprime[i]:
            j = i + i
        while j <= n:
            isprime[j] = False
            j = j + i
    return isprime
N = int(input())
ans = 0
is_prime = eratos(10**6+13)
for i in range(2, 10**6+14):
    if not is_prime[i]:
        continue
    x = i
    while N % x == 0:
        ans += 1
        N //= x
        x *= i
        # print(N)
if ans == 0 and N != 1:
    ans += 1
elif N > 10**6:
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def yakusu(n):
    results = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            results.append(i)
            results.append(n // i)
    return list(set(results)) + [n]

N = int(input())
count = 0
for i in yakusu(N):
    NN = N
    while NN >= i:
        if NN % i == 0:
            NN //= i
        else:
            NN %= i
    if NN == 1:
        count += 1
for i in yakusu(N-1):
    NN = N
    while NN >= i:
        if NN % i == 0:
            NN //= i
        else:
            NN %= i
    if NN == 1:
        count += 1
print(count)


Fixed submission:
def yakusu(n):
    if n == 1:
        return []
    results = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            results.append(i)
            results.append(n // i)
    return list(set(results)) + [n]

N = int(input())
count = 0
for i in yakusu(N):
    NN = N
    while NN >= i:
        if NN % i == 0:
            NN //= i
        else:
            NN %= i
    if NN == 1:
        count += 1
for i in yakusu(N-1):
    NN = N
    while NN >= i:
        if NN % i == 0:
            NN //= i
        else:
            NN %= i
    if NN == 1:
        count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
class DisjointSet:
    def __init__(self, size):
        self.rank = [0 for i in range(size)]
        self.p = [0 for i in range(size)]
        for i in range(size):
            self.makeSet(i)
    
    def makeSet(self, x):
        self.p[x] = x
        self.rank[x] = 0

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
    
    def findSet(self, x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]
        

from collections import defaultdict, Counter
count_friend = Counter()
friends = defaultdict(set)
blocks = defaultdict(set)
N, M, K = map(int, input().split())
ds = DisjointSet(N+1)
# graph = [[] for i in range(N+1)]
for i in range(M):
    A, B = map(int, input().split())
    ds.unite(A, B)
    count_friend[A] += 1
    count_friend[B] += 1
for i in range(K):
    C, D = map(int, input().split())
    blocks[C].add(D)
    blocks[D].add(C)
c_ids = [ds.findSet(i) for i in range(N+1)]
for i in range(1, N+1):
    friends[c_ids[i]].add(i)
ans = []
for i in range(1, N+1):
    c_id = c_ids[i]
    ans += [len(friends[c_id]-blocks[i])-count_friend[i]-1]
print(' '.join(list(map(str, ans))))
# print(ds.p)

Fixed submission:
class DisjointSet:
    def __init__(self, size):
        self.rank = [0 for i in range(size)]
        self.p = [0 for i in range(size)]
        for i in range(size):
            self.makeSet(i)
    
    def makeSet(self, x):
        self.p[x] = x
        self.rank[x] = 0

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
    
    def findSet(self, x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]
        

from collections import defaultdict, Counter
count_friend = Counter()
# friends = defaultdict(list)
friends_cluster = Counter()
# blocks = defaultdict(set)
count_block = Counter()
N, M, K = map(int, input().split())
ds = DisjointSet(N+1)
# graph = [[] for i in range(N+1)]
for i in range(M):
    A, B = map(int, input().split())
    ds.unite(A, B)
    count_friend[A] += 1
    count_friend[B] += 1
for i in range(K):
    C, D = map(int, input().split())
    if ds.same(C, D):
        count_block[C] += 1
        count_block[D] += 1
c_ids = [ds.findSet(i) for i in range(N+1)]
for i in range(1, N+1):
    friends_cluster[c_ids[i]] += 1
ans = []
for i in range(1, N+1):
    c_id = c_ids[i]
    ans += [friends_cluster[c_id]-count_block[i]-count_friend[i]-1]
print(' '.join(list(map(str, ans))))
# print(ds.p)
Buggy python submission (verdict: Runtime Error):
N = int(input())
for i in range(1, N):
    tmp = (i * 1.08) // 1
    if tmp == N:
        ans = i
        break
    elif tmp > N:
        ans = ':('
        break
print(ans)

Fixed submission:
N = int(input())
# ans = ':('
for i in range(1, N+1):
    tmp = (i * 1.08) // 1
    if tmp == N:
        ans = i
        break
    elif tmp > N:
        ans = ':('
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
def dfs(s, targets):
    global K
    visited[s] = True
    # print(targets)
    for t in targets:
        if visited[t]:
            continue
        mab = max(G3[s], G3[t])
        while (mab in G2[s]) or (mab in G2[t]):
            mab += 1
        K = max(K, mab)
        ans[p2i[(s, t)]]= mab
        G2[s].add(mab)
        G2[t].add(mab)
        while G3[s] in G2[s]:
            G3[s] += 1
        while G3[t] in G2[t]:
            G3[t] += 1
        dfs(t, G[t])

K = 0
N = int(input())
G = [[] for i in range(N+1)]
G2 = [set() for i in range(N+1)]
p2i = {}
visited = [False for i in range(N+1)]
ans = [0 for i in range(N-1)]
G3 = [1] * (N+1)
for i in range(N-1):
    a, b = map(int, input().split())
    p2i[(a, b)] = i
    p2i[(b, a)] = i
    G[a].append(b)
    G[b].append(a)
# print(max(p2i.values()))
s = 1
targets = G[s]
dfs(s, targets)
print(K)
for a in ans:
    print(a)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def dfs(s, targets):
    global K
    visited[s] = True
    # print(targets)
    for t in targets:
        if visited[t]:
            continue
        mab = max(G3[s], G3[t])
        while (mab in G2[s]) or (mab in G2[t]):
            mab += 1
        K = max(K, mab)
        ans[p2i[(s, t)]]= mab
        G2[s].add(mab)
        G2[t].add(mab)
        while G3[s] in G2[s]:
            G3[s] += 1
        while G3[t] in G2[t]:
            G3[t] += 1
        dfs(t, G[t])

K = 0
N = int(input())
G = [[] for i in range(N+1)]
G2 = [set() for i in range(N+1)]
p2i = {}
visited = [False for i in range(N+1)]
ans = [0 for i in range(N-1)]
G3 = [1] * (N+1)
for i in range(N-1):
    a, b = map(int, input().split())
    p2i[(a, b)] = i
    p2i[(b, a)] = i
    G[a].append(b)
    G[b].append(a)
# print(max(p2i.values()))
s = 1
targets = G[s]
dfs(s, targets)
print(K)
for a in ans:
    print(a)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import Counter
from functools import reduce
from operator import mul
M = 998244353
N = int(input())
D = list(map(int, input().split()))
counter = set(D)
if D[0] == 0:
    D[0] = 1
    ans = reduce(mul, D)
    for i, k in enumerate(sorted(counter)):
        if i == k:
            continue
        ans = 0
    print(ans % M)
else:
    print(0)


Fixed submission:
N = int(input())
ans = 0
for i in range(1, N):
    if N - i != i:
        ans += 1
print(ans//2)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import Counter
import math
M = 998244353
N = int(input())
# D = list(map(int, input().split()))
counter = Counter(map(int, input().split()))
ans = counter[1]
pre_c = 1
for i, (n, c) in enumerate(sorted(counter.items())):
    if i != n:
        ans = 0
        break
    elif n <= 1 or c == 1:
        pre_c = c
        continue
    elif pre_c == 1:
        ans *= c
        pre_c = c
        continue
    ans *= (math.factorial(c) ** 2 * (c+1)) // (math.factorial(c+2 - pre_c) * math.factorial(pre_c-1)) // pre_c
    pre_c = c
print(ans % M)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import Counter
M = 998244353
N = int(input())
D = list(map(int, input().split()))
counter = Counter(D)
ans = 1
pre_c = 1
if D[0] != 0 or counter[0] != 1:
    print(0)
else:
    for i, (k, c) in enumerate(sorted(counter.items(), key=lambda x: x[0])):
        if k == 0:
            continue
        elif i != k:
            ans = 0
            break
        ans *= pre_c ** c
        pre_c = c
    print(ans%M)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ans = 0
for i in range(N):
    for j in range(i+1, N):
        Lij = L[i] + L[j]
        for k in range(j+1, N):
            if Lij <= L[k]:
                break
            ans += 1
print(ans)

Fixed submission:
import bisect
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ans = 0
for i in range(N):
    for j in range(i+1, N):
        Lij = L[i] + L[j]
        k = bisect.bisect_left(L, Lij)
        ans += max(k - j - 1, 0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def yakusu(n):
    results = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            results.append(i)
            results.append(n // i)
    return results

N = int(input())
A = list(map(int, input().split()))
is_odd = [False for i in range(N+1)]
A.insert(0, 0)
ans = []
for i in range(N, 0, -1):
    if A[i] == 1:
        if not is_odd[i]:
            ans.append(i)
            for y in set(yakusu(i)):
                is_odd[y] = not is_odd[y]
    elif A[i] == 0:
        if is_odd[i]:
            ans.append(i)
            for y in set(yakusu(i)):
                is_odd[y] = not is_odd[y]
print(len(ans))
if len(ans) != 0:
    print(' '.join(map(str, ans)))


Fixed submission:
def yakusu(n):
    results = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            results.append(i)
            results.append(n // i)
    return results

N = int(input())
A = list(map(int, input().split()))
is_odd = [False for i in range(N+1)]
A.insert(0, 0)
ans = []
for i in range(N, 0, -1):
    if A[i] == 1:
        if not is_odd[i]:
            ans.append(i)
            for y in set(yakusu(i)):
                is_odd[y] = not is_odd[y]
    elif A[i] == 0:
        if is_odd[i]:
            ans.append(i)
            for y in set(yakusu(i)):
                is_odd[y] = not is_odd[y]
print(len(ans))
if len(ans) != 0:
    print(' '.join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
m = 10 ** 9 + 7
for i in range(1, K+1):
    R = N - K - i + 1
    if i == 1:
        KC = 1
    else:
        KC = math.factorial(K-1) // math.factorial(i-1)
    ans = math.factorial(R+i) // (math.factorial(R) * math.factorial(i))
    # print(R, KC, ans)
    print((ans*KC) % m)


Fixed submission:
import math
N, K = map(int, input().split())
m = 10 ** 9 + 7
for i in range(1, K+1):
    R = N - K - i + 1
    if i == 1:
        KC = 1
    else:
        KC = math.factorial(K-1) // math.factorial(i-1) // math.factorial(K-i)
    if R < 0:
        ans = 0
    else:
        ans = math.factorial(R+i) // (math.factorial(R) * math.factorial(i))
    print((ans*KC) % m)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
xy = sorted(xy, key=lambda x: x[0])
counter = Counter()
for i in range(1, N):
    nxy = xy[i]
    pxy = xy[i-1]
    counter[(nxy[0]-pxy[0], nxy[1]-pxy[1])] += 1

print(N-counter.most_common(1)[0][1])


Fixed submission:
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
# xy = sorted(xy, key=lambda x: x[0])
counter = Counter()
for i in range(N):
    for j in range(i+1, N):
        nxy = xy[i]
        pxy = xy[j]
        counter[(nxy[0]-pxy[0], nxy[1]-pxy[1])] += 1
        counter[(pxy[0]-nxy[0], pxy[1]-nxy[1])] += 1
# print(counter)
if N == 1:
    print(1)
else:
    print(N-counter.most_common(1)[0][1])
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
ans = 0
ls = len(s)
i = 0
while i < ls-2:
    if s[i:i+3] == ['A', 'B', 'C']:
        ans += 1
        s[i:i+3] = ['B', 'C', 'A']
        i -= 1
        continue
    i += 1
print(ans)


Fixed submission:
s = list(input())
ans = 0
ls = len(s)
i = 0
ca = 0
while i < ls-2:
    if s[i:i+3] == ['A', 'B', 'C']:
        ans += 1 + ca
        # print(i, ans, ca)
        s[i+2] = 'A'
        if ca >= 1:
            ca -= 2
            s[i+1] = 'A'
        else:
            ca = 0
        continue
    elif s[i] == 'A':
        ca += 1
    else:
        ca = 0
    i += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
ans = 0
ls = len(s)
i = 0
while i < ls-2:
    abc = s[i:i+3]
    if abc == ['A', 'B', 'C']:
        ans += 1
        s[i:i+3] = ['B', 'C', 'A']
        i -= 1
        continue
    i += 1
print(ans)


Fixed submission:
s = list(input())
ans = 0
ls = len(s)
i = 0
ca = 0
while i < ls-2:
    if s[i:i+3] == ['A', 'B', 'C']:
        ans += 1 + ca
        # print(i, ans, ca)
        s[i+2] = 'A'
        if ca >= 1:
            ca -= 2
            s[i+1] = 'A'
        else:
            ca = 0
        continue
    elif s[i] == 'A':
        ca += 1
    else:
        ca = 0
    i += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
ans = 0
ls = len(s)
i = 0
while i < ls-2:
    abc = s[i:i+3]
    if abc == ['A', 'B', 'C']:
        ans += 1
        s[i:i+3] = ['B', 'C', 'A']
        i -= 1
        continue
    i += 1
print(ans)


Fixed submission:
s = list(input())
ans = 0
ls = len(s)
i = 0
ca = 0
while i < ls-2:
    if s[i:i+3] == ['A', 'B', 'C']:
        ans += 1 + ca
        # print(i, ans, ca)
        s[i+2] = 'A'
        if ca >= 1:
            ca -= 2
            s[i+1] = 'A'
        else:
            ca = 0
        continue
    elif s[i] == 'A':
        ca += 1
    else:
        ca = 0
    i += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
c = 1
while c > 0:
    c = s.count('ABC')
    ans += c
    s = s.replace('ABC', 'BCA')
# print(s)
print(ans)


Fixed submission:
s = list(input())
ans = 0
ls = len(s)
i = 0
ca = 0
while i < ls-2:
    if s[i:i+3] == ['A', 'B', 'C']:
        ans += 1 + ca
        # print(i, ans, ca)
        s[i+2] = 'A'
        if ca >= 1:
            ca -= 2
            s[i+1] = 'A'
        else:
            ca = 0
        continue
    elif s[i] == 'A':
        ca += 1
    else:
        ca = 0
    i += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ans = 0
c = 1
while c > 0:
    c = s.count('ABC')
    ans += c
    s = s.replace('ABC', 'BCA')
# print(s)
print(ans)


Fixed submission:
s = list(input())
ans = 0
ls = len(s)
i = 0
ca = 0
while i < ls-2:
    if s[i:i+3] == ['A', 'B', 'C']:
        ans += 1 + ca
        # print(i, ans, ca)
        s[i+2] = 'A'
        if ca >= 1:
            ca -= 2
            s[i+1] = 'A'
        else:
            ca = 0
        continue
    elif s[i] == 'A':
        ca += 1
    else:
        ca = 0
    i += 1

print(ans)