Buggy python submission (verdict: Time Limit Exceeded):

A,B,Q = (int(i) for i in 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 math
s_t = [0] * A #min dis form s to t
for i in range(A):
    max_ = B - 1
    min_ = 0
    k = int(max_ / 2)
    while(abs(max_ - min_)>1):
        if abs(t[k + 1] - s[i]) >  abs(t[k] - s[i]):
            max_ = k
            k =  int((k+min_) / 2)
        else:
            min_ = k
            k = int((k+max_)/2)
    k = max_
    if abs(t[max_] - s[i]) >  abs(t[min_] - s[i]):
        k = min_
    s_t[i] = abs(t[k] - s[i])

t_s = [0] * B #min dis form t to s
for i in range(B):
    max_ = A - 1
    min_ = 0
    k = int(max_ / 2)
    while(abs(max_ - min_)>1):
        if abs(s[k + 1] - t[i]) >  abs(s[k] - t[i]):
            max_ = k
            k =  int((k+min_) / 2)
        else:
            min_ = k
            k = int((k+max_)/2)
    k = max_
    if abs(s[max_] - t[i]) >  abs(s[min_] - t[i]):
        k = min_
    t_s[i] = abs(s[k] - t[i])


for i in range(Q):
    dis = []
    #first s
    max_ = A - 1
    min_ = 0
    k = int(max_ / 2)
    while(abs(max_ - min_)>1):
        if abs(s[k + 1] - x[i]) >  abs(s[k] - x[i]):
            max_ = k
            k =  int((k+min_) / 2)
        else:
            min_ = k
            k = int((k+max_)/2)
    k = max_
    if abs(s[max_] - x[i]) >  abs(s[min_] - x[i]):
        k = min_

    dis.append(abs(s[k] - x[i]) + s_t[k])
    if k > 0:
        dis.append(abs(s[k-1] - x[i]) + s_t[k-1])
    if k+1<A:
        dis.append(abs(s[k+1] - x[i]) + s_t[k+1])

    #first t
    max_ = B - 1
    min_ = 0
    k = int(max_ / 2)
    while(abs(max_ - min_)>1):
        if abs(t[k + 1] - x[i]) >  abs(t[k] - x[i]):
            max_ = k
            k =  int((k+min_) / 2)
        else:
            min_ = k
            k = int((k+max_)/2)
    k = max_
    if abs(t[max_] - x[i]) >  abs(t[min_] - x[i]):
        k = min_

    dis.append(abs(t[k] - x[i]) + t_s[k])
    if k > 0:
        dis.append(abs(t[k-1] - x[i]) + t_s[k-1])
    if k+1<B:
        dis.append(abs(t[k+1] - x[i]) + t_s[k+1])

    print(sorted(dis)[0])

    


Fixed submission:

A,B,Q = (int(i) for i in 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 math
s_t = [0] * A #min dis form s to t
for i in range(A):
    max_ = B - 1
    min_ = 0
    k = int(max_ / 2)
    while(abs(max_ - min_)>1):
        if abs(t[k + 1] - s[i]) >  abs(t[k] - s[i]):
            max_ = k
            k =  int((k+min_) / 2)
        else:
            min_ = k
            k = int((k+max_)/2)
    k = max_
    if abs(t[max_] - s[i]) >  abs(t[min_] - s[i]):
        k = min_
    s_t[i] = abs(t[k] - s[i])

t_s = [0] * B #min dis form t to s
for i in range(B):
    max_ = A - 1
    min_ = 0
    k = int(max_ / 2)
    while(abs(max_ - min_)>1):
        if abs(s[k + 1] - t[i]) >  abs(s[k] - t[i]):
            max_ = k
            k =  int((k+min_) / 2)
        else:
            min_ = k
            k = int((k+max_)/2)
    k = max_
    if abs(s[max_] - t[i]) >  abs(s[min_] - t[i]):
        k = min_
    t_s[i] = abs(s[k] - t[i])


for i in range(Q):
    dis = []
    #first s
    max_ = A - 1
    min_ = 0
    k = int(max_ / 2)
    while(abs(max_ - min_)>1):
        if abs(s[k + 1] - x[i]) >  abs(s[k] - x[i]):
            max_ = k
            k =  int((k+min_) / 2)
        else:
            min_ = k
            k = int((k+max_)/2)
    k = max_
    if abs(s[max_] - x[i]) >  abs(s[min_] - x[i]):
        k = min_

    dis.append(abs(s[k] - x[i]) + s_t[k])
    if k > 0:
        dis.append(abs(s[k-1] - x[i]) + s_t[k-1])
    if k+1<A:
        dis.append(abs(s[k+1] - x[i]) + s_t[k+1])

    #first t
    max_ = B - 1
    min_ = 0
    k = int(max_ / 2)
    while(abs(max_ - min_)>1):
        if abs(t[k + 1] - x[i]) >  abs(t[k] - x[i]):
            max_ = k
            k =  int((k+min_) / 2)
        else:
            min_ = k
            k = int((k+max_)/2)
    k = max_
    if abs(t[max_] - x[i]) >  abs(t[min_] - x[i]):
        k = min_

    dis.append(abs(t[k] - x[i]) + t_s[k])
    if k > 0:
        dis.append(abs(t[k-1] - x[i]) + t_s[k-1])
    if k+1<B:
        dis.append(abs(t[k+1] - x[i]) + t_s[k+1])

    print(sorted(dis)[0])