Buggy python submission (verdict: Time Limit Exceeded):
#import numpy as np

def getNearestValue(list, num):
    last=0

    for i in list:
        if i < num:
            last = i
        else:
            if last==0: 
                return i

            if num - last > i - num:
                return i
            else:
                return last

    return last

    # idx = np.searchsorted(list, num, side="left")
    # if idx > 0 and (idx == len(list) or abs(num - list[idx-1]) < abs(num - list[idx])):
    #     return list[idx-1]
    # else:
    #     return list[idx]

    # idx = np.abs(np.asarray(list) - num).argmin()
    # return list[idx]

def main():
    A, B, Q = map(int, input().split())  #複数数値入力
    S = [0] * A
    T = [0] * B
    X = [0] * Q
    for i in range(A):
        S[i] = int(input())
    for i in range(B):
        T[i] = int(input())
    for i in range(Q):
        X[i] = int(input())

    for i in range(Q):
        # 1:神社先
        basyo1 = getNearestValue(S, X[i])   
        dist1 = abs(basyo1 - X[i])
        dist1 += abs(getNearestValue(T, basyo1) -basyo1)

        # 2:寺先
        basyo2 = getNearestValue(T, X[i])
        dist2 = abs(basyo2 - X[i])
        dist2 += abs(getNearestValue(S, basyo2) -basyo2)

        print(min(dist1, dist2))


main()

Fixed submission:
import bisect

A, B, Q = map(int, input().split())  # 複数数値入力
S = [0] * A
T = [0] * B
X = [0] * Q
for i in range(A):
    S[i] = int(input())
for i in range(B):
    T[i] = int(input())
for i in range(Q):
    X[i] = int(input())

S.insert(0, -float("inf"))
S.append(float("inf"))
T.insert(0, -float("inf"))
T.append(float("inf"))

for i in range(Q):
    b = bisect.bisect_right(S, X[i])
    d = bisect.bisect_right(T, X[i])
    res = float("inf")
    for s in [S[b - 1], S[b]]:
        for t in [T[d - 1], T[d]]:
            d1 = abs(s - X[i]) + abs(t - s)  # 先に神社
            d2 = abs(t - X[i]) + abs(t - s)  # 先に寺
            res = min(res, d1, d2)

    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def getNearestValue(list, num):
    idx = np.searchsorted(list, num, side="left")
    if idx > 0 and (idx == len(list) or abs(num - list[idx-1]) < abs(num - list[idx])):
        return list[idx-1]
    else:
        return list[idx]

#    idx = np.abs(np.asarray(list) - num).argmin()
#    return list[idx]

def main():
    A, B, Q = map(int, input().split())  #複数数値入力
    S = [0] * A
    T = [0] * B
    X = [0] * Q
    for i in range(A):
        S[i] = int(input())
    for i in range(B):
        T[i] = int(input())
    for i in range(Q):
        X[i] = int(input())

    for i in range(Q):
        ans = 0

        # 1:神社先
        basyo1 = getNearestValue(S, X[i])   
        dist1 = abs(basyo1 - X[i])
        dist1 += abs(getNearestValue(T, basyo1) -basyo1)

        # 2:寺先
        basyo2 = getNearestValue(T, X[i])
        dist2 = abs(basyo2 - X[i])
        dist2 += abs(getNearestValue(S, basyo2) -basyo2)

        ans += min(dist1, dist2)
        print(ans)


main()

Fixed submission:
import bisect

A, B, Q = map(int, input().split())  # 複数数値入力
S = [0] * A
T = [0] * B
X = [0] * Q
for i in range(A):
    S[i] = int(input())
for i in range(B):
    T[i] = int(input())
for i in range(Q):
    X[i] = int(input())

S.insert(0, -float("inf"))
S.append(float("inf"))
T.insert(0, -float("inf"))
T.append(float("inf"))

for i in range(Q):
    b = bisect.bisect_right(S, X[i])
    d = bisect.bisect_right(T, X[i])
    res = float("inf")
    for s in [S[b - 1], S[b]]:
        for t in [T[d - 1], T[d]]:
            d1 = abs(s - X[i]) + abs(t - s)  # 先に神社
            d2 = abs(t - X[i]) + abs(t - s)  # 先に寺
            res = min(res, d1, d2)

    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

# リストからある値に最も近い値を返却する関数
def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

def main():
    A, B, Q = map(int, input().split())  #複数数値入力
    S = [0] * A
    T = [0] * B
    X = [0] * Q
    for i in range(A):
        S[i] = int(input())
    for i in range(B):
        T[i] = int(input())
    for i in range(Q):
        X[i] = int(input())

    for i in range(Q):
        ans = 0

        # 1:神社先
        basyo1 = getNearestValue(S, X[i])
        dist1 = abs(basyo1 - X[i])
        dist1 += abs(getNearestValue(T, basyo1) -basyo1)

        # 2:寺先
        basyo2 = getNearestValue(T, X[i])
        dist2 = abs(basyo2 - X[i])
        dist2 += abs(getNearestValue(S, basyo2) -basyo2)

        ans += min(dist1, dist2)
        print(ans)


main()

Fixed submission:
import bisect

A, B, Q = map(int, input().split())  # 複数数値入力
S = [0] * A
T = [0] * B
X = [0] * Q
for i in range(A):
    S[i] = int(input())
for i in range(B):
    T[i] = int(input())
for i in range(Q):
    X[i] = int(input())

S.insert(0, -float("inf"))
S.append(float("inf"))
T.insert(0, -float("inf"))
T.append(float("inf"))

for i in range(Q):
    b = bisect.bisect_right(S, X[i])
    d = bisect.bisect_right(T, X[i])
    res = float("inf")
    for s in [S[b - 1], S[b]]:
        for t in [T[d - 1], T[d]]:
            d1 = abs(s - X[i]) + abs(t - s)  # 先に神社
            d2 = abs(t - X[i]) + abs(t - s)  # 先に寺
            res = min(res, d1, d2)

    print(res)