Buggy python submission (verdict: Time Limit Exceeded):
import math

A,B,Q = map(int, input().split())
S=[0]*A
T=[0]*B
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
S.append(10**11)
S.insert(0,(-1)*(10**11))
T.append(10**11)
T.insert(0,(-1)*(10**11))
for i in range(Q):
  x = int(input())
  floor = 0
  ceil = len(S)-1
  while ceil-floor > 1:
    half = math.floor((floor+ceil)/2)
    s = S[half]
    if s < x:
      floor = half
    else:
      ceil = half
  nearest_x_S = [S[floor]-x, S[ceil]-x]
        
  floor = 0
  ceil = len(T)-1
  while ceil-floor > 1:
    half = math.floor((floor+ceil)/2)
    t = T[half]
    if t < x:
      floor = half
    else:
      ceil = half
  nearest_x_T = [T[floor]-x, T[ceil]-x]
  
  ans_cand = []
  for x_S in nearest_x_S:
    for x_T in nearest_x_T:
      if x_S*x_T > 0:
        ans_cand.append(max(abs(x_S),abs(x_T)))
      else:
        ans_cand.append(abs(x_S)+abs(x_T)+min(abs(x_S),abs(x_T)))
  print(int(min(ans_cand)))

Fixed submission:
mod = 1000000007
eps = 10**-9
inf = 10**15


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.buffer.readline

    A, B, Q = map(int, input().split())
    S = [-inf]
    for _ in range(A):
        S.append(int(input()))
    S.append(inf)
    T = [-inf]
    for _ in range(B):
        T.append(int(input()))
    T.append(inf)

    for _ in range(Q):
        x = int(input())
        i = bisect_left(S, x)
        j = bisect_left(T, x)
        ans = []
        ans.append(x - S[i-1] + abs(S[i-1] - T[j-1]))
        ans.append(x - S[i-1] + abs(S[i-1] - T[j]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i-1]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i]))
        ans.append(S[i] - x + abs(S[i] - T[j-1]))
        ans.append(S[i] - x + abs(S[i] - T[j]))
        ans.append(T[j] - x + abs(T[j] - S[i-1]))
        ans.append(T[j] - x + abs(T[j] - S[i]))
        print(min(ans))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math

A,B,Q = map(int, input().split())
S=[0]*A
T=[0]*B
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
S.append(10**11)
S.insert(0,(-1)*(10**11))
T.append(10**11)
T.insert(0,(-1)*(10**11))
for i in range(Q):
  x = int(input())
  floor = 0
  ceil = len(S)-1
  while ceil-floor > 1:
    half = math.floor((floor+ceil)/2)
    s = S[half]
    if s < x:
      floor = half
    else:
      ceil = half
  nearest_x_S = [S[floor]-x, S[ceil]-x]
        
  floor = 0
  ceil = len(T)-1
  while ceil-floor > 1:
    half = math.floor((floor+ceil)/2)
    t = T[half]
    if t < x:
      floor = half
    else:
      ceil = half
  nearest_x_T = [T[floor]-x, T[ceil]-x]
  
  ans_cand = []
  for x_S in nearest_x_S:
    for x_T in nearest_x_T:
      if x_S*x_T > 0:
        ans_cand.append(max(abs(x_S),abs(x_T)))
      else:
        ans_cand.append(abs(x_S)+abs(x_T)+min(abs(x_S),abs(x_T)))
  print(int(min(ans_cand)))
  
  


Fixed submission:
mod = 1000000007
eps = 10**-9
inf = 10**15


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.buffer.readline

    A, B, Q = map(int, input().split())
    S = [-inf]
    for _ in range(A):
        S.append(int(input()))
    S.append(inf)
    T = [-inf]
    for _ in range(B):
        T.append(int(input()))
    T.append(inf)

    for _ in range(Q):
        x = int(input())
        i = bisect_left(S, x)
        j = bisect_left(T, x)
        ans = []
        ans.append(x - S[i-1] + abs(S[i-1] - T[j-1]))
        ans.append(x - S[i-1] + abs(S[i-1] - T[j]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i-1]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i]))
        ans.append(S[i] - x + abs(S[i] - T[j-1]))
        ans.append(S[i] - x + abs(S[i] - T[j]))
        ans.append(T[j] - x + abs(T[j] - S[i-1]))
        ans.append(T[j] - x + abs(T[j] - S[i]))
        print(min(ans))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math

