qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import bisect
import sys
A, B, Q = map(int,input().split())

S = [-10**18] + list(map(int, (sys.stdin.readline() for _ in [0]*A))) + [10**18]
T = [-10**18] + list(map(int, (sys.stdin.readline() for _ in [0]*A))) + [10**18]


for _ in range(Q):
    x = int(input())
    ans = 10**18
    for i in range(2):
        if i == 0:
            a = S
            b = T
        elif i== 1:
            a = T
            b = S

        idx_x = bisect.bisect_left(a,x)
        for j in range(2):
            ax = a[idx_x-j]
            idx_a = bisect.bisect_left(b,ax)
            for k in range(2):
                bx = b[idx_a-k]
                ans = min(ans, abs(ax-x)+abs(bx-ax))
    print(ans)

Fixed code:
import bisect
import sys
A, B, Q = map(int,input().split())

S = [-10**18] + list(map(int, (sys.stdin.readline() for _ in [0]*A))) + [10**18]
T = [-10**18] + list(map(int, (sys.stdin.readline() for _ in [0]*B))) + [10**18]





for _ in range(Q):
    x = int(input())
    ans = 10**18
    for i in range(2):
        if i == 0:
            a = S
            b = T
        elif i== 1:
            a = T
            b = S

        idx_x = bisect.bisect_left(a,x)
        for j in range(2):
            ax = a[idx_x-j]
            idx_a = bisect.bisect_left(b,ax)
            for k in range(2):
                bx = b[idx_a-k]
                ans = min(ans, abs(ax-x)+abs(bx-ax))
    print(ans)
Buggy code:
import bisect


def solve(a_list, b_list, position):
    # time O(log(A))
    a_right_key = bisect.bisect_left(a_list, position)
    a_left_key = a_right_key - 1
    # time O(log(B))
    b_right_key = bisect.bisect_left(b_list, position)
    b_left_key = b_right_key - 1

    a_left, a_right = a_list[a_left_key], a_list[a_right_key]
    b_left, b_right = b_list[b_left_key], b_list[b_right_key]

    ans = 10 ** 20
    for a_position in [a_left, a_right]:
        for b_position in [b_left, b_right]:
            distance1 = abs(position - a_position) + abs(a_position - b_position)
            distance2 = abs(position - b_position) + abs(a_position - b_position)
            ans = min(ans, distance1, distance2)
    return ans


def main():
    inf = 10 ** 20
    A, B, Q = map(int, input().split())

    # time O(A)
    a_list = [int(input()) for _ in range(A)]
    a_list = [-inf] + a_list + [inf]
    # time O(B)
    b_list = [int(input()) for _ in range(A)]
    b_list = [-inf] + b_list + [inf]

    # time O(Q (log(A) + log(B))
    for _ in range(Q):
        position = int(input())
        ans = solve(a_list, b_list, position)
        print(ans)


if __name__ == "__main__":
    main()


Fixed code:
import bisect


def solve(a_list, b_list, position):
    # time O(log(A))
    a_right_key = bisect.bisect_left(a_list, position)
    a_left_key = a_right_key - 1
    # time O(log(B))
    b_right_key = bisect.bisect_left(b_list, position)
    b_left_key = b_right_key - 1

    a_left, a_right = a_list[a_left_key], a_list[a_right_key]
    b_left, b_right = b_list[b_left_key], b_list[b_right_key]

    ans = 10 ** 20
    for a_position in [a_left, a_right]:
        for b_position in [b_left, b_right]:
            distance1 = abs(position - a_position) + abs(a_position - b_position)
            distance2 = abs(position - b_position) + abs(a_position - b_position)
            ans = min(ans, distance1, distance2)
    return ans


def main():
    inf = 10 ** 20
    A, B, Q = map(int, input().split())

    # time O(A)
    a_list = [int(input()) for _ in range(A)]
    a_list = [-inf] + a_list + [inf]
    # time O(B)
    b_list = [int(input()) for _ in range(B)]
    b_list = [-inf] + b_list + [inf]

    # time O(Q (log(A) + log(B))
    for _ in range(Q):
        position = int(input())
        ans = solve(a_list, b_list, position)
        print(ans)


if __name__ == "__main__":
    main()
