Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03001 (python)

Fixed submission:
W, H, x, y = map(float, input().split())

if x == W or y == H or x == 0.0 or y == 0.0:
    ans = H*W/2
    ans_2 = 0
elif x*H == y*W or (W-x)*H == y*W:
    ans = H*W/2
    if float(x) == W/2 and float(y) == H/2:
        ans_2 = 1
    else:
        ans_2 = 0
elif abs(W/2-x) * (H/2) / abs(H/2-y) < W/2:
    ans = H*W/2
    ans_2 = 0
else:
    yoko_a = W * y
    yoko_b = W * (H-y)
    yoko = min(yoko_a, yoko_b)

    tate_a = H * x
    tate_b = H * (W-x)
    tate = min(tate_a, tate_b)
    
    ans = max(tate, yoko)
    ans = float(ans)

    if tate == yoko:
        ans_2 = 1
    else:
        ans_2 = 0

print(ans, ans_2)

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(float, input().split())

if x == W or y == H or x == 0 or y == 0:
    ans = H*W/2
    ans_2 = 0
if x*H == y*W or (W-x)*H == y*W or :
    ans = H*W/2
    if float(x) == W/2 and float(y) == H/2:
        ans_2 = 1
    else:
        ans_2 = 0
else:
    yoko_a = W * y
    yoko_b = W * (H-y)
    yoko = min(yoko_a, yoko_b)

    tate_a = H * x
    tate_b = H * (W-x)
    tate = min(tate_a, tate_b)
    
    ans = max(tate, yoko)
    ans = float(ans)

    if tate == yoko:
        ans_2 = 1
    else:
        ans_2 = 0

print(ans, ans_2)

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())

if x*H == y*W or (W-x)*H == y*W:
    ans = H*W/2
    if float(x) == W/2 and float(y) == H/2:
        ans_2 = 1
    else:
        ans_2 = 0
        print(ans, ans_2)
else:
    # 0 0
    _y = y*W/x
    _x = W
    if _y > H:
        _y = H
        _x = x*H/y
    a_00 = _x*_y/2

    # H 0
    _y = H
    _x = x * H / (H-y)
    if _x > W:
        _x = W
        _y = (H-y)*W/x
    a_H0 = _x*_y/2

    # 0 W
    _y = y*W/(W-x)
    _x = W
    if _y > H:
        _y = H
        _x = H*(W-x)/y
    a_0W = _x*_y/2

    # H W
    _y = H
    _x = (W-x)*H/(H-y)
    if _x > W:
        _x = W
        _y = (H-y)*W/(W-x)
    a_HW = _x*_y/2

    yoko_a = W * y
    yoko_b = W * (H-y)
    yoko = float(min(yoko_a, yoko_b))

    tate_a = H * x
    tate_b = H * (W-x)
    tate = float(min(tate_a, tate_b))

    a = [a_HW, a_H0, a_0W, a_00, yoko, tate]
    a = sorted(a)
    print(a[-1])
    if a[-1] == a[-2]:
        print(1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())

# 0 0
_y = y*W/x
_x = W
if _y > H:
    _y = H
    _x = x*H/y
a_00 = _x*_y/2

# H 0
_y = H
_x = x * H / (H-y)
if _x > W:
    _x = W
    _y = (H-y)*W/x
a_H0 = _x*_y/2

# 0 W
_y = y*W/(W-x)
_x = W
if _y > H:
    _y = H
    _x = H*(W-x)/y
a_0W = _x*_y/2

# H W
_y = H
_x = (W-x)*H/(H-y)
if _x > W:
    _x = W
    _y = (H-y)*W/(W-x)
a_HW = _x*_y/2

yoko_a = W * y
yoko_b = W * (H-y)
yoko = float(min(yoko_a, yoko_b))

tate_a = H * x
tate_b = H * (W-x)
tate = float(min(tate_a, tate_b))

a = [a_HW, a_H0, a_0W, a_00, yoko, tate]
a = sorted(a)
print(a[-1])
if a[-1] == a[-2]:
    print(1)
else:
    print(0)
Problem p03006 (python)

Fixed submission:
N = int(input())

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x,y))
    
from collections import defaultdict

dd = defaultdict(lambda:defaultdict(bool))

X = sorted(XY)

for x,y in XY:
    dd[x][y] = True

max_count = 0
for i, (x0, y0) in enumerate(X):
    for x1, y1 in X[i+1:]:
        diff_x, diff_y = (x1-x0, y1-y0)
        counter = 0
        for x, y in X:
            if dd[x+diff_x][y+diff_y]:
                counter += 1
        max_count = max(max_count, counter)