A,B,Q = map(int, input().split())
S=[0]*A
T=[0]*B
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
S.append(10**11)
S.insert(0,(-1)*(10**11))
T.append(10**11)
T.insert(0,(-1)*(10**11))
for i in range(Q):
  x = int(input())
  floor = 0
  ceil = len(S)-1
  while ceil-floor > 1:
    half = math.floor((floor+ceil)/2)
    s = S[half]
    if s < x:
      floor = half
    elif x < s:
      ceil = half
    else:
      floor = half
      ceil = half+1
  nearest_x_S = [S[floor]-x, S[ceil]-x]
        
  floor = 0
  ceil = len(T)-1
  while ceil-floor > 1:
    half = math.floor((floor+ceil)/2)
    t = T[half]
    if t < x:
      floor = half
    elif x < t:
      ceil = half
    else:
      floor = half
      ceil = half+1
  nearest_x_T = [T[floor]-x, T[ceil]-x]
  
  ans_cand = []
  for x_S in nearest_x_S:
    for x_T in nearest_x_T:
      if x_S*x_T > 0:
        ans_cand.append(max(abs(x_S),abs(x_T)))
      else:
        ans_cand.append(abs(x_S)+abs(x_T)+min(abs(x_S),abs(x_T)))
  print(int(min(ans_cand)))
  
  


Fixed submission:
mod = 1000000007
eps = 10**-9
inf = 10**15


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.buffer.readline

    A, B, Q = map(int, input().split())
    S = [-inf]
    for _ in range(A):
        S.append(int(input()))
    S.append(inf)
    T = [-inf]
    for _ in range(B):
        T.append(int(input()))
    T.append(inf)

    for _ in range(Q):
        x = int(input())
        i = bisect_left(S, x)
        j = bisect_left(T, x)
        ans = []
        ans.append(x - S[i-1] + abs(S[i-1] - T[j-1]))
        ans.append(x - S[i-1] + abs(S[i-1] - T[j]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i-1]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i]))
        ans.append(S[i] - x + abs(S[i] - T[j-1]))
        ans.append(S[i] - x + abs(S[i] - T[j]))
        ans.append(T[j] - x + abs(T[j] - S[i-1]))
        ans.append(T[j] - x + abs(T[j] - S[i]))
        print(min(ans))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import math

A,B,Q = map(int, input().split())
S=[0]*A
T=[0]*B
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
S.append(10**11)
S.insert(0,(-1)*(10**11))
T.append(10**11)
T.insert(0,(-1)*(10**11))
for i in range(Q):
  x = int(input())
  floor = 0
  ceil = len(S)-1
  while ceil-floor > 1:
    half = math.floor((floor+ceil)/2)
    s = S[half]
    if s < x:
      floor = half
    elif x < s:
      ceil = half
    else:
      floor = half
      ceil = half+1
  nearest_x_S = [S[floor]-x, S[ceil]-x]
        
  floor = 0
  ceil = len(S)-1
  while ceil-floor > 1:
    half = math.floor((floor+ceil)/2)
    t = T[half]
    if t < x:
      floor = half
    elif x < t:
      ceil = half
    else:
      floor = half
      ceil = half+1
  nearest_x_T = [T[floor]-x, T[ceil]-x]
  
  ans_cand = []
  for x_S in nearest_x_S:
    for x_T in nearest_x_T:
      if x_S*x_T > 0:
        ans_cand.append(max(abs(x_S),abs(x_T)))
      else:
        ans_cand.append(abs(x_S)+abs(x_T)+min(abs(x_S),abs(x_T)))
  print(int(min(ans_cand)))
  
  


Fixed submission:
mod = 1000000007
eps = 10**-9
inf = 10**15


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.buffer.readline

    A, B, Q = map(int, input().split())
    S = [-inf]
    for _ in range(A):
        S.append(int(input()))
    S.append(inf)
    T = [-inf]
    for _ in range(B):
        T.append(int(input()))
    T.append(inf)

    for _ in range(Q):
        x = int(input())
        i = bisect_left(S, x)
        j = bisect_left(T, x)
        ans = []
        ans.append(x - S[i-1] + abs(S[i-1] - T[j-1]))
        ans.append(x - S[i-1] + abs(S[i-1] - T[j]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i-1]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i]))
        ans.append(S[i] - x + abs(S[i] - T[j-1]))
        ans.append(S[i] - x + abs(S[i] - T[j]))
        ans.append(T[j] - x + abs(T[j] - S[i-1]))
        ans.append(T[j] - x + abs(T[j] - S[i]))
        print(min(ans))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math

