Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

MOD = 10**9+7
def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%MOD
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], MOD -2, MOD)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % MOD
    return frac, fraci
frac, fraci = frac(1341398)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%MOD

K = int(readline())
S = len(readline().strip())
ans = 0

M = 1341398
A = [1]*M
B = [1]*M
for i in range(1, M):
    A[i] = (A[i-1]*25)%MOD
    B[i] = (B[i-1]*26)%MOD

ans = 0

for i in range(K+1):
    ans = (ans+A[i]*B[K-i]*comb(i+S-1, i))%MOD

print(ans)



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

MOD = 10**9+7
def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%MOD
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], MOD -2, MOD)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % MOD
    return frac, fraci
frac, fraci = frac(2341398)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%MOD

K = int(readline())
S = len(readline().strip())
ans = 0

M = 1341398
A = [1]*M
B = [1]*M
for i in range(1, M):
    A[i] = (A[i-1]*25)%MOD
    B[i] = (B[i-1]*26)%MOD

ans = 0

for i in range(K+1):
    ans = (ans+A[i]*B[K-i]*comb(i+S-1, i))%MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int, readline().split()))

INF = 10**18
limit = 5
dpb = [-INF]*(2*limit+3)
dpw = [-INF]*(2*limit+3)
dpw[0] = 0
for i in range(N):
    a = A[i]
    dpb2 = [-INF]*N
    dpw2 = [-INF]*N
    for j in range(-limit, limit):
        if -limit <= j - 1 < limit:
            dpw2[j-1] = max(dpw2[j-1], dpb[j], dpw[j])
            dpb2[j-1] = max(dpb2[j-1], dpb[j], dpw[j])
        if -limit <= j + 1 < limit:
            dpb2[j+1] = max(dpb2[j+1], dpw[j]+a)
    dpw = dpw2[:]
    dpb = dpb2[:]

idx = N//2*2 - N
print(max(dpw[idx], dpb[idx]))
    

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

N = int(readline())
A = list(map(int, readline().split()))

INF = 10**18
limit = 4
S = (2*limit+3)
dpb = [-INF]*S
dpw = [-INF]*S
dpw[0] = 0
for i in range(N):
    a = A[i]
    dpb2 = [-INF]*S
    dpw2 = [-INF]*S
    for j in range(-limit, limit):
        if -limit <= j - 1 < limit:
            dpw2[j-1] = max(dpw2[j-1], dpb[j], dpw[j])
            dpb2[j-1] = max(dpb2[j-1], dpb[j], dpw[j])
        if -limit <= j + 1 < limit:
            dpb2[j+1] = max(dpb2[j+1], dpw[j]+a)
    dpw = dpw2[:]
    dpb = dpb2[:]