#print(max_count)

ans = N - max_count
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x,y))
    
import itertools
import collections
import sys

sys.setrecursionlimit(10000)

ans_list = []
for v in itertools.permutations(XY):
    count_list = []
    for (x0, y0), (x1,y1) in zip(v[1:], v[:-1]):
        count_list.append((x1-x0, y1-y0))
    ans_list.append(max(collections.Counter(count_list).values()))
    
ans = N-max(ans_list)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x,y))
    
    
import itertools
import collections

ans_list = []
for v in itertools.permutations(XY):
    count_list = []
    for (x0, y0), (x1,y1) in zip(v[1:], v[:-1]):
        count_list.append((x1-x0, y1-y0))
    ans_list.append(max(collections.Counter(count_list).values()))
    
ans = N-max(ans_list)
print(ans)
Problem p03007 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

BB = A[:]

BB_P = []
BB_M = []


for b in BB:
    if b < 0:
        BB_M.append(b)
    else:
        BB_P.append(b)

        
ope = []
if not BB_M:
    BB_P = sorted(BB_P)
    p = BB_P[-1]
    m = BB_P[0]
    for b in BB_P[1:-1]:
        ope.append((m,b))
        m = m-b
    ope.append((p,m))
    ans = p - m
elif not BB_P:
    BB_M = sorted(BB_M)
    p = BB_M[-1]
    for b in BB_M[:-1]:
        ope.append((p, b))
        p = p-b
    ans = p
else:
    p = BB_P.pop()
    m = BB_M.pop()
    for b in BB_P:
        ope.append((m ,b))
        m = m-b
    for b in BB_M:
        ope.append((p ,b))
        p = p-b
    ope.append((p,m))
    ans = p-m
    
print(ans)
for x,y in ope:
    print(x, y)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

BB = A[:]

BB_P = []
BB_M = []


for b in BB:
    if b < 0:
        BB_M.append(b)
    else:
        BB_P.append(b)

        
ope = []
if not BB_M:
    BB_P = sorted(BB_P)
    p = BB_P[-1]
    m = BB_P[0]
    for b in BB_P[1:-1]:
        ope.append((m,b))
        m = m-b
    ope.append((p,m))
    ans = p - m
elif not BB_P:
    BB_M = sorted(BB_M)
    p = BB_M[-1]
    for b in BB_M[:-1]:
        ope.append((p, b))
        p = p-b
    ans = p
else:
    p = BB_P.pop()
    m = BB_M.pop()
    for b in BB_P:
        ope.append((m ,b))
        m = m-b
    for b in BB_M:
        ope.append((p ,b))
        p = p-b
    ope((p,m))
    ans = p-m
    
print(ans)
for x,y in ope:
    print(x, y)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

BB = A[:]

BB_P = []
BB_M = []


for b in BB:
    if b < 0:
        BB_M.append(b)
    else:
        BB_P.append(b)

        
ope = []
if not BB_M:
    BB_P = sorted(BB_P)
    p = BB_P[-1]
    m = BB_P[0]
    for b in BB_P[1:-1]:
        ope.append((m,b))
        m = m-b
    ope.append((p,m))
    ans = p - m
elif not BB_P:
    BB_M = sorted(BB_M)
    p = BB_M[-1]
    for b in BB_M[:-1]:
        ope.append((p, b))
        p = p-b
    ans = p
else:
    p = BB_P.pop()
    m = BB_M.pop()
    for b in BB_P:
        ope.append((m ,b))
        m = m-b
    for b in BB_M:
        ope.append((p ,b))
        p = p-b
    ope((p,m))
    ans = p-m
    
print(ans)
for x,y in ope:
    print(x, y)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

BB = A[:]


def dfs(BB, ope):
    if len(BB) == 1:
        return BB[0], ope
    
    ret_list = []
    for i, x in enumerate(BB):
        for j, y in enumerate(BB[i+1:]):
            ret_list.append(dfs(BB[:i]+BB[i+1:i+1+j]+BB[i+1+j+1:]+[x-y], ope[:] + [(x, y)]))
            ret_list.append(dfs(BB[:i]+BB[i+1:i+1+j]+BB[i+1+j+1:]+[y-x], ope[:] + [(y, x)]))
    return max(ret_list)

ans = dfs(BB, [])

