Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import numpy as np

a,b,q=map(int,input().split())

ST=[]
for i in range(a):
    k=int(input())
    ST.append([k,0,0])
for i in range(b):
    k=int(input())
    ST.append([k,1,0])

ST.sort()

le0=-1
le1=-1
ri0=1
ri1=1

for i in range(a+b):
    if ST[i][1]==0 :
        pa=1
        
        moyori=np.inf

        if le1>=0:
            moyori=min(moyori,abs(ST[i][0]-ST[le1][0]))
        if ri1<=i :
            ri1=i+1
            while ri1<=a+b-1 and ST[ri1][1]==ty :
                ri1+=1
        if ri1<=a+b-1:
            moyori=min(moyori,abs(ST[i][0]-ST[ri1][0]))
        ST[i][2]=moyori
        le0=i
    else:
        pa=0
        
        moyori=np.inf

        if le0>=0:
            moyori=min(moyori,abs(ST[i][0]-ST[le0][0]))
        if ri0<=i :
            ri0=i+1
            while ri0<=a+b-1 and ST[ri0][1]==ty :
                ri0+=1
        if ri0<=a+b-1:
            moyori=min(moyori,abs(ST[i][0]-ST[ri0][0]))
        ST[i][2]=moyori
        le1=i



#print(ST)

for i in range(q):
    k=int(input())
    ST.append([k,2,0,i])

ST.sort()

ANS=[]
le0=-1
le1=-1
ri0=1
ri1=1
for i in range(a+b+q):
    if ST[i][1]==0 :
        le0=i
    elif ST[i][1]==1 :
        le1=i
    elif ST[i][1]==2 :
        moyori=np.inf
    
            
        if le0>=0:
            moyori=min(moyori,abs(ST[i][0]-ST[le0][0])+ST[le0][2])
            #print("L"+str(le[typ]))
            
        if ri0<=i :
            ri0=i+1
            while ri0<=a+b+q-1 and (ST[ri0][1]==1 or ST[ri0][1]==2):
                ri0+=1
        if ri0<=a+b+q-1 :
            moyori=min(moyori,abs(ST[i][0]-ST[ri0][0])+ST[ri0][2])
            #print("R"+str(ri[typ]))
            

        if le1>=0:
            moyori=min(moyori,abs(ST[i][0]-ST[le1][0])+ST[le1][2])
            #print("L"+str(le[typ]))
            
        if ri1<=i :
            ri1=i+1
            while ri1<=a+b+q-1 and (ST[ri1][1]==0 or ST[ri1][1]==2):
                ri1+=1
        if ri1<=a+b+q-1 :
            moyori=min(moyori,abs(ST[i][0]-ST[ri1][0])+ST[ri1][2])
            #print("R"+str(ri[typ]))
            



        ST[i][2]=moyori
        ANS.append([ST[i][3],moyori])

ANS.sort()

#print(ST)

for i in range(q):
    print(ANS[i][1])


import bisect as bi

a,b,q=map(int,input().split())

INF=10**15

S=[-INF]+[int(input()) for i in range(a)]+[INF]
T=[-INF]+[int(input()) for i in range(b)]+[INF]
X=[int(input()) for i in range(q)]

for i in range(q):
    d=bi.bisect_right(S,X[i])
    e=bi.bisect_right(T,X[i])
    as0=abs(X[i]-S[d-1])
    as1=abs(X[i]-S[d])
    at0=abs(X[i]-T[e-1])
    at1=abs(X[i]-T[e])
    ans=min(max(as0,at0),max(as1,at1),2*as0+at1,as0+2*at1,2*at0+as1,at0+as1*2)
    print(ans)


Verdicts: Runtime Error

Accepted