idx = N//2*2 - N
print(max(dpw[idx], dpb[idx]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline
from decimal import Decimal, getcontext
getcontext().prec = 10000
A, B, C = map(Decimal, readline().split())
half = Decimal(0.5)
print('Yes' if A**half + B**half < C**half else 'No')

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

a, b, c = map(int, readline().split())
print('Yes' if 4*a*b < (c-a-b)**2 and (c-a-b) > 0 else 'No')

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline
from decimal import Decimal, getcontext
getcontext().prec = 100000
A, B, C = map(Decimal, readline().split())
half = Decimal(0.5)
print('Yes' if A**half + B**half < C**half else 'No')

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

a, b, c = map(int, readline().split())
print('Yes' if 4*a*b < (c-a-b)**2 and (c-a-b) > 0 else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

K, Q = map(int, readline().split())

D = list(map(int, readline().split()))

Ans = [None]*Q
for q in range(Q):
    n, x, mod = map(int, readline().split())
    D2 = [d%mod for d in D]
    res = x + ((n-1)//K)*sum(D2)
    zero = ((n-1)//K)*D2.count(0)
    for i in range((n-1)%K):
        res += D2[i]
        if not D2[i]:
            zero += 1
    minus = res//mod - x//mod
    Ans[q] = n-1 - zero - minus
print('\n'.join(map(str, Ans)))

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

K, Q = map(int, readline().split())

D = list(map(int, readline().split()))

Ans = [None]*Q
for q in range(Q):
    n, x, mod = map(int, readline().split())
    x%= mod
    D2 = [d%mod for d in D]
    res = 0
    cnt = 0
    zero = 0
    for d2 in D2:
        res += d2
        if res > mod:
            cnt += 1
            res -= mod
        if not d2:
            zero += 1
    
    loop =  ((n-1)//K)
    minus = loop*cnt
    zero *= loop
    res2 = 0
    for i in range((n-1)%K):
        res2 += D2[i]
        if not D2[i]:
            zero += 1
        if res > mod:
            res -= mod
            minus += 1
    minus += (x%mod + loop*res + res2)//mod
    Ans[q] = n-1 - zero - minus
print('\n'.join(map(str, Ans)))
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

def count(A, B, x):
    N = len(A)
    M = len(B)
    res = 0
    r = -1
    for l in range(N):
        a = A[l]
        while r < M-1 and B[r+1]*a <= x:
            r += 1
        res += r+1
    return res

def count2(A, x):
    res = 0
    for a in A:
        if a*a <= x:
            res += 1
    return res
        

N, K = map(int, readline().split())
A = list(map(int, readline().split()))
Am = []
Ap = []

minus = 0
zero = 0
plus = 0
for a in A:
    if a < 0:
        minus += 1
        Am.append(-a)
    elif a == 0:
        zero += 1
    else:
        plus += 1
        Ap.append(a)

ms = minus*plus
zs = ms + zero*(minus+plus) + zero*(zero-1)//2

Am.sort()
Ap.sort()
Amr = Am[::-1]
Apr = Ap[::-1]

if K <= ms:
    K = ms+1-K
    ok = max(max(Am), max(Ap))**2
    ng = 0
    while abs(ok-ng)>1:
        med = (ok+ng)//2
        if count(Amr, Ap, med) >= K:
            ok = med
        else:
            ng = med
    ans = -ok
elif K <= zs:
    ans = 0
else:
    K -= zs
    ok = max(max(Am), max(Ap))**2
    ng = 0
    while abs(ok-ng)>1:
        med = (ok+ng)//2
        if (count(Amr, Am, med) + count(Apr, Ap, med) - count2(Am, med) - count2(Ap, med))//2 >= K:
            ok = med
        else:
            ng = med
    ans = ok

print(ans)
    
    



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

def count(A, B, x):
    N = len(A)
    M = len(B)
    res = 0
    r = -1
    for l in range(N):
        a = A[l]
        while r < M-1 and B[r+1]*a <= x:
            r += 1
        res += r+1
    return res

def count2(A, x):
    res = 0
    for a in A:
        if a*a <= x:
            res += 1
    return res
        

N, K = map(int, readline().split())
A = list(map(int, readline().split()))
Am = []
Ap = []

minus = 0
zero = 0
plus = 0
for a in A:
    if a < 0:
        minus += 1
        Am.append(-a)
    elif a == 0:
        zero += 1
    else:
        plus += 1
        Ap.append(a)

ms = minus*plus
zs = ms + zero*(minus+plus) + zero*(zero-1)//2

Am.sort()
Ap.sort()
Amr = Am[::-1]
Apr = Ap[::-1]

if K <= ms:
    K = ms+1-K
    ok = max(max(Am+[0]), max(Ap+[0]))**2
    ng = 0
    while abs(ok-ng)>1:
        med = (ok+ng)//2
        if count(Amr, Ap, med) >= K:
            ok = med
        else:
            ng = med
    ans = -ok
elif K <= zs:
    ans = 0
else:
    K -= zs
    ok = max(max(Am+[0]), max(Ap+[0]))**2
    ng = 0
    while abs(ok-ng)>1:
        med = (ok+ng)//2
        if (count(Amr, Am, med) + count(Apr, Ap, med) - count2(Am, med) - count2(Ap, med))//2 >= K:
            ok = med
        else:
            ng = med
    ans = ok

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

MOD = 10**9+7
def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%MOD
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], MOD -2, MOD)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % MOD
    return frac, fraci
frac, fraci = frac(1341398)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%MOD

def accumulate2d(X2):
    X = X2
    N = len(X)
    M = len(X[0])
    
    for i in range(N):
        for j in range(1, M):
            X[i][j] += X[i][j-1]
    
    for j in range(M):
        for i in range(1, N):
            X[i][j] += X[i-1][j]
    
    return X

r1, c1, r2, c2 = map(int, readline().split())

def calc(R, C):
    if min(R, C) == 0:
        return 1
    res = R
    for i in range(1, C):
        res = (res + comb(R+i, i+1)) % MOD
    return res
r2 += 1
c2 += 1
print((calc(r2, c2)-calc(r2, c1)-calc(r1, c2)+calc(r1, c1))%MOD)

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

MOD = 10**9+7
def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%MOD
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], MOD -2, MOD)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % MOD
    return frac, fraci
frac, fraci = frac(2341398)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%MOD

def accumulate2d(X2):
    X = X2
    N = len(X)
    M = len(X[0])
    
    for i in range(N):
        for j in range(1, M):
            X[i][j] += X[i][j-1]
    
    for j in range(M):
        for i in range(1, N):
            X[i][j] += X[i-1][j]
    
    return X

r1, c1, r2, c2 = map(int, readline().split())

def calc(R, C):
    if min(R, C) == 0:
        return 1
    res = R
    for i in range(1, C):
        res = (res + comb(R+i, i+1)) % MOD
    return res
r2 += 1
c2 += 1
print((calc(r2, c2)-calc(r2, c1)-calc(r1, c2)+calc(r1, c1))%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

MOD = 10**9+7
def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%MOD
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], MOD -2, MOD)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % MOD
    return frac, fraci
frac, fraci = frac(41398)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%MOD


N, K = map(int, readline().split())
A = list(map(int, readline().split()))

dp = [0]*(N+1)
dp[0] = 1

for i in range(K):
    a = A[i]
    dp2 = [0]*(N+1)
    for j in range(N+1):
        d = dp[j]
        for k in range(min(a, N-j)+1):
            dp2[j+k] = (dp2[j+k] + d*comb(N-j, k)*comb(N-k, a-k)) %MOD
    dp = dp2[:]
print(dp[N])


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

MOD = 10**9+7
def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%MOD
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], MOD -2, MOD)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % MOD
    return frac, fraci