print(ans[0])
for a in ans[1]:
    print(a[0], a[1])
Problem p03014 (python)

Fixed submission:
H, W =  map(int, input().split())

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
import numpy as np

def count_light(Gs, h, w):
    Gc = np.empty((h,w))
    for i in range(w):
        if i == 0:
            Gc[:, i] = Gs[:, i]
        else:
            Gc[:, i] = (Gc[:, i-1] + 1) * Gs[:, i]

    return Gc

Gs1 = np.asarray(S) == "."
Gn1 = count_light(Gs1, H, W)

Gs2 = np.rot90(Gs1, k=1)
Gn2 = count_light(Gs2, W, H)

Gs3 = np.rot90(Gs2, k=1)
Gn3 = count_light(Gs3, H, W)

Gs4 = np.rot90(Gs3, k=1)
Gn4 = count_light(Gs4, W, H)

Gn2 = np.rot90(Gn2, k=-1)
Gn3 = np.rot90(Gn3, k=-2)
Gn4 = np.rot90(Gn4, k=-3)

Gsum = Gn1+Gn2+Gn3+Gn4
ans = int(np.max(Gsum)-3)
print(ans)

Buggy submission (verdict: Runtime Error):
H, W =  map(int, input().split())

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
import numpy as np

def count_light(Gs, h, w):
    Gc = np.empty((h,w))
    for i, gs in enumerate(Gs):
        count = 0
        for j, s in enumerate(gs):
            if s == '#':
                count = 0
                Gc[i][j] = 0
            else:
                count += 1
                Gc[i][j] = count

    return Gc

Gs1 = np.asarray(S)
Gn1 = count_light(Gs1, H, W)

Gs2 = np.rot90(Gs, k=1)
Gn2 = count_light(Gs2, W, H)

Gs3 = np.rot90(Gs2, k=1)
Gn3 = count_light(Gs3, H, W)

Gs4 = np.rot90(Gs3, k=1)
Gn4 = count_light(Gs4, W, H)

Gn2 = np.rot90(Gn2, k=-1)
Gn3 = np.rot90(Gn3, k=-2)
Gn4 = np.rot90(Gn4, k=-3)

Gsum = Gn1+Gn2+Gn3+Gn4
ans = int(np.max(Gsum)-3)
print(ans)

Buggy submission (verdict: Runtime Error):
H, W =  map(int, input().split())

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
import numpy as np

Gs = np.asarray(S)
Gs_ = np.rot90(Gs, k=1)

def count_light(Gs, h, w):
    Gc = np.empty((h,w))
    for i, gs in enumerate(Gs):
        count = 0
        gc = []
        for j, s in enumerate(gs):
            if s == '#':
                count = 0
                Gc[i][j] = 0
            else:
                count += 1
                Gc[i][j] = count

    Gn = np.empty((h,w))
    for i, gc in enumerate(Gc):
        count = -1
        gn = []
        for j, c in enumerate(reversed(gc)):
            if c == 0:
                count = -1
                Gn[i][j] = 0
            else:
                if count == -1:
                    count = c
                Gn[i][w-j-1]  = count

    return Gn

Gn = count_light(Gs, H, W)
Gn_ = count_light(Gs_, W, H)
Gn_ = np.rot90(Gn_, k=-1)

Gsum = Gn+Gn_
ans = np.max(Gsum)-1

        
print(int(ans))
Problem p03032 (python)

Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))

# N < Kの場合があることに注意


INT_MIN = -1 * (10**10)

ans = INT_MIN

NK = min(N, K)
for left in range(0,NK+1):
    for right in range(0, NK+1-left):
        #print("========")
        #print(left, right)
        #print(V[:left], V[left:N-right], V[N-right:])
        
        rest_ope = K-left-right
        #print(rest_ope)
        my_v = V[:left]+V[N-right:]
        sum_v = 0
        for i, x in enumerate(sorted(my_v)):
            if x < 0 and i < rest_ope:
                continue
            else:
                sum_v += x
        #print(sum_v)
        ans = max(ans, sum_v)
        
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
V = list(map(int, input().split()))

import copy

import sys

INT_MIN = -1 * sys.maxsize

import bisect

