Problem p03112 (python)

Fixed submission:
def main():
    INF=10**11
    from bisect import bisect_left
    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())
        s=bisect_left(S,x)
        t=bisect_left(T,x)
        ans=max(T[t],S[s])-x
        ans=min(ans,S[s]-T[t-1]+min(S[s]-x,x-T[t-1]))
        ans=min(ans,x-min(S[s-1],T[t-1]))
        ans=min(ans,T[t]-S[s-1]+min(T[t]-x,x-S[s-1]))
        print(ans)
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import numpy as np
    import sys
    input=sys.stdin.readline

    a,b,q=map(int,input().split())
    S=np.array([int(input()) for _ in range(a)])
    T=np.array([int(input()) for _ in range(b)])
    Q=np.array([int(input()) for _ in range(q)])
    idxs=np.searchsorted(S,Q)
    idxt=np.searchsorted(T,Q)
    
    for i in range(q):
        x=Q[i]
        s=idxs[i]
        t=idxt[i]
        
        if s==0 and t==0:
            print(max(S[0],T[0])-x)
        elif s==0 and t==b:
            print(S[0]-T[-1]+min(S[0]-x,x-T[-1]))               
        elif s==a and t==0:
            print(T[0]-S[-1]+min(T[0]-x,x-S[-1]))
        elif s==a and t==b:
            print(x-min(S[-1],T[-1]))
        
        elif s==0:
            print(min(max(S[0],T[t])-x,min(S[0]-x,x-T[t-1])+S[0]-T[t-1]))
        elif s==a:
            print(min(x-min(S[-1],T[t-1]),min(T[t]-x,x-S[-1])+T[t]-S[-1]))                  
        elif t==0:
            print(min(max(T[0],S[s])-x,min(T[0]-x,x-S[s-1])+T[0]-S[s-1]))
        elif t==b:
            print(min(x-min(T[-1],S[s-1]),min(S[t]-x,x-T[-1])+S[s]-T[-1]))
            
        else:
            print(min(max(T[t],S[s])-x,x-min(T[t-1],S[s-1])))   
  
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import numpy as np
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(1000000000)

    a,b,q=map(int,input().split())
    S=np.array([int(input()) for _ in range(a)])
    T=np.array([int(input()) for _ in range(b)])
    Q=np.array([int(input()) for _ in range(q)])
    idxs=np.searchsorted(S,Q)
    idxt=np.searchsorted(T,Q)
    
    for i in range(q):
        x=Q[i]
        s=idxs[i]
        t=idxt[i]
        if s==0 and t==0:
            print(max(S[0],T[0])-x)
        elif s==0 and t==b:
            print(S[0]-T[-1]+min(S[0]-x,x-T[-1]))
        elif s==0:
            print(min(max(S[0],T[t])-x,min(S[0]-x,x-T[t-1])+S[0]-T[t-1]))
                  
        elif s==a and t==0:
            print(T[0]-S[-1]+min(T[0]-x,x-S[-1]))
        elif s==a and t==b:
            print(x-min(S[-1],T[-1]))
        elif s==a:
            print(min(x-min(S[-1],T[t-1]),min(T[t]-x,x-S[-1])+T[t]-S[-1]))
                  
        elif t==0:
            print(min(max(T[0],S[s])-x,min(T[0]-x,x-S[s-1])+T[0]-S[s-1]))
        elif t==b:
            print(min(x-min(T[-1],S[s-1]),min(S[t]-x,x-T[-1])+S[s]-T[-1]))
        else:
            print(min(max(T[t],S[s])-x,x-min(T[t-1],S[s-1])))   
  
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import numpy as np
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(1000000000)

    a,b,q=map(int,input().split())
    S=np.array([int(input()) for _ in range(a)])
    T=np.array([int(input()) for _ in range(b)])
    
    for _ in range(q):
        x=int(input())
        s=np.searchsorted(S,x)
        t=np.searchsorted(T,x)
        if s==0 and t==0:
            print(max(S[0],T[0])-x)
        elif s==0 and t==b:
            print(S[0]-T[-1]+min(S[0]-x,x-T[-1]))
        elif s==0:
            print(min(max(S[0],T[t])-x,min(S[0]-x,x-T[t-1])+S[0]-T[t-1]))
                  
        elif s==a and t==0:
            print(T[0]-S[-1]+min(T[0]-x,x-S[-1]))
        elif s==a and t==b:
            print(x-min(S[-1],T[-1]))
        elif s==a:
            print(min(x-min(S[-1],T[t-1]),min(T[t]-x,x-S[-1])+T[t]-S[-1]))
                  
        elif t==0:
            print(min(max(T[0],S[s])-x,min(T[0]-x,x-S[s-1])+T[0]-S[s-1]))
        elif t==b:
            print(min(x-min(T[-1],S[s-1]),min(S[t]-x,x-T[-1])+S[s]-T[-1]))
        else:
            print(min(max(T[t],S[s])-x,x-min(T[t-1],S[s-1])))   
  
if __name__=='__main__':
    main()