A,B,Q = map(int, input().split())
S=[0]*A
T=[0]*B
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
S.append(float('inf'))
S.insert(0,(-1)*float('inf'))
T.append(float('inf'))
T.insert(0,(-1)*float('inf'))
for i in range(Q):
  x = int(input())
  floor = 0
  ceil = len(S)-1
  index = math.floor(A/2)
  while True:
    s = S[index]
    s_before = S[index-1]
    s_next = S[index+1]
    if s < x:
      if x <= s_next:
        nearest_x_S = [s-x, s_next-x]
        break
      else:
        floor = index
        index = math.floor((floor+ceil)/2)
    elif x < s:
      if s_before <= x:
        nearest_x_S = [s_before-x, s-x]
        break
      else:
        ceil = index
        index = math.floor((floor+ceil)/2)
        
  floor = 0
  ceil = len(T)-1
  index = math.floor(B/2)
  while True:
    t = T[index]
    t_before = T[index-1]
    t_next = T[index+1]
    if t < x:
      if x <= t_next:
        nearest_x_T = [t-x, t_next-x]
        break
      else:
        floor = index
        index = math.floor((floor+ceil)/2)
    elif x < t:
      if t_before <= x:
        nearest_x_T = [t_before-x, t-x]
        break
      else:
        ceil = index
        index = math.floor((floor+ceil)/2)

  ans_cand = []
  for x_S in nearest_x_S:
    for x_T in nearest_x_T:
      if x_S*x_T > 0:
        ans_cand.append(max(abs(x_S),abs(x_T)))
      else:
        ans_cand.append(abs(x_S)+abs(x_T)+min(abs(x_S),abs(x_T)))
  print(int(min(ans_cand)))

Fixed submission:
mod = 1000000007
eps = 10**-9
inf = 10**15


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.buffer.readline

    A, B, Q = map(int, input().split())
    S = [-inf]
    for _ in range(A):
        S.append(int(input()))
    S.append(inf)
    T = [-inf]
    for _ in range(B):
        T.append(int(input()))
    T.append(inf)

    for _ in range(Q):
        x = int(input())
        i = bisect_left(S, x)
        j = bisect_left(T, x)
        ans = []
        ans.append(x - S[i-1] + abs(S[i-1] - T[j-1]))
        ans.append(x - S[i-1] + abs(S[i-1] - T[j]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i-1]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i]))
        ans.append(S[i] - x + abs(S[i] - T[j-1]))
        ans.append(S[i] - x + abs(S[i] - T[j]))
        ans.append(T[j] - x + abs(T[j] - S[i-1]))
        ans.append(T[j] - x + abs(T[j] - S[i]))
        print(min(ans))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math

A,B,Q = map(int, input().split())
S=[0]*A
T=[0]*B
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
S.append(float('inf'))
S.insert(0,(-1)*float('inf'))
T.append(float('inf'))
T.insert(0,(-1)*float('inf'))
for i in range(Q):
  x = int(input())
  floor = 0
  ceil = len(S)-1
  index = math.floor(A/2)
  while True:
    if S[index] < x:
      if x <= S[index+1]:
        nearest_x_S = [S[index]-x, S[index+1]-x]
        break
      else:
        floor = index
        index = math.floor((floor+ceil)/2)
    elif x < S[index]:
      if S[index-1] <= x:
        nearest_x_S = [S[index-1]-x, S[index]-x]
        break
      else:
        ceil = index
        index = math.floor((floor+ceil)/2)
        
  floor = 0
  ceil = len(T)-1
  index = math.floor(B/2)
  while True:
    if T[index] < x:
      if x <= T[index+1]:
        nearest_x_T = [T[index]-x, T[index+1]-x]
        break
      else:
        floor = index
        index = math.floor((floor+ceil)/2)
    elif x < T[index]:
      if T[index-1] <= x:
        nearest_x_T = [T[index-1]-x, T[index]-x]
        break
      else:
        ceil = index
        index = math.floor((floor+ceil)/2)

  ans_cand = []
  for x_S in nearest_x_S:
    for x_T in nearest_x_T:
      if x_S*x_T > 0:
        ans_cand.append(max(abs(x_S),abs(x_T)))
      else:
        ans_cand.append(abs(x_S)+abs(x_T)+min(abs(x_S),abs(x_T)))
  print(int(min(ans_cand)))
  
  