def dfs(k, v_q, v_plus, v_minus):
    v_p_sum = sum(v_plus)
    #if k == 0:
    #    return v_p_sum + sum(v_minus)
    #c = INT_MIN
    if k < len(v_minus):
        #v_minus = sorted(v_minus)
        c = v_p_sum + sum(v_minus[k:])
        return c
    
    
    v_q_left = copy.copy(v_q)
    l = v_q_left.popleft()
    if l >= 0:
        a = dfs(k-1, v_q_left, v_plus[:]+[l], v_minus[:])
    else:
        tmp = v_minus[:]
        bisect.insort(tmp, l)
        a = dfs(k-1, v_q_left, v_plus[:], tmp)
    
    v_q_right = copy.copy(v_q)
    r = v_q_right.pop()
    if r >= 0:
        b = dfs(k-1, v_q_right, v_plus[:]+[r], v_minus[:])
    else:
        tmp = v_minus[:]
        bisect.insort(tmp, r)
        b = dfs(k-1, v_q_right, v_plus[:], tmp)
    
    return max([a, b, v_p_sum])
    


from collections import deque
v_q = deque(V)

ans = dfs(K, v_q, [], [])
print(ans)
Problem p03061 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

nums = A[:]
import fractions

gcd_queue = [
    (nums[0], True),
    (nums[1], True),
    (fractions.gcd(nums[0], nums[1]), False),
]
for n in nums[2:]:
    tmp_queue = []
    for q in gcd_queue:
        if q[1] == True:
            tmp_queue.append((fractions.gcd(q[0], n), True))
        else:
            tmp_queue.append((fractions.gcd(q[0], n), False))
            tmp_queue.append((q[0], True))
    gcd_queue = set(tmp_queue[:])

ans = 0
for q in gcd_queue:
    ans = max(ans, q[0])
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

nums = A[:]
import math

gcd_queue = [
    (nums[0], True),
    (nums[1], True),
    (math.gcd(nums[0], nums[1]), False),
]
for n in nums[2:]:
    tmp_queue = []
    for q in gcd_queue:
        if q[1] == True:
            tmp_queue.append((math.gcd(q[0], n), True))
        else:
            tmp_queue.append((math.gcd(q[0], n), False))
            tmp_queue.append((q[0], True))
    gcd_queue = tmp_queue[:]
#print(gcd_queue)

ans = 0
for q in gcd_queue:
    ans = max(ans, q[0])
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

nums = A[:]
import math

def cal_gcd(i, flag, ans):
    if i == len(nums):
        return ans
    ans_0 = -1
    if flag == False:
        ans_0 = cal_gcd(i+1, True, ans)
    
    if ans == 0:
        ans = nums[i]
    #print(i)
    ans = math.gcd(ans, nums[i])
    ans_1 = cal_gcd(i+1, flag, ans)
    return max(ans_0, ans_1)
    
ans = cal_gcd(0, False, 0)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

nums = A[:]
#print(nums)
import math

def cal_gcd(sub_nums):
    gcd_tmp = sub_nums[0]
    for i, v in enumerate(sub_nums):
        if i == 0:
            continue
        gcd_tmp = math.gcd(v, gcd_tmp)
        #print(gcd_tmp)
    return gcd_tmp

ans = 1
import itertools
for v in itertools.combinations(nums, len(nums) - 1):
    #print(v)
    gcd_tmp = cal_gcd(v)
    #print(gcd_tmp)
    ans = max(ans, gcd_tmp)
print(ans)
Problem p03081 (python)

Fixed submission:
N, Q = map(int, input().split())
s = str(input())

t = []
d = []

for _ in range(Q):
    ti, di = input().split()
    t.append(ti)
    d.append(di)
    
LEFT_DIE = -1
RIGHT_DIE = N

def is_dead(i):
    for ti, di in zip(t, d):
        if s[i] == ti:
            if di == 'L':
                i -= 1
            if di == 'R':
                i += 1
            if i == LEFT_DIE:
                return LEFT_DIE
            if i == RIGHT_DIE:
                return RIGHT_DIE
    return 0

low = -1
high = N;
# LEFT
while high - low > 1:
    mid = (low + high) // 2;
    if is_dead(mid) == LEFT_DIE:
        low = mid
    else:
        high = mid
left_edge = high

low = -1
high = N;
# RIGHT
while high - low > 1:
    mid = (low + high) // 2;
    if is_dead(mid) == RIGHT_DIE:
        high = mid
    else:
        low = mid
right_edge = low

#print(left_edge, right_edge)
ans_s = s[left_edge:right_edge+1]
#print(ans_s)
ans = len(ans_s)
print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s = str(input())

t = []
d = []

for _ in range(Q):
    ti, di = map(str, input().split())
    t.append(ti)
    d.append(di)
    