frac, fraci = frac(1398)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%MOD


N, K = map(int, readline().split())
A = list(map(int, readline().split()))

dp = [0]*(N+1)
dp[0] = 1

for i in range(K):
    a = A[i]
    dp2 = [0]*(N+1)
    for j in range(N+1):
        d = dp[j]
        if not d:
            continue
        for k in range(min(a, N-j)+1):
            dp2[j+k] = (dp2[j+k] + d*comb(N-j, k)*comb(N-k, a-k)) %MOD
    dp = dp2[:]
print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

MOD = 10**9+7
N = int(readline())
C = list(map(int, readline().split()))
C.sort()

ans = 0
for i in range(N):
    ans = (ans + pow(2, 2*N-2)*C[i]*(N-i+1))%MOD
print(ans)


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

MOD = 10**9+7
N = int(readline())
C = list(map(int, readline().split()))
C.sort()

ans = 0
for i in range(N):
    ans = (ans + pow(2, 2*N-2, MOD)*C[i]*(N-i+1))%MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
    for _ in range(test_case):
import sys
readline = sys.stdin.readline

N, A, B = map(int, readline().split())

ans = None
if (B - A) % 2 == 0:
    ans = (B-A)//2
else:
    ans = A + (B - A - 1)//2
    ans = min(ans, N-B+1 + (-A+B-1)//2)    
print(ans)
    

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

N, A, B = map(int, readline().split())

ans = None
if (B - A) % 2 == 0:
    ans = (B-A)//2
else:
    ans = A + (B - A - 1)//2
    ans = min(ans, N-B+1 + (-A+B-1)//2)    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
from operator import mul
from functools import reduce
readline = sys.stdin.readline

#エラトステネスの篩と素因数分解

M = 10**6 + 3
prime = [0]*M
for i in range(2, M):
    if prime[i]:
        continue
    for j in range(i, M, i):
        if not prime[j]:
            prime[j] = i

def pd(x):
    C = Counter()
    while x > 1:
        C[prime[x]] += 1
        x //= prime[x]
    return C

MOD = 998244353
N = int(readline())
A = list(map(int, readline().split()))
C = Counter(A)
mA = max(A) + 1
table = [0]*mA
table2 = [0]*mA
T = [0]*mA
i2 = pow(2, MOD-2, MOD)

for k in A:
    pk = pd(k)
    lk = list(pk.keys())
    lv = [v+1 for v in pk.values()]
    ll = len(pk)
    for s in range(reduce(mul, lv, 1)):
        res = 1
        for idx in range(ll):
            res *= pow(lk[idx], s%lv[idx])
            s //= lv[idx]
        table[res] += k
        table2[res] += k*k

T = [(x1*x1-x2)*i2%MOD for x1, x2 in zip(table, table2)]

ans = 0
coeff = [0]*mA
for i in range(1, mA):
    
    k = T[i]
    l = - coeff[i] + pow(i, MOD-2, MOD)
    ans = (ans+l*k)%MOD
    for j in range(2*i, mA, i):
        coeff[j] = (coeff[j] + l)%MOD
print(ans)

Fixed submission:
import sys
readline = sys.stdin.readline    
MOD = 998244353
N = int(readline())
A = list(map(int, readline().split()))
mA = max(A) + 1
T = [0]*mA
i2 = pow(2, MOD-2, MOD)


table = [0]*mA
table2 = [0]*mA
for a in A:
    table[a] = (table[a] + a)%MOD
    table2[a] = (table2[a] + a*a)%MOD
prime = [True]*mA
for p in range(2, mA):
    if not prime[p]:
        continue
    for k in range((mA-1)//p, 0, -1):
        table[k] = (table[k] + table[k*p])%MOD
        table2[k] = (table2[k] + table2[k*p])%MOD
        prime[k*p] = False

T = [(x1*x1-x2)*i2%MOD for x1, x2 in zip(table, table2)]

ans = 0
coeff = [0]*mA
for i in range(1, mA):
    k = T[i]
    l = - coeff[i] + pow(i, MOD-2, MOD)
    ans = (ans+l*k)%MOD
    for j in range(2*i, mA, i):
        coeff[j] = (coeff[j] + l)%MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
mod = 10**9+7

def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%mod
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], mod -2, mod)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % mod
    return frac, fraci
frac, fraci = frac(10000)

def count(S):
    res = 1
    cnt = 0
    for s in S:
        if s:
            cnt += 1
        else:
            res = (res*cnt)%mod
            cnt -= 1
    
    return res
N = int(input())
S = [1 if s == 'B' else 0 for s in input().strip()]
L = 2*N
S = [(S[i] + i)%2 for i in range(L)]
print(count(S)*frac[N]%mod)


Fixed submission:
mod = 10**9+7

def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%mod
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], mod -2, mod)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % mod
    return frac, fraci
