Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
factors = []

while N % 2 == 0:
    factors.append(2)
    N //= 2
f = 3
while f*f <= N:
    if N % f == 0:
        factors.append(f)
        N //= f
    else:
        f += 2

if not factors:
    print(N-1)
else:
    if N > 1:
        factors.append(N)

    n = len(factors)
    sums = []
    for i in range(1, n**2-1):
        l = 1
        r = 1
        for j in range(n):
            if (i >> j) & 1:
                l *= factors[j]
            else:
                r *= factors[j]
        sums.append(l-1 + r-1)
    print(min(sums))

Fixed submission:
import math
N = int(input())

minlen = 10**12
for i in range(1, int(math.sqrt(N))+1):
    if N%i == 0:
        minlen = min(minlen, i + N//i - 2)

if minlen == 10**9:
    print(N-1)
else:
    print(minlen)
Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
vs = a*a*b
rem = vs - x
if rem > x:
    y = 2*x/(a*b)
    theta = math.degrees(math.atan2(b, y))
    print(theta)
else:
    y = 2*rem/(a*a)
    theta = math.degrees(math.atan2(y, a))
    print(theta)

Fixed submission:
import math
a, b, x = map(int, input().split())
vs = a*a*b
rem = vs - x
if rem > x:
    y = 2*x/(a*b)
    theta = math.degrees(math.atan2(b, y))
    print(theta)
else:
    y = 2*rem/(a*a)
    theta = math.degrees(math.atan2(y, a))
    print(theta)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = tuple(map(int, input().split()))
F = tuple(map(int, input().split()))

if sum(A) <= K:
    print(0)
else:
    def solve(N, K, A, F):
        A = sorted(A)
        F = sorted(F, reverse=True)
        l = -1
        r = 10**12
        while (r - l) > 1:
            mid = (r + l) // 2
            # 成績がmidだったとして、修行しなければならない回数を算出
            fmid = sum([max(0, a - (mid // f)) for a, f in zip(A, F)])
            if fmid <= K:
                r = mid
            else:
                l = mid
        return(r)
    print(solve(N, K, A, F))

Fixed submission:
import numpy as np
N, K = map(int, input().split())
A = np.array(tuple(map(int, input().split())))
F = np.array(tuple(map(int, input().split())))

if sum(A) <= K:
    print(0)
else:
    def solve(N, K, A, F):
        A = np.sort(A)
        F = np.sort(F)[::-1]
        l = -1
        r = 10**12
        while (r - l) > 1:
            mid = (r + l) // 2
            # 成績がmidだったとして、修行しなければならない回数を算出
            fmid = (np.fmax([0]*N, A - (mid // F))).sum()
            if fmid <= K:
                r = mid
            else:
                l = mid
        return(r)
    print(solve(N, K, A, F))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = tuple(map(int, input().split()))
F = tuple(map(int, input().split()))

if sum(A) <= K:
    print(0)
else:
    A = sorted(A)
    F = sorted(F, reverse=True)
    l = -1
    r = 10**12
    while (r - l) > 1:
        mid = (r + l) // 2
        # 成績がmidだったとして、修行しなければならない回数を算出
        fmid = sum([max(0, a - (mid // f)) for a, f in zip(A, F)])
        if fmid <= K:
            r = mid
        else:
            l = mid
    print(r)


Fixed submission:
import numpy as np
N, K = map(int, input().split())
A = np.array(tuple(map(int, input().split())))
F = np.array(tuple(map(int, input().split())))

if sum(A) <= K:
    print(0)
else:
    def solve(N, K, A, F):
        A = np.sort(A)
        F = np.sort(F)[::-1]
        l = -1
        r = 10**12
        while (r - l) > 1:
            mid = (r + l) // 2
            # 成績がmidだったとして、修行しなければならない回数を算出
            fmid = (np.fmax([0]*N, A - (mid // F))).sum()
            if fmid <= K:
                r = mid
            else:
                l = mid
        return(r)
    print(solve(N, K, A, F))
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(lambda x:int(x)-1, input().split())
    G[a].append(b)

points = [0] * N 
for _ in range(Q):
    p, x = map(int, input().split())
    points[p-1] += x

from collections import deque
st = deque([[0, points[0]]])
result = [0] * N
while st:
    idx, count = st.pop()
    result[idx] = str(count)
    for ni in G[idx]:
        st.append([ni, count+points[ni]])

print(" ".join(result))

Fixed submission:
N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(lambda x:int(x)-1, input().split())
    G[a].append(b)
    G[b].append(a)

points = [0] * N 
for _ in range(Q):
    p, x = map(int, input().split())
    points[p-1] += x

from collections import deque
st = deque([[0, points[0]]])
result = ['0'] * N
visited = [0] * N
visited[0] = 1
while st:
    idx, count = st.pop()
    result[idx] = str(count)
    for ni in G[idx]:
        if visited[ni] != 1:
            visited[ni] = 1
            st.append([ni, count+points[ni]])

print(" ".join(result))
Buggy python submission (verdict: Runtime Error):
def resolve():
n, m = map(int, input().split())
denq = []
for _ in range(m):
    ks = tuple(map(lambda x: int(x)-1, input().split()))
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    kk = [0] * m
    # switch_states = [(i>>j)&1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += (i>>s)&1
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)


Fixed submission:
N, M = map(int, input().split())
ds = []
for _ in range(M):
    ds.append(tuple(map(int, input().split()))[1::])
    
P = tuple(map(int, input().split()))

# スイッチのon/offについて全探索
oks = 0
for i in range(2**N):
    switch_states = [(i>>j)&1 for j in range(N)]
    # すべての電球について
    for di, d in enumerate(ds):
        # 関連するスイッチがonの個数を数える
        switch_counts = 0
        for s in d:
            switch_counts += switch_states[s-1]
        if switch_counts%2 != P[di]:
            break
    else:
        oks += 1
print(oks)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
n = int(input())
A = tuple(map(int, input().split()))

from collections import deque
q = deque([])
q.append([0, A[0], False])
q.append([1, A[1], True])
# 深さ優先探索
# idx, これまでのGCD, 抜いたか抜いてないか
ans = 0
while q:
    idx, g, jogai = q.pop()
    if g <= ans:
        continue
    if idx == n-1:
        ans = max(ans, g)
        continue

    q.append([idx+1, gcd(g, A[idx+1]), jogai])
    if not jogai:
        q.append([idx+1, g, True])
print(ans)

Fixed submission:
from math import gcd
n = int(input())
A = list(map(int, input().split()))

# 以降のGCD
left_gcds = [A[0]]
for a in A[1:]:
    left_gcds.append(gcd(left_gcds[-1], a))

right_gcds = [A[-1]]
for a in A[:n-1][::-1]:
    right_gcds.append(gcd(right_gcds[-1], a))
right_gcds.reverse()

ans = 0
for i in range(n):
    if i == 0:
        tmp = right_gcds[i+1]
    elif i == n-1:
        tmp =left_gcds[i-1]
    else:
        tmp = gcd(left_gcds[i-1], right_gcds[i+1])
    ans = max(ans, tmp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
n = int(input())
A = tuple(map(int, input().split()))

from collections import deque
q = deque([])
q.append([0, A[0], False])
q.append([1, A[1], True])
# 深さ優先探索
# idx, これまでのGCD, 抜いたか抜いてないか
ans = 0
while q:
    idx, g, jogai = q.pop()
    if idx == n-1:
        ans = max(ans, g)
        continue

    q.append([idx+1, gcd(g, A[idx+1]), jogai])
    if not jogai:
        q.append([idx+1, g, True])
print(ans)


Fixed submission:
from math import gcd
n = int(input())
A = list(map(int, input().split()))

# 以降のGCD
left_gcds = [A[0]]
for a in A[1:]:
    left_gcds.append(gcd(left_gcds[-1], a))

right_gcds = [A[-1]]
for a in A[:n-1][::-1]:
    right_gcds.append(gcd(right_gcds[-1], a))
right_gcds.reverse()

ans = 0
for i in range(n):
    if i == 0:
        tmp = right_gcds[i+1]
    elif i == n-1:
        tmp =left_gcds[i-1]
    else:
        tmp = gcd(left_gcds[i-1], right_gcds[i+1])
    ans = max(ans, tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import re
n, q = map(int, input().split())
S = input()
for _ in range(q):
    l, r = map(int, input().split())
    SS = S[l-1:r]
    rl = re.findall(r'AC', SS)
    print(len(rl))



Fixed submission:
n, q = map(int, input().split())
S = input()
CS = [0]
cur = 0
for i in range(1, n):
    if S[i-1] + S[i] == 'AC':
        cur += 1
        CS.append(cur)
    else:
        CS.append(cur)

for _ in range(q):
    l, r = map(int, input().split())
    print(CS[r-1] - CS[l-1])
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
bits = []
for i in range(b.bit_length()):
    k = pow(2, i+1)
    nb, rb = divmod(b, k)
    na, ra = divmod(max(0,a-1), k)

    bb = nb*(k//2) + max(0, rb - k//2 + 1)
    aa = na*(k//2) + max(0, ra - k//2 + 1)
    bits.append((bb-aa)%2)
print(int(''.join(map(str, bits[::-1])), 2))


Fixed submission:
a, b = map(int, input().split())
if a == b:
    print(a)
else:
    bits = []
    for i in range(b.bit_length()):
        k = pow(2, i+1)
        nb, rb = divmod(b, k)
        na, ra = divmod(max(0,a-1), k)

        bb = nb*(k//2) + max(0, rb - k//2 + 1)
        aa = na*(k//2) + max(0, ra - k//2 + 1)
        bits.append((bb-aa)%2)
    # print(bits)
    print(int(''.join(map(str, bits[::-1])), 2))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = tuple(map(int, input().split()))

if K >= N:
    print(abs(H[0] - H[N-1]))
else:
    dp = [abs(H[0] - H[i]) for i in range(K)] + [10**9] * (N - K)

    for i in range(K, N):
        for j in range(1, K+1):
            dp[i]= min(dp[i], dp[i-j] + abs(H[i] - H[i-j]))

    print(dp[-1])

Fixed submission:
N, K = map(int, input().split())
H = tuple(map(int, input().split()))

if K >= N:
    print(abs(H[0] - H[N-1]))
else:
    dp = [abs(H[0] - H[i]) for i in range(K)] + [10**9] * (N - K)

    for i in range(K, N):
        for j in range(1, K+1):
            dp[i]= min(dp[i], dp[i-j] + abs(H[i] - H[i-j]))

    print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = tuple(map(int, input().split()))

if K >= N:
    print(abs(H[0] - H[N-1]))
else:
    dp = [abs(H[0] - H[i]) for i in range(K)] + [0] * (N - K)

    for i in range(K, N):
        min_cost = 10**9            
        for j in range(1, K+1):
            cost = dp[i-j] + abs(H[i] - H[i-j])
            min_cost = min(min_cost, cost)
        dp[i] = min_cost

    print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
H = tuple(map(int, input().split()))

if K >= N:
    print(abs(H[0] - H[N-1]))
else:
    dp = [abs(H[0] - H[i]) for i in range(K)] + [10**9] * (N - K)

    for i in range(K, N):
        for j in range(1, K+1):
            dp[i]= min(dp[i], dp[i-j] + abs(H[i] - H[i-j]))

    print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = tuple(map(int, input().split()))

if K >= N:
    print(abs(H[0] - H[N-1]))
else:
    dp = [abs(H[0] - H[i]) for i in range(K)] + [0] * (N - K)
    for i in range(K, N):
        dp[i] = min([dp[i-j] + abs(H[i] - H[i-j]) for j in range(1, K+1)])

    print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
H = tuple(map(int, input().split()))

if K >= N:
    print(abs(H[0] - H[N-1]))
else:
    dp = [abs(H[0] - H[i]) for i in range(K)] + [10**9] * (N - K)

    for i in range(K, N):
        for j in range(1, K+1):
            dp[i]= min(dp[i], dp[i-j] + abs(H[i] - H[i-j]))

    print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m, Q = map(int, input().split())

ts = [[0] * (n+1) for _ in range(n+1)]
for _ in range(m):
    l, r = tuple(map(int, input().split()))
    ts[l][r] += 1

from itertools import accumulate
tsa = [list(accumulate(t)) for t in ts]

for _ in range(Q):
    p, q = tuple(map(int, input().split()))
    c = 0
    for i in range(p, q+1):
        c += tsa[i][q] - tsa[i][p-1]
    print(c)

Fixed submission:
n, m, Q = map(int, input().split())

ts = [[0] * (n+1) for _ in range(n+1)]
for _ in range(m):
    l, r = tuple(map(int, input().split()))
    ts[l][r] += 1
# 二次元累積和
for i in range(1, n+1):
    for j in range(1, n+1):
        ts[i][j] += ts[i][j-1]

for i in range(1, n+1):
    for j in range(1, n+1):
        ts[i][j] += ts[i-1][j]

for _ in range(Q):
    p, q = tuple(map(int, input().split()))
    print(ts[q][q] - ts[p-1][q] - ts[q][p-1] + ts[p-1][p-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, m, Q = map(int, input().split())

ts = [[0] * (n+1) for _ in range(n+1)]
for _ in range(m):
    l, r = tuple(map(int, input().split()))
    ts[l][r] += 1

from itertools import accumulate
tsa = [list(accumulate(t)) for t in ts]

for _ in range(Q):
    p, q = tuple(map(int, input().split()))
    c = 0
    for i in range(p, q+1):
        c += tsa[i][q] - tsa[i][p-1]
    print(c)




Fixed submission:
n, m, Q = map(int, input().split())

ts = [[0] * (n+1) for _ in range(n+1)]
for _ in range(m):
    l, r = tuple(map(int, input().split()))
    ts[l][r] += 1
# 二次元累積和
for i in range(1, n+1):
    for j in range(1, n+1):
        ts[i][j] += ts[i][j-1]

for i in range(1, n+1):
    for j in range(1, n+1):
        ts[i][j] += ts[i-1][j]

for _ in range(Q):
    p, q = tuple(map(int, input().split()))
    print(ts[q][q] - ts[p-1][q] - ts[q][p-1] + ts[p-1][p-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = tuple(map(int, input().split()))
l = np.lcm.reduce(A) - 1

f = 0 
for a in A:
    f += l % a
print(f)

Fixed submission:
from fractions import gcd
N = int(input())
A = tuple(map(int, input().split()))

l = A[0]
for i in range(1, N):
    l = l * A[i] // gcd(l, A[i])
l = l - 1

f = 0 
for a in A:
    f += l % a
print(f)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
requests = [tuple(map(int, input().split())) for _ in range(M)]
requests.sort(key=lambda x: x[1])
connects = [1] * N
for a, b in requests:
    if all(connects[a:b]):
        connects[b-1] = 0
print(connects.count(0))

Fixed submission:
N, M = map(int, input().split())
requests = [tuple(map(int, input().split())) for _ in range(M)]
requests.sort(key=lambda x: x[1])
counts = 0
left = 0
for a, b in requests:
    if a >= left:
        left = b
        counts += 1
print(counts)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
requests = [tuple(map(int, input().split())) for _ in range(M)]
requests.sort(key=lambda x: x[1])
connects = [1] * N
for a, b in requests:
    if all(connects[a:b]):
        connects[b-1] = 0
print(connects.count(0))

Fixed submission:
N, M = map(int, input().split())
requests = [tuple(map(int, input().split())) for _ in range(M)]
requests.sort(key=lambda x: x[1])
counts = 0
left = 0
for a, b in requests:
    if a >= left:
        left = b
        counts += 1
print(counts)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = tuple(map(int, input().split()))
print(max(A) - min(A)

Fixed submission:
N = int(input())
A = tuple(map(int, input().split()))
print(max(A) - min(A))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(int, input().split()))

Bs = set()
for i in range(N):
    Bs.add(A[i] - (i+1))

mins = sum(A)
for b in Bs:
    s = 0
    for i, a in enumerate(A):
        s += abs(a - (b+i+1))
    mins = min(mins, s)
print(mins)

Fixed submission:
N = int(input())
A = tuple(map(int, input().split()))
B = [a-(i+1) for i, a in enumerate(A)]
B = sorted(B)
b = B[len(B) // 2]
s = 0
for b_ in B:
    s += abs(b_ - b)
print(s)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
M = [input() for _ in range(h)]

ng = False
for i in range(h):
    for j in range(w):
        if M[i][j]  == '.':
            continue

        for mi, mj in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            ni = i + mi; nj = j + mj
            if ni < 0 or h <= ni or nj < 0 or w <= nj:
                continue

            if M[ni][nj] == '#':
                break
        else:
            ng=True
    if ng:
        break
if ng:
    break

if ng:
    print('No')
else:
    print('Yes')

Fixed submission:
h, w = map(int, input().split())
M = [input() for _ in range(h)]

ng = False
for i in range(h):
    for j in range(w):
        if M[i][j]  == '.':
            continue

        for mi, mj in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            ni = i + mi; nj = j + mj
            if ni < 0 or h <= ni or nj < 0 or w <= nj:
                continue

            if M[ni][nj] == '#':
                break
        else:
            ng=True
    if ng:
        break

if ng:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = set(map(int, input().split()))

maxa = max(A)

if maxa%2 == 1:
    l2 = maxa//2
    r2 = maxa//2 + 1
else:
    l2 = maxa//2
    r2 = maxa//2

i = 0
while True:
    if l2-i in A:
        print(maxa, l2-i)
        break
    
    if r2+i in A:
        print(maxa, r2+i)
        break
    
    i += 1


Fixed submission:
n = int(input())
A = map(int, input().split())
A = sorted(A)
maxa = max(A)

from bisect import bisect_left
m = (maxa+1)//2
l2 = bisect_left(A, m)

if abs(A[l2] - m) >= abs(A[l2-1] - m):
    print(maxa, A[l2-1])
else:
    print(maxa, A[l2])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
stations = []
for _ in range(n-1):
    stations.append(tuple(map(int, input().split())))

for i in range(n-1):
    stats = stations[i:]
    t = 0
    for c, s, f in stats:
        if t <= s:
            t = s
        else:
            temp = s
            while temp < t:
                temp += f
            t = temp
        t += c
    print(t)
print(0)


Fixed submission:
n = int(input())
stations = []
for _ in range(n-1):
    stations.append(tuple(map(int, input().split())))

outputs = [0] * n
for i in range(n-1):
    t = 0
    for j in range(i, n-1):
        c, s, f = stations[j]
        if t <= s:
            t = s
        else:
            if t%f != 0:
                t = t+f - t%f
        t += c
    print(t)
print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = tuple(map(int, input().split()))

d = dict()
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

if len(d) <= k:
    print(0)
else:
    c = 0
    while len(d) > k:
        v = d.pop(min(d, key=d.get))
        c += v
    print(c)

Fixed submission:
n, k = map(int, input().split())
A = tuple(map(int, input().split()))
d = dict()
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

cs = sorted(list(d.values()))

if len(cs) <= k:
    print(0)
else:
    c = 0
    print(sum(cs[:-k]))
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, intput().split())
a = n*a
print(min(a, b))

Fixed submission:
n, a, b = map(int, input().split())
a = n*a
print(min(a, b))
Buggy python submission (verdict: Runtime Error):
n, C = map(int, input().split())
cq = [[] for _ in range(C)]

for _ in range(n):
    s, t, c = tuple(map(int, input().split()))
    if cq[c-1]:
        fs, ft = cq[c-1][-1]
        if ft != s:
            cq[c-1].append([s, t])
        else:
            cq[c-1][-1] = [fs, t]
    else:
        cq[c-1].append([s, t])

R = [0] * (2*10**5+1)
for qq in cq:
    for s, t in qq:
        R[2*s-1] += 1
        R[2*t+1] -= 1

from itertools import accumulate
CR = list(accumulate(R))

print(max(CR))

Fixed submission:
n, C = map(int, input().split())
cq = [[] for _ in range(C)]
stc = [tuple(map(int, input().split())) for _ in range(n)]
stc = sorted(stc, key=lambda x: x[0])

for s, t, c in stc:
    c -= 1
    if cq[c]:
        fs, ft = cq[c][-1]
        if ft != s:
            cq[c].append([s, t])
        else:
            cq[c][-1] = [fs, t]
    else:
        cq[c].append([s, t])

R = [0] * (2*10**5+2)
for qq in cq:
    for s, t in qq:
        R[2*s-1] += 1
        R[2*t+1] -= 1

from itertools import accumulate
CR = list(accumulate(R))
print(max(CR))
Buggy python submission (verdict: Runtime Error):
a, b input().split()
if a==b:
  print("=")
else:
  print("<" if a < b else ">")

Fixed submission:
a, b = input().split()
if a==b:
  print("=")
else:
  print("<" if a < b else ">")
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
s100 = 100*(n - m) * 2**m
s1900 = m * 1900 * 2**m
print(s100 + s1900)
\

Fixed submission:
n, m = map(int, input().split())
s100 = 100*(n - m) * 2**m
s1900 = m * 1900 * 2**m
print(s100 + s1900)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = sorted(tuple(map(int, input().split())))
B = tuple(map(int, input().split()))
C = sorted(tuple(map(int, input().split())))

count = 0
for b in B:
    # Aの候補
    la = -1
    ra = n
    while (ra - la) > 1:
        mid = (la+ra)//2
        if A[mid] > b:
            ra = mid
        else:
            la = mid
    if A[la] != b:
        la += 1

    # Cの候補
    lc = -1
    rc = n
    while (rc - lc) > 1:
        mid = (lc+rc)//2
        if C[mid] < b:
            lc = mid
        else:
            rc = mid
    if C[rc] == b:
        rc += 1
    
    count += la*(n-rc)

print(count)

Fixed submission:
n = int(input())
A = sorted(tuple(map(int, input().split())))
B = tuple(map(int, input().split()))
C = sorted(tuple(map(int, input().split())))

import bisect

count = 0
for b in B:
    # Aの候補
    la = bisect.bisect_left(A, b)
    # Cの候補
    rc = bisect.bisect_right(C, b)
    
    count += la*(n-rc)

print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
A = sorted(tuple(map(int, input().split())))
B = tuple(map(int, input().split()))
C = sorted(tuple(map(int, input().split())))

count = 0
for b in B:
    # Aの候補
    la = -1
    ra = n
    while (ra - la) > 1:
        mid = (la+ra)//2
        if A[mid] > b:
            ra = mid
        else:
            la = mid
    if A[la] != b:
        la += 1

    # Cの候補
    lc = -1
    rc = n
    while (rc - lc) > 1:
        mid = (lc+rc)//2
        if C[mid] < b:
            lc = mid
        else:
            rc = mid
    if C[rc] == b:
        rc += 1
        
        count += la*(n-rc)
    
    print(count)


Fixed submission:
n = int(input())
A = sorted(tuple(map(int, input().split())))
B = tuple(map(int, input().split()))
C = sorted(tuple(map(int, input().split())))

import bisect

count = 0
for b in B:
    # Aの候補
    la = bisect.bisect_left(A, b)
    # Cの候補
    rc = bisect.bisect_right(C, b)
    
    count += la*(n-rc)

print(count)
Buggy python submission (verdict: Runtime Error):
S = input()
snx = S.replace('x', '')
ls = len(S)
if ls == 1:
    print(0)
    exit(0)
l = 0
r = ls-1

ans = 0
while l < r:

    lxc = 0
    while S[l] == 'x':
        l += 1
        lxc += 1
    
    rxc = 0
    while S[r] == 'x':
        r -= 1
        rxc += 1

    ans += abs(lxc-rxc)

    if S[l] == S[r]:
        l += 1
        r -= 1
    else:
        print(-1)
        break
else:
    print(ans)


Fixed submission:
S = input()
snx = S.replace('x', '')
ls = len(S)
if ls == 1 or len(snx) == 0:
    print(0)
    exit(0)
l = 0
r = ls-1

ans = 0
while l < r:
    lxc = 0
    while S[l] == 'x':
        l += 1
        lxc += 1
    rxc = 0
    while S[r] == 'x':
        r -= 1
        rxc += 1
    ans += abs(lxc-rxc)

    if S[l] == S[r]:
        l += 1
        r -= 1
    else:
        print(-1)
        break
else:
    print(ans)