LEFT_DIE = -1
RIGHT_DIE = len(s)

def is_dead(i):
    for ti, di in zip(t, d):
        if s[i] == ti:
            if di == 'L':
                i -= 1
            if di == 'R':
                i += 1
            if i == LEFT_DIE:
                return LEFT_DIE
            if i == RIGHT_DIE:
                return RIGHT_DIE
    return 0

low = -1
high = len(s);
# LEFT
while high - low > 1:
    mid = (low + high) // 2;
    if is_dead(mid) == LEFT_DIE:
        low = mid
    else:
        high = mid
left_edge = high

low = -1
high = len(s);
# RIGHT
while high - low > 1:
    mid = (low + high) // 2;
    if is_dead(mid) == RIGHT_DIE:
        high = mid
    else:
        low = mid
right_edge = low
        
        

left_edge = check_left()
#print(left_edge)
right_edge = check_right()
#print(right_edge)

ans_s = s[left_edge+1:right_edge]
#print(ans_s)
ans = len(ans_s)
print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s = str(input())

t = []
d = []

for _ in range(Q):
    ti, di = map(str, input().split())
    t.append(ti)
    d.append(di)
    
spell_target = {}
for i, c in enumerate(s):
    if c in spell_target:
        spell_target[c].append(i+1)
    else:
        spell_target[c] = [i+1]
#print(spell_target)

golems_nums = [1 for _ in range(len(s) + 2)]
golems_nums[0] = 0
golems_nums[-1] = 0
#print(golems_nums)

for ti, di in zip(t, d):
    if di == 'L':
        targets = spell_target[ti]
        for n in targets:
            golems_nums[n-1] += golems_nums[n]
            golems_nums[n] = 0
    if di == 'R':
        targets = spell_target[ti]
        for n in reversed(targets):
            golems_nums[n+1] += golems_nums[n]
            golems_nums[n] = 0
#print(golems_nums)
ans = sum(golems_nums) - golems_nums[0] - golems_nums[-1]
print(ans)
Problem p03082 (python)

Fixed submission:
N, X = map(int, input().split())
S = list(map(int, input().split()))

MOD = 1000000007
numbers = S[:]
numbers.sort(reverse=True)


dp = {X: 1}

for i, n in enumerate(numbers):
    tmp_dp = {}
    for k, v in dp.items():
        if k < n:
            tmp_dp[k] = (tmp_dp.get(k,0)+v*(N-i))
        else:
            tmp_dp[k]=(tmp_dp.get(k,0)+v*(N-i-1)) 
            tmp_dp[k%n]=(tmp_dp.get(k%n,0)+v) 
    dp = tmp_dp.copy()
        
ans = 0
for k, v in dp.items():
    ans += k *  v

print(ans % MOD)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, X = map(int, input().split())
S = list(map(int, input().split()))

MOD = 1000000007
numbers = S[:]
numbers.sort()


dp = np.zeros((N+1, X+1), dtype=int)
dp = np.arange(X+1)
dp_n = []
for n  in numbers:
    dp_n = np.zeros((X+1), dtype=np.int64)
    dp_n += [dp[x % n] for x in range(X+1)]
    dp_n = dp_n % MOD
    dp_n += dp * i % MOD
    dp_n = dp_n % MOD
    dp = dp_n

print(int(dp_n[X]) % MOD)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, X = map(int, input().split())
S = list(map(int, input().split()))

MOD = 1000000007
numbers = S[:]
numbers.sort()


dp = np.zeros((N+1, X+1), dtype=int)
dp = np.arange(X+1)
dp_n = []
for n  in numbers:
    dp_n = np.zeros((X+1), dtype=np.int64)
    dp_n += [dp[x % n] for x in range(X+1)]
    dp_n = dp_n % MOD
    dp_n += dp * i % MOD
    dp_n = dp_n % MOD
    dp = dp_n

print(int(dp_n[X]) % MOD)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
S = list(map(int, input().split()))

MOD = 1000000007
numbers = S[:]
numbers.sort()
#dp = [[0 for _ in range(X+1)] for _ in range(N+1)]

dp = [[0] * (X+1) for _ in range(N+1)]
#dp[0] = [x for x in range(X+1)]
#from collections import defaultdict
#dp = [defaultdict(int) for _ in range(N+1)]
dp[0] = [x for x in range(X+1)]

import array 
dp = [array.array('Q', l) for l in dp]