frac, fraci = frac(200000)

def count(S):
    res = 1
    cnt = 0
    for s in S:
        if s:
            cnt += 1
        else:
            res = (res*cnt)%mod
            cnt -= 1
        if cnt < 0:
            return 0
    return res
N = int(input())
S = [1 if s == 'B' else 0 for s in input().strip()]
L = 2*N
S = [(S[i] + i)%2 for i in range(L)]
if sum(S) != N:
    print(0)
else:
    print(count(S)*frac[N]%mod)
Buggy python submission (verdict: Runtime Error):
mod = 10**9+7
N, K = map(int, input().split())
if K % 2:
    print(0)
else:
    dp = [[[0]*(2*N**2) for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        for k in range(i+2):
            for S in range(-N**2+1, N**2):
                d = dp[i][k][S]
                if not d:
                    continue
                dp[i+1][k][S] = (dp[i+1][k][S]+(2*k+1)*d)%mod
                dp[i+1][k+1][S-2*(i+1)] = (dp[i+1][k+1][S-2*(i+1)]+d)%mod
                dp[i+1][k-1][S+2*(i+1)] = (dp[i+1][k-1][S+2*(i+1)]+k*k*d)%mod
    print(dp[N][0][K])

Fixed submission:
mod = 10**9+7
N, K = map(int, input().split())
if K % 2:
    print(0)
else:
    dp = [[[0]*(2*N**2+2*N) for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        for k in range(i+2):
            for S in range(-N**2+1, N**2):
                d = dp[i][k][S]
                if not d:
                    continue
                dp[i+1][k][S] = (dp[i+1][k][S]+(2*k+1)*d)%mod
                dp[i+1][k+1][S-2*(i+1)] = (dp[i+1][k+1][S-2*(i+1)]+d)%mod
                dp[i+1][k-1][S+2*(i+1)] = (dp[i+1][k-1][S+2*(i+1)]+k*k*d)%mod
    print(dp[N][0][K])
Buggy python submission (verdict: Runtime Error):
from itertools import combinations
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
X, Y = list(map(list, zip(*XY)))

P = [abs(x1 - x2) for x1, x2 in combinations(X, 2)]
P = list(set(P))
Q = [abs(y1 - y2) for y1, y2 in combinations(Y, 2)]
Q = list(set(Q))
ans = 10**10
XY.sort()
for p in P:
    for q in Q:
        S = set()
        la = 0
        for x, y in XY:
            if (x, y) not in S:
                la += 1
            S.add((x+p, y+q))
        ans = min(ans, la)
        S = set()
        la = 0
        for x, y in XY:
            if (x, y) not in S:
                la += 1
            S.add((x+p, y-q))
        ans = min(ans, la)
print(ans)

Fixed submission:
N, K = map(int, input().split())
if K == 1:
    print(0)
else:
    print(N-K)
Buggy python submission (verdict: Runtime Error):
import sys
N, X = map(int, input().split())
BLU = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
B, L, U = map(list, zip(*BLU))
C = [(u-l)*b for b, l, u in BLU]
D = [(X*u - c, u, c, l) for u, c, l in zip(U, C, L)]
D.sort(reverse = True)
SL = sum(l*b for l, b in zip(L, B))
SS = 0
for i, (d, _, _, _) in enumerate(D):
    SS += d
    if SS >= SL:
        break
SSb = SS - d
lans = i*X
m = 10**10
for _, u, c, l in D[i:]:
    m = min(m, -(-(c + SL - SSb)//u), -((SSb - SL)//l))
lans += m

ans = (i+1) * X
m = 0
for _, u, _, _ in D[:i+1]:
    m = max(m, -(-(SS - SL))//u)
print(min(lans, ans - m))

Fixed submission:
N, A, B, C, D =  map(int, input().split())
S = input()
S = [False] + [s == '.' for s in S] + [False]
def check(s, t):
    i = s
    for _ in range(s, t+1):
        if i + 1 == t or i + 2 == t:
            return True
        if S[i+2]:
            i += 2
            continue
        if S[i+1]:
            i += 1
            continue
        return False

def checki(s, t):
    for i in range(s, t+1):
        if S[i-1] and S[i] and S[i+1]:
            return True
    return False



if A < B < D < C:
    if not check(B, D) or not check(A, C):
        print('No')
    elif checki(B, D):
        print('Yes')
    else:
        print('No')
else:
    if check(A, C) and check(B, D):
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
def count(S):
    p = 0
    res = 0
    for s in S:
        if s == '0':
            p += 1
        else:
            res += p
    return res

S = input().strip()
a = '0'
b = 1
bc = '1'
x = '2'
T = ''
stack = []
for s in S:
    if s == 'A':
        if stack:
            T += x
        stack = []
        T += a
    elif s == 'B':
        stack.append(b)
    elif s == 'C':
        if stack and stack[-1] == b:
            stack.pop()
            if stack:
                T += x
            T += bc
        else:
            stack.append(x)
ans = 0
for g in T.split(x):
    ans += count(g)
print(ans)

Fixed submission:
def count(S):
    p = 0
    res = 0
    for s in S:
        if s == '0':
            p += 1
        else:
            res += p
    return res

S = input().strip()
a = '0'
b = 1
bc = '1'
x = '2'
T = ''
stack = []
for s in S:
    if s == 'A':
        if stack:
            T += x
        stack = []
        T += a
    elif s == 'B':
        stack.append(b)
    elif s == 'C':
        if stack and stack[-1] == b:
            stack.pop()
            if stack:
                T += x
            T += bc
        else:
            stack.append(x)
ans = 0
for g in T.split(x):
    ans += count(g)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
Q = int(input())
mod = 1000003
frac = [1]*1000003
for i in range(2,1000003):
    frac[i] = i * frac[i-1]%mod
for _ in range(Q):
    x, d, n = map(int, sys.stdin.readline().split())
    p = pow(d, mod-2, mod)*x % mod
    print(frac[p+n-1]*pow(frac[p-1], mod-2, mod)*pow(d, n, mod)%mod)


Fixed submission:
N = int(input())
print((N-2)*180)
Buggy python submission (verdict: Runtime Error):
import sys
Q = int(input())
mod = 1000003
frac = [1]*1000003
for i in range(2,1000003):
    frac[i] = i * frac[i-1]%mod
for _ in range(Q):
    x, d, n = map(int, sys.stdin.readline().split())
    p = pow(d, mod-2, mod)*x % mod
    if d == 0:
        print(pow(x, n, mod))
    elif x == 0:
        print(0)
    elif p == 0:
        print(0)
        continue
    elif p + n - 1 >= mod:
        print(0)
        continue
    
    print(frac[p+n-1]*pow(frac[p-1], mod-2, mod)*pow(d, n, mod)%mod)

Fixed submission:
import sys
Q = int(input())
mod = 1000003
frac = [1]*1000003
for i in range(2,1000003):
    frac[i] = i * frac[i-1]%mod
for _ in range(Q):
    x, d, n = map(int, sys.stdin.readline().split())
    p = pow(d, mod-2, mod)*x % mod
    if d == 0:
        print(pow(x, n, mod))
        continue
    elif x == 0:
        print(0)
        continue
    elif p == 0:
        print(0)
        continue
    elif p + n - 1 >= mod:
        print(0)
        continue
    
    print(frac[p+n-1]*pow(frac[p-1], mod-2, mod)*pow(d, n, mod)%mod)

Buggy python submission (verdict: Runtime Error):
import sys
Q = int(input())
mod = 1000003
frac = [1]*1000003
for i in range(2,1000003):
    frac[i] = i * frac[i-1]%mod
for _ in range(Q):
    x, d, n = map(int, sys.stdin.readline().split())
    p = pow(d, mod-2, mod)*x % mod
    print(frac[p+n-1]*pow(frac[p-1], mod-2, mod)*pow(d, n, mod)%mod)


Fixed submission:
import sys
Q = int(input())
mod = 1000003
frac = [1]*1000003
for i in range(2,1000003):
    frac[i] = i * frac[i-1]%mod
for _ in range(Q):
    x, d, n = map(int, sys.stdin.readline().split())
    p = pow(d, mod-2, mod)*x % mod
    if d == 0:
        print(pow(x, n, mod))
        continue
    elif x == 0:
        print(0)
        continue
    elif p == 0:
        print(0)
        continue
    elif p + n - 1 >= mod:
        print(0)
        continue
    
    print(frac[p+n-1]*pow(frac[p-1], mod-2, mod)*pow(d, n, mod)%mod)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left as bl
import sys
N, Q = map(int, input().split())
stx = [tuple(map(int, sys.stdin.readline().split()))[::-1] for _ in range(N)]

stx.sort()

D = [int(sys.stdin.readline()) for _ in range(Q)] 
A = [0]*Q
X = [0]*N
for i, (x, t, s) in enumerate(stx):
    il = bl(D, s-x)
    ir = bl(D, t-x)
    A[il] += 2**i
    A[ir] += 2**i
    X[i] = x
for i in range(1, Q):
    A[i] = A[i]^A[i-1]
for a in A:
    if not a:
        print(-1)
    else:
        print(X[(a & -a).bit_length() - 1])

Fixed submission:
from heapq import heappop as hpp, heappush as hp
import sys
N, Q = map(int, input().split())
stx = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
stx = [(s-x, t-x, x) for s, t, x in stx]
stx.sort(reverse = True)

D = [int(sys.stdin.readline()) for _ in range(Q)] 
H = []
ans = [None]*Q

for i, d in enumerate(D):
    while stx and stx[-1][0] <= d:
        hp(H, stx.pop()[1:][::-1])    
    while H and H[0][1] <= d:
        hpp(H)
    if not H:
        ans[i] = -1
    else:
        ans[i] = H[0][0]

for a in ans:
    print(a)