Buggy code:
import bisect
A, B, Q = map(int, input().split())
inf = 10**18
lisS = [-inf] + [int(input(x)) for x in range(A)] + [inf]
lisT = [-inf] + [int(input(x)) for x in range(B)] + [inf]
for _ in range(Q):
  x = int(input())
  i = bisect.bisect_right(lisS, x)
  j = bisect.bisect_right(lisT, x)
  res = inf
  for S in [lisS[i - 1], lisS[i]]:
    for T in [lisT[j - 1], lisT[j]]:
      r1 = abs(S - x) + abs(S - T)
      r2 = abs(T - x) + abs(S - T)
      res = min(res, r1, r2)
  print(res)

Fixed code:
import bisect
A, B, Q = map(int, input().split())
inf = 10**18
lisS = [-inf] + [int(input()) for x in range(A)] + [inf]
lisT = [-inf] + [int(input()) for x in range(B)] + [inf]
for _ in range(Q):
  x = int(input())
  i = bisect.bisect_right(lisS, x)
  j = bisect.bisect_right(lisT, x)
  res = inf
  for S in [lisS[i - 1], lisS[i]]:
    for T in [lisT[j - 1], lisT[j]]:
      r1 = abs(S - x) + abs(S - T)
      r2 = abs(T - x) + abs(S - T)
      res = min(res, r1, r2)
  print(res)
Buggy code:
import bisect

A, B, Q = [int(i) for i in input().split()]

s = [-10**12] + [int(input()) for i in range(A)] + [10**12]
t = [-10**12] + [int(input()) for i in range(B)] + [10**12]
x = [int(input()) for i in range(Q)]

for item in x:
    b, d = bisect.bisect_left(s, item), bisect.bisect_left(t, item)
    min_value = 10**12
    for item_a in [s[a], s[a+1]]:
        for item_c in [t[c], t[c+1]]:
            pata = abs(item_a - item) + abs(item_a - item_c)
            patb = abs(item_c - item) + abs(item_a - item_c)
            min_value = min(min_value, pata, patb)
    print(min_value)


Fixed code:
import bisect

A, B, Q = [int(i) for i in input().split()]

s = [-10**12] + [int(input()) for i in range(A)] + [10**12]
t = [-10**12] + [int(input()) for i in range(B)] + [10**12]
x = [int(input()) for i in range(Q)]

for item in x:
    a, c = bisect.bisect_left(s, item), bisect.bisect_left(t, item)
    min_value = 10**12
    for item_a in [s[a-1], s[a]]:
        for item_c in [t[c-1], t[c]]:
            pata = abs(item_a - item) + abs(item_a - item_c)
            patb = abs(item_c - item) + abs(item_a - item_c)
            min_value = min(min_value, pata, patb)
    print(min_value)
Buggy code:
import bisect
inf = 10**18
a, b, q = map(int, input().split())
s = [-inf] + [int(input()) for _ in range(a)] + [inf]
t = [-inf] + [int(input()) for _ in range(a)] + [inf]

for _ in range(q):
    x = int(input())
    i = bisect.bisect_right(s, x)
    j = bisect.bisect_right(t, x)
    ans = inf
    for s_x in [s[i-1], s[i]]:
        for t_x in [t[i-1], t[i]]:
            ans0 = abs(s_x - x) + abs(t_x - s_x)
            ans1 = abs(t_x - x) + abs(s_x - t_x)
            ans = min(ans, ans0, ans1)
    print(ans)


Fixed code:
import bisect
inf = 10**18
a, b, q = map(int, input().split())
s = [-inf] + [int(input()) for _ in range(a)] + [inf]
t = [-inf] + [int(input()) for _ in range(b)] + [inf]

for _ in range(q):
    x = int(input())
    i = bisect.bisect_right(s, x)
    j = bisect.bisect_right(t, x)
    ans = inf
    for s_x in [s[i-1], s[i]]:
        for t_x in [t[j-1], t[j]]:
            ans0 = abs(s_x - x) + abs(t_x - s_x)
            ans1 = abs(t_x - x) + abs(s_x - t_x)
            ans = min(ans, ans0, ans1)
    print(ans)
Buggy code:
import sys
from bisect import bisect_right
input = sys.stdin.readline().strip()
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
xs = [int(input()) for i in range(Q)]
for x in xs:
    b, d = bisect_right(s, x), bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Fixed code:
import bisect
import sys
A, B, Q = map(int, input().split())
INF = 10 ** 13
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
xs = [int(sys.stdin.readline()) for i in range(Q)]
for x in xs:
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)
Buggy code:
import bisect