for i, n  in enumerate(numbers):
    for x in range(X+1):
        dp[i+1][x] += dp[i][x % n]
        dp[i+1][x] += dp[i][x] * i #% MOD

print(dp[N][X] % MOD)
Problem p03112 (python)

Fixed submission:
A, B, Q = map(int, input().split())
s = []
t = []
x = []
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
for _ in range(Q):
    x.append(int(input()))

import sys
INT_MAX = sys.maxsize
s.insert(0, -1 * INT_MAX)
s.append(INT_MAX)
t.insert(0, -1 * INT_MAX)
t.append(INT_MAX)

import bisect
for xi in x:
    #print(xi)
    si = bisect.bisect_right(s, xi)
    #si = 0
    #for si, v in enumerate(s):
    #    if v > xi:
    #        break
    ti = bisect.bisect_right(t, xi)
    #ti = 0
    #for ti, v in enumerate(t):
    #    if v > xi:
    #        break
    #print(si, ti)
    sa = s[si]
    ta = t[ti]
    sb = s[si-1]
    tb = t[ti-1]
    #print(sa, sb,ta,tb)
    ans = min([
        abs(xi-sa)+abs(sa-ta),
        abs(xi-sa)+abs(sa-tb),
        abs(xi-sb)+abs(sb-ta),
        abs(xi-sb)+abs(sb-tb),
        abs(xi-ta)+abs(ta-sa),
        abs(xi-ta)+abs(ta-sb),
        abs(xi-tb)+abs(tb-sa),
        abs(xi-tb)+abs(tb-sb)
    ])
    print(ans)

Buggy submission (verdict: Runtime Error):
A, B, Q = map(int, input().split())
s = []
t = []
x = []
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
for _ in range(Q):
    x.append(int(input()))

import sys
INT_MAX = sys.maxsize
s.insert(0, -1 * INT_MAX)
s.append(INT_MAX)
t.insert(0, -1 * INT_MAX)
t.append(INT_MAX)

import bisect
for xi in x:
    #print(xi)
    si = bisect.bisect_right(s, xi)
    #si = 0
    #for si, v in enumerate(s):
    #    if v > xi:
    #        break
    ti = bisect.bisect_right(s, xi)
    #ti = 0
    #for ti, v in enumerate(t):
    #    if v > xi:
    #        break
    #print(si, ti)
    sa = s[si]
    ta = t[ti]
    sb = s[si-1]
    tb = t[ti-1]
    #print(sa, sb,ta,tb)
    ans = min([
        abs(xi-sa)+abs(sa-ta),
        abs(xi-sa)+abs(sa-tb),
        abs(xi-sb)+abs(sb-ta),
        abs(xi-sb)+abs(sb-tb),
        abs(xi-ta)+abs(ta-sa),
        abs(xi-ta)+abs(ta-sb),
        abs(xi-tb)+abs(tb-sa),
        abs(xi-tb)+abs(tb-sb)
    ])
    print(ans)
Problem p03476 (python)

Fixed submission:
import sys
input = sys.stdin.readline
Q = int(input())

LR = []
for _ in range(Q):
    l,r = map(int, input().split())
    LR.append((l,r))
    
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return {i: True for i in range(n + 1) if is_prime[i]}

prime_dict = primes(10**5)
like_2017 = []
for n in prime_dict:
    if (n+1)//2 in prime_dict:
        like_2017.append(n)
#print(like_2017)
like_2017 = list(sorted(like_2017))


from bisect import bisect_left, bisect_right

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(a, x)
    return i

for l, r in LR:
    if l == r:
        if l in like_2017:
            print(1)
        else:
            print(0)
    else:
        l_idx = index(like_2017, l)
        r_idx = index(like_2017, r)
        if r in like_2017:
            r_idx += 1
        print(r_idx-l_idx)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
Q = int(input())

LR = []
for _ in range(Q):
    l,r = map(int, input().split())
    LR.append((l,r))
    
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return {i: True for i in range(n + 1) if is_prime[i]}

prime_dict = primes(10**5)
like_2017 = []
for n in prime_dict:
    if (n+1)//2 in prime_dict:
        like_2017.append(n)
#print(like_2017)


from bisect import bisect_left, bisect_right

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(a, x)
    if i != len(a):
        return i
    elif a[i] == x:
        return i
    raise ValueError

for l, r in LR:
    if l == r:
        if l in like_2017:
            print(1)
        else:
            print(0)
    else:
        l_idx = index(like_2017, l)
        r_idx = index(like_2017, r)
        print(r_idx-l_idx)