Fixed submission:
mod = 1000000007
eps = 10**-9
inf = 10**15


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.buffer.readline

    A, B, Q = map(int, input().split())
    S = [-inf]
    for _ in range(A):
        S.append(int(input()))
    S.append(inf)
    T = [-inf]
    for _ in range(B):
        T.append(int(input()))
    T.append(inf)

    for _ in range(Q):
        x = int(input())
        i = bisect_left(S, x)
        j = bisect_left(T, x)
        ans = []
        ans.append(x - S[i-1] + abs(S[i-1] - T[j-1]))
        ans.append(x - S[i-1] + abs(S[i-1] - T[j]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i-1]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i]))
        ans.append(S[i] - x + abs(S[i] - T[j-1]))
        ans.append(S[i] - x + abs(S[i] - T[j]))
        ans.append(T[j] - x + abs(T[j] - S[i-1]))
        ans.append(T[j] - x + abs(T[j] - S[i]))
        print(min(ans))


if __name__ == '__main__':
    main()

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

A,B,Q = map(int, input().split())
S=np.zeros([A])
T=np.zeros([B])
X=np.zeros([Q])
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
S = np.concatenate([[float('inf')],S,[float('inf')]],axis=0)
T = np.concatenate([[float('inf')],T,[float('inf')]],axis=0)
for i in range(Q):
  x = int(input())
  dist_x_S = S - x
  dist_x_S_abs = np.abs(dist_x_S)
  min_index = np.argmin(dist_x_S_abs)
  if dist_x_S[min_index] > 0:
    nearest_x_S = [dist_x_S[min_index-1], dist_x_S[min_index]]
  elif dist_x_S[min_index] < 0:
    nearest_x_S = [dist_x_S[min_index], dist_x_S[min_index+1]]
  else:
    nearest_x_S = [0, dist_x_S[np.argmin([np.abs(dist_x_S[min_index-1]),np.argmin(dist_x_S[min_index+1])])]]
  
  dist_x_T = T - x
  dist_x_T_abs = np.abs(dist_x_T)
  min_index = np.argmin(dist_x_T_abs)
  if dist_x_T[min_index] > 0:
    nearest_x_T = [dist_x_T[min_index-1], dist_x_T[min_index]]
  elif dist_x_T[min_index] < 0:
    nearest_x_T = [dist_x_T[min_index], dist_x_T[min_index+1]]
  else:
    nearest_x_T = [0, dist_x_T[np.argmin([np.abs(dist_x_T[min_index-1]),np.argmin(dist_x_T[min_index+1])])]]  
  
  ans_cand = []
  for x_S in nearest_x_S:
    for x_T in nearest_x_T:
      if x_S*x_T > 0:
        ans_cand.append(max(abs(x_S),abs(x_T)))
      else:
        ans_cand.append(abs(x_S)+abs(x_T)+min(abs(x_S),abs(x_T)))
  print(int(min(ans_cand)))
  
  


Fixed submission:
mod = 1000000007
eps = 10**-9
inf = 10**15


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.buffer.readline

    A, B, Q = map(int, input().split())
    S = [-inf]
    for _ in range(A):
        S.append(int(input()))
    S.append(inf)
    T = [-inf]
    for _ in range(B):
        T.append(int(input()))
    T.append(inf)

    for _ in range(Q):
        x = int(input())
        i = bisect_left(S, x)
        j = bisect_left(T, x)
        ans = []
        ans.append(x - S[i-1] + abs(S[i-1] - T[j-1]))
        ans.append(x - S[i-1] + abs(S[i-1] - T[j]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i-1]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i]))
        ans.append(S[i] - x + abs(S[i] - T[j-1]))
        ans.append(S[i] - x + abs(S[i] - T[j]))
        ans.append(T[j] - x + abs(T[j] - S[i-1]))
        ans.append(T[j] - x + abs(T[j] - S[i]))
        print(min(ans))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np

A,B,Q = map(int, input().split())
S=np.zeros([A])
T=np.zeros([B])
X=np.zeros([Q])
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
if A ==1:
  S = np.concatenate([S,[float('inf')]],axis=0)
if B ==1:
  T = np.concatenate([T,[float('inf')]],axis=0)