A,B,Q=map(int,input().split())
inf = 10 ** 18
S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]

for q in range(Q):
    x = int(input())
    s_l = bisect.bisect_left(s,x)
    s_h = s_l + 1
    t_l = bisect.bisect_left(t,x)
    t_h = t_l + 1

    ans = inf
    for s in [s_l,s_h]:
        for t in [t_l,t_h]:
            d1 = abs(s-x)+abs(t-s)
            d2 = abs(t-x)+abs(s-t)
            ans = min(ans,d1,d2)
    
    print(ans)


Fixed code:
import bisect

A,B,Q=map(int,input().split())
inf = 10 ** 18
S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]

for q in range(Q):
    x = int(input())
    s_h = bisect.bisect(S,x)
    s_l = s_h - 1
    t_h = bisect.bisect(T,x)
    t_l = t_h - 1

    ans = inf
    for s in [S[s_l],S[s_h]]:
        for t in [T[t_l],T[t_h]]:
            d1 = abs(s-x)+abs(t-s)
            d2 = abs(t-x)+abs(s-t)
            ans = min(ans,d1,d2)
    
    print(ans)
Buggy code:
import bisect as bs
a, b, q = map(int, input().split())
INF = 10**18
s = [-INF] + sorted([int(input()) for _ in range(a)]) + [INF]
t = [-INF] + sorted([int(input()) for _ in range(b)]) + [INF]

for _ in range(q):
    z = int(input())
    x, y = bs.bisect_right(s, z), bs.bisect_right(t, z)
    s1, s2, t1, t2 = s[x-1], s[x], t[y-1], t[y]
    print(min(max(z - s1, z - t1), max(s2 - z, t2 - z), min(2 * t2 - z - s1, 2 * s2 - z - t1)))

Fixed code:
import bisect as bs
a, b, q = map(int, input().split())
INF = 10**18
s = [-INF] + sorted([int(input()) for _ in range(a)]) + [INF]
t = [-INF] + sorted([int(input()) for _ in range(b)]) + [INF]

for _ in range(q):
    z = int(input())
    x, y = bs.bisect_right(s, z), bs.bisect_right(t, z)
    s1, s2, t1, t2 = s[x-1], s[x], t[y-1], t[y]
    print(min(max(z - s1, z - t1), max(s2 - z, t2 - z),
    min(2 * t2 - z - s1, 2 * s2 - z - t1), min(z + t2 - 2 * s1, z + s2 - 2 * t1)))
Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 24 22:10:01 2019

@author: Yamazaki Kenichi
"""
import numpy as np

A,B,Q = map(int,input().split())
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
x = [int(input()) for i in range(Q)]

def lr(s,c,A):
    si = np.searchsorted(s,c)
    if si == A:
        return [c-s[si-1], 10**10]
    elif si == 0:
        return [10**10, s[0]-c]
    else:
        return [c-s[si-1], s[si]-c]
for c in x:
    ans = 0
    slr = lr(s,c,A)
    tlr = lr(t,c,B)
    ans = min(max(slr[0],tlr[0]),
              max(slr[1],tlr[1]),
              slr[0]*2+ tlr[1],
              slr[0]+ tlr[1]*2,
              slr[1]*2 + tlr[0],
              slr[1]+ tlr[0]*2
              )
    print(ans)
    

Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 24 22:10:01 2019

@author: Yamazaki Kenichi
"""
import numpy as np
import bisect

A,B,Q = map(int,input().split())
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
x = [int(input()) for i in range(Q)]

def lr(s,c,A):
    si = bisect.bisect(s,c)
    if si == A:
        return [c-s[si-1], 10**11]
    elif si == 0:
        return [10**11, s[0]-c]
    else:
        return [c-s[si-1], s[si]-c]
for c in x:
    ans = 0
    slr = lr(s,c,A)
    tlr = lr(t,c,B)
    ans = min(max(slr[0],tlr[0]),
              max(slr[1],tlr[1]),
              slr[0]*2+ tlr[1],
              slr[0]+ tlr[1]*2,
              slr[1]*2 + tlr[0],
              slr[1]+ tlr[0]*2
              )
    print(ans)
Buggy code:
import bisect

A, B, Q = map(int, input().split())
INF = 10 ** 10
s_list = [-INF] + [int(input()) for i in range(A)] + [INF]
t_list = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    near_right_s = bisect.bisect_right(s_list, x)
    near_right_t = bisect.bisect_right(t_list, x)
    min_distance = INF
    for s in [s_list[near_right_s - 1], s_list[near_right_s]]:
        for t in [t_list[near_right_t - 1], t_list[near_right_t]]:
            distance_1 = abs(s - x) + abs(t - s)
            distance_2 = abs(t - x) + abs(s - t)
            min_distance = min(min_distance, distance_1, distance_2)
    print(min_distance)

Fixed code:
import bisect

A, B, Q = map(int, input().split())
INF = 10 ** 11
s_list = [-INF] + [int(input()) for i in range(A)] + [INF]
t_list = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    near_right_s = bisect.bisect_right(s_list, x)
    near_right_t = bisect.bisect_right(t_list, x)
    min_distance = INF
    for s in [s_list[near_right_s - 1], s_list[near_right_s]]:
        for t in [t_list[near_right_t - 1], t_list[near_right_t]]:
            distance_1 = abs(s - x) + abs(t - s)
            distance_2 = abs(t - x) + abs(s - t)
            min_distance = min(min_distance, distance_1, distance_2)
    print(min_distance)
Buggy code:
import bisect
A,B,Q=map(int,input().split())
INF=10**18
S=[-INF]+[int(input()) for i in range(A)]+[INF]
T=[-INF]+[int(input()) for i in range(B)]+[INF]

print(S)
print(T)

for q in range(Q):
    x=int(input())
    i=bisect.bisect_right(S,x)
    j=bisect.bisect_right(T,x)
    d=INF
    for s in [S[i-1],S[i]]:
        for t in [T[j-1],T[j]]:
            d1=abs(s-x)+abs(s-t)
            d2=abs(t-x)+abs(s-t)
            d=min(d1,d2)
    print(d)
    

Fixed code:
import bisect
A,B,Q=map(int,input().split())
INF=10**18
S=[-INF]+[int(input()) for i in range(A)]+[INF]
T=[-INF]+[int(input()) for i in range(B)]+[INF]
for q in range(Q):
    x=int(input())
    s=bisect.bisect_right(S,x)
    t=bisect.bisect_right(T,x)
    d=INF
    for i in [S[s-1],S[s]]:
        for j in [T[t-1],T[t]]:
            ds=abs(i-x)+abs(i-j)
            dt=abs(j-x)+abs(i-j)
            d=min(d,ds,dt)
    print(d)
Buggy code:
improt bisect
A, B, Q = map(int, input().split())
ss = [int(input()) for i in range(A)]
ts = [int(input()) for i in range(B)]
xs = [int(input()) for i in range(Q)]
INF = 10**11

-INF, INF = -1, 10**10 + 1
ss = [-INF] + ss + [INF]
ts = [-INF] + ts + [INF]

# s_e is index the nearest s on the east side of x
for x in xs:
  s_e_ix = bisect.bisect_left(ss, x)
  s_e = ss[s_e_ix]
  s_w = ss[s_e_ix - 1]
  t_e_ix = bisect.bisect_left(ts, x)
  t_e = ts[t_e_ix]
  t_w_ix = ts[t_e_ix - 1]
  
  d = INF
  for s in [s_w, s_e]:
    for t in [t_w, t_e]:
      d0 = abs(s-x) + abs(t-s)
      d1 = abs(t-x) + abs(s-t)
      d = min(d0, d1, d)
  print(d)
  
                             

Fixed code:
import bisect
A, B, Q = map(int, input().split())
ss = [int(input()) for i in range(A)]
ts = [int(input()) for i in range(B)]
xs = [int(input()) for i in range(Q)]
INF = 10**11

ss = [-INF] + ss + [INF]
ts = [-INF] + ts + [INF]
 
# s_e is index the nearest s on the east side of x
for x in xs:
  s_e_ix = bisect.bisect_left(ss, x)
  s_e = ss[s_e_ix]
  s_w = ss[s_e_ix - 1]
  
  t_e_ix = bisect.bisect_left(ts, x)
  t_e = ts[t_e_ix]
  t_w = ts[t_e_ix - 1]
  
  d = INF
  for s in [s_w, s_e]:
    for t in [t_w, t_e]:
      d0 = abs(s-x) + abs(t-s)
      d1 = abs(t-x) + abs(s-t)
      d = min(d0, d1, d)
  print(d)