for i in range(Q):
  x = int(input())
  dist_x_S = S - x
  dist_x_S_abs = np.abs(dist_x_S)
  min_index = np.argmin(dist_x_S_abs)
  if dist_x_S[min_index] > 0:
    nearest_x_S = [dist_x_S[min_index-1], dist_x_S[min_index]]
  elif dist_x_S[min_index] < 0:
    nearest_x_S = [dist_x_S[min_index], dist_x_S[min_index+1]]
  else:
    nearest_x_S = [0, dist_x_S[np.argmin([np.abs(dist_x_S[min_index-1]),np.argmin(dist_x_S[min_index+1])])]]
  
  dist_x_T = T - x
  dist_x_T_abs = np.abs(dist_x_T)
  min_index = np.argmin(dist_x_T_abs)
  if dist_x_T[min_index] > 0:
    nearest_x_T = [dist_x_T[min_index-1], dist_x_T[min_index]]
  elif dist_x_T[min_index] < 0:
    nearest_x_T = [dist_x_T[min_index], dist_x_T[min_index+1]]
  else:
    nearest_x_T = [0, dist_x_T[np.argmin([np.abs(dist_x_T[min_index-1]),np.argmin(dist_x_T[min_index+1])])]]  
  
  ans_cand = []
  for x_S in nearest_x_S:
    for x_T in nearest_x_T:
      if x_S*x_T > 0:
        ans_cand.append(max(abs(x_S),abs(x_T)))
      else:
        ans_cand.append(abs(x_S)+abs(x_T)+min(abs(x_S),abs(x_T)))
  print(int(min(ans_cand)))
  
  


Fixed submission:
mod = 1000000007
eps = 10**-9
inf = 10**15


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.buffer.readline

    A, B, Q = map(int, input().split())
    S = [-inf]
    for _ in range(A):
        S.append(int(input()))
    S.append(inf)
    T = [-inf]
    for _ in range(B):
        T.append(int(input()))
    T.append(inf)

    for _ in range(Q):
        x = int(input())
        i = bisect_left(S, x)
        j = bisect_left(T, x)
        ans = []
        ans.append(x - S[i-1] + abs(S[i-1] - T[j-1]))
        ans.append(x - S[i-1] + abs(S[i-1] - T[j]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i-1]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i]))
        ans.append(S[i] - x + abs(S[i] - T[j-1]))
        ans.append(S[i] - x + abs(S[i] - T[j]))
        ans.append(T[j] - x + abs(T[j] - S[i-1]))
        ans.append(T[j] - x + abs(T[j] - S[i]))
        print(min(ans))


if __name__ == '__main__':
    main()

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

A,B,Q = map(int, input().split())
S=np.zeros([A])
T=np.zeros([B])
X=np.zeros([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 = int(input())
  dist_x_S = np.zeros([A,2])
  for j in range(A):
    dist_x_S[j][1] = S[j] - x
    dist_x_S[j][0] = np.abs(dist_x_S[j][1])
  sorted_dist_x_S = np.sort(dist_x_S,axis=0)
  if A > 1:
    nearest_x_S = np.array([sorted_dist_x_S[0][1],sorted_dist_x_S[1][1]])
  else:
    nearest_x_S = np.array([sorted_dist_x_S[0][1],float('inf')])
  
  dist_x_T = np.zeros([B,2])
  for j in range(B):
    dist_x_T[j][1] = T[j] - x
    dist_x_T[j][0] = np.abs(dist_x_T[j][1])
  sorted_dist_x_T = np.sort(dist_x_T,axis=0)
  if B > 1:
    nearest_x_T = np.array([sorted_dist_x_T[0][1],sorted_dist_x_T[1][1]])
  else:
    nearest_x_T = np.array([sorted_dist_x_T[0][1],float('inf')])
  
  ans_cand = []
  for x_S in nearest_x_S:
    for x_T in nearest_x_T:
      if x_S*x_T > 0:
        ans_cand.append(max(abs(x_S),abs(x_T)))
      else:
        ans_cand.append(abs(x_S)+abs(x_T)+min(abs(x_S),abs(x_T)))
  print(int(min(ans_cand)))

Fixed submission:
mod = 1000000007
eps = 10**-9
inf = 10**15


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.buffer.readline

    A, B, Q = map(int, input().split())
    S = [-inf]
    for _ in range(A):
        S.append(int(input()))
    S.append(inf)
    T = [-inf]
    for _ in range(B):
        T.append(int(input()))
    T.append(inf)

    for _ in range(Q):
        x = int(input())
        i = bisect_left(S, x)
        j = bisect_left(T, x)
        ans = []
        ans.append(x - S[i-1] + abs(S[i-1] - T[j-1]))
        ans.append(x - S[i-1] + abs(S[i-1] - T[j]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i-1]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i]))
        ans.append(S[i] - x + abs(S[i] - T[j-1]))
        ans.append(S[i] - x + abs(S[i] - T[j]))
        ans.append(T[j] - x + abs(T[j] - S[i-1]))
        ans.append(T[j] - x + abs(T[j] - S[i]))
        print(min(ans))


if __name__ == '__main__':
    main()