Buggy code:
import sys
from bisect import bisect.bisect_right 
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [sys.stdin.readline() for i in range(A)] + [INF]
t = [-INF] + [sys.stdin.readline() for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    #print(b,d)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)



Fixed code:
import bisect
import sys
A, B, Q = map(int, input().split())
INF = 10 ** 13
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(sys.stdin.readline())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)
Buggy code:
from bisect import bisect_right
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
xs = [int(input()) for i in range(Q)]
for x in xs:
    x = int(input())
    b, d = bisect_right(s, x), bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)


Fixed code:
import sys
from bisect import bisect_right
input = sys.stdin.readline
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
xs = [int(input()) for i in range(Q)]
for x in xs:
    b, d = bisect_right(s, x), bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)
Buggy code:
# D
from bisect import bisect_right
A,B,Q = map(int, input().split())
INF = float('inf')
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(A)] + [INF]
for q in range(Q):
    x = int(input())
    b,d = bisect_right(s, x), bisect_right(t, x)
    ans = INF
    for s_visit in [s[b-1], s[b]]:
        for t_visit in [t[d-1, t[d]]]:
            dist1 = abs(s_visit - x) + abs(t_visit - s_visit)
            dist2 = abs(t_visit - x) + abs(s_visit - t_visit)
            ans = min(ans, dist1, dist2)
    print(ans)

Fixed code:
# D
from bisect import bisect_right
A,B,Q = map(int, input().split())
INF = float('inf')
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b,d = bisect_right(s, x), bisect_right(t, x)
    ans = INF
    for s_visit in [s[b-1], s[b]]:
        for t_visit in [t[d-1], t[d]]:
            dist1 = abs(s_visit - x) + abs(t_visit - s_visit)
            dist2 = abs(t_visit - x) + abs(s_visit - t_visit)
            ans = min(ans, dist1, dist2)
    print(ans)
Buggy code:
import bisect as bi
a,b,q = map(int,input().split())
s = sorted([int(input()) for i in range(a) ])
t = sorted([int(input()) for i in range(b) ])
x = sorted([int(input()) for i in range(q) ])

for i in range(q):
    Q = x[i]
    ans_s = []
    ans_t = []
    ans_s.append(s[bi.bisect_left(s,Q)])
    ans_t.append(t[bi.bisect_left(t,Q)])
    ans = 10**11
    
    if bi.bisect_right(s,Q) == len(s):
        ans_s.append(s[bi.bisect_left(s,Q)-1])
    else:
        ans_s.append(s[bi.bisect_left(s,Q)])
        
    if bi.bisect_right(t,Q) == len(t):
        ans_t.append(t[bi.bisect_left(t,Q)-1])
    else:
        ans_t.append(t[bi.bisect_left(t,Q)])
    
    for i in range(2):
        for j in range(2):
            ans = max(ans,abs(ans_s[i]-Q)+abs(ans_s[i]-ans_t[j]),abs(ans_t[j]-Q)+abs(ans_s[i]-ans_t[j]))
    
    print(ans)

Fixed code:
import bisect as bi
a,b,q = map(int,input().split())
s = sorted([int(input()) for i in range(a) ])
t = sorted([int(input()) for i in range(b) ])
x = [int(input()) for i in range(q) ]

for i in range(q):
    Q = x[i]
    ans_s = []
    ans_t = []
    ans_s.append(s[bi.bisect_left(s,Q)-1])
    ans_t.append(t[bi.bisect_left(t,Q)-1])
    ans = 10**11
    
    if bi.bisect_right(s,Q) == len(s):
        ans_s.append(s[bi.bisect_left(s,Q)-1])
    else:
        ans_s.append(s[bi.bisect_left(s,Q)])
        
    if bi.bisect_right(t,Q) == len(t):
        ans_t.append(t[bi.bisect_left(t,Q)-1])
    else:
        ans_t.append(t[bi.bisect_left(t,Q)])
    
    for i in range(2):
        for j in range(2):
            ans = min(ans,abs(ans_s[i]-Q)+abs(ans_s[i]-ans_t[j]),abs(ans_t[j]-Q)+abs(ans_s[i]-ans_t[j]))
    
    print(ans)
Buggy code:
a,b,q = map(int,input().split())
s = [-float('inf')]+[int(input()) for i in range(a)]+[float('inf')]
t = [-float('inf')]+[int(input()) for i in range(b)]+[float('inf')]
x = [int(input()) for i in range(q)]
import bisect
for x_ in x:
    s_r = bisect.bisect_right(s,x_)
    t_r = bisect.bisect_right(s,x_)
    res = INF
    for S in [s[s_r-1],s[s_r]]:
        for T in [t[t_r-1],t[t_r]]:
            d1 = abs(S-x_)+abs(T-S)
            d2 = abs(T-x_)+abs(S-T)
            res = min(res,d1,d2)
    print(res)

for ans_ in ans:
    print(ans_)

Fixed code:
a,b,q = map(int,input().split())
s = [-float('inf')]+[int(input()) for i in range(a)]+[float('inf')]
t = [-float('inf')]+[int(input()) for i in range(b)]+[float('inf')]
x = [int(input()) for i in range(q)]
import bisect
for x_ in x:
    s_r = bisect.bisect_right(s,x_)
    t_r = bisect.bisect_right(t,x_)
    res = float('inf')
    for S in [s[s_r-1],s[s_r]]:
        for T in [t[t_r-1],t[t_r]]:
            d1 = abs(S-x_)+abs(T-S)
            d2 = abs(T-x_)+abs(S-T)
            res = min(res,d1,d2)
    print(res)
Buggy code:
import bisect

A, B, Q = map(int, input().split())
INF = 10**18
S = [-INF]
for i in range(A):
    S.append(int(input()))
S.append(INF)
T = [-INF]
for i in range(B):
    T.append(int(input()))
    T.append(INF)
X = []
for i in range(Q):
    X.append(int(input()))

for x in X:
    ids, idt = bisect.bisect_right(S, x), bisect.bisect_right(T, x)
    print(min(abs(s-t) + min(abs(s-x), abs(t-x))
              for s in S[ids-1:ids+1] for t in T[idt-1:idt+1]))


Fixed code:
import bisect

A, B, Q = map(int, input().split())
INF = 10**18
S = [-INF]
for i in range(A):
    S.append(int(input()))
S.append(INF)
T = [-INF]
for i in range(B):
    T.append(int(input()))
T.append(INF)
X = []
for i in range(Q):
    X.append(int(input()))

for x in X:
    a, b = bisect.bisect_right(S, x), bisect.bisect_right(T, x)
    print(min(abs(s-t) + min(abs(s-x), abs(t-x))
              for s in S[a-1:a+1] for t in T[b-1:b+1]))
Buggy code:
import bisect

A, B, Q = map(int, input().split())

INF = 10 ** 18
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]

for x in range(Q):
  b = bisect.bisect_right(s, x)
  d = disect.bisect_right(t, x)
  dist = 0
  for sb in [s[b - 1], s[b]]:
    for td in [t[d - 1], t[d]]:
      d1, d2 = abs(x - sb) + abs(sb - td), abs(x - td) + abs(td - sb)
      dist = min(dist, d1, d2)
  print(dist)

Fixed code:
import bisect

A, B, Q = map(int, input().split())

INF = 10 ** 18
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]

for i in range(Q):
  x = int(input())
  b = bisect.bisect_right(s, x)
  d = bisect.bisect_right(t, x)
  dist = INF
  for sb in [s[b - 1], s[b]]:
    for td in [t[d - 1], t[d]]:
      d1, d2 = abs(x - sb) + abs(sb - td), abs(x - td) + abs(td - sb)
      dist = min(dist, d1, d2)
  print(dist)
Buggy code:
import bisect
import sys

def main():
  input = sys.stdin.readline
  A, B, Q = map(int, input().split())
  INF = 10**18
  S = [-INF] + [int(input()) for _ in range(A)] + [INF]
  T = [-INF] + [int(inout()) for _ in range(B)] + [INF]
  
  for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for s in [S[b-1], S[b]]:
      for t in [T[d-1], T[d]]:
        d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)
        res = min(res, d1, d2)
  print(res)


if __name__ == '__main__':
  main()

Fixed code:
import bisect


def main():
    A, B, Q = map(int, input().split())
    INF = 10 ** 18
    s = [-INF] + [int(input()) for _ in range(A)] + [INF]
    t = [-INF] + [int(input()) for _ in range(B)] + [INF]
    for q in range(Q):
        x = int(input())
        b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
        res = INF
        for S in [s[b-1], s[b]]:
            for T in [t[d-1], t[d]]:
                d1 = abs(S-x) + abs(T-S)
                d2 = abs(T-x) + abs(S-T)
                res = min(res, d1, d2)
        print(res)


if __name__ == "__main__":
    main()