Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

def main():
  N_a, N_b, N_q = map(int, input().strip().split(' '))
  As = list(map(int, [input().strip() for _ in range(N_a)]))
  Bs = list(map(int, [input().strip() for _ in range(N_b)]))
  Qs = list(map(int, [input().strip() for _ in range(N_q)]))

  for q in Qs:
    min_a_l = -(2*(10**10)+1)
    min_b_l = -(2*(10**10)+1)
    min_a_r = 2*(10**10)+1
    min_b_r = 2*(10**10)+1
    i = 0
    for a in As:
      da = a - q
      if da < 0:
        i += 1
      elif da > 0:
        min_a_r = da
        if i-1>=0:
          min_a_l = As[i-1] - q
        break
    if i == len(As):
      min_a_l = As[-1] - q


    i = 0
    for b in Bs:
      db = b - q
      if db < 0:
        i += 1
      elif db > 0:
        min_b_r = db
        if i-1>=0:
          min_b_l = Bs[i-1] - q
        break
    if i == len(Bs):
      min_b_l = Bs[-1] - q

    score = min([
      min_a_r if min_a_r > min_b_r else min_b_r,
      abs(min_a_l) if min_a_l < min_b_l else abs(min_b_l),
      2*min_a_r + abs(min_b_l) if min_a_r < abs(min_b_l) else min_a_r + 2*abs(min_b_l),
      2*abs(min_a_l) + abs(min_b_r) if abs(min_a_l) < abs(min_b_r) else abs(min_a_l) + 2*abs(min_b_r)])
    print(score)

  pass

if __name__=='__main__':
  main()

Fixed submission:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from bisect import bisect_left

def main():
  N_a, N_b, N_q = map(int, input().strip().split(' '))
  As = list(map(int, [input().strip() for _ in range(N_a)]))
  Bs = list(map(int, [input().strip() for _ in range(N_b)]))
  Qs = list(map(int, [input().strip() for _ in range(N_q)]))

  for q in Qs:
    min_a_l = -(2*(10**10)+1)
    min_b_l = -(2*(10**10)+1)
    min_a_r = 2*(10**10)+1
    min_b_r = 2*(10**10)+1
    a_index = bisect_left(As, q)
    if len(As) > a_index-1 >= 0:
      min_a_l = As[a_index-1] - q
    if a_index < len(As):
      min_a_r = As[a_index] - q

    b_index = bisect_left(Bs, q)
    if len(Bs) > b_index-1 >= 0:
      min_b_l = Bs[b_index-1] - q
    if b_index < len(Bs):
      min_b_r = Bs[b_index] - q

    score = min([
      min_a_r if min_a_r > min_b_r else min_b_r,
      abs(min_a_l) if min_a_l < min_b_l else abs(min_b_l),
      2*min_a_r + abs(min_b_l) if min_a_r < abs(min_b_l) else min_a_r + 2*abs(min_b_l),
      2*abs(min_a_l) + abs(min_b_r) if abs(min_a_l) < abs(min_b_r) else abs(min_a_l) + 2*abs(min_b_r)])
    print(score)

  pass

if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

def main():
  N_a, N_b, N_q = map(int, input().strip().split(' '))
  As = list(map(int, [input().strip() for _ in range(N_a)]))
  Bs = list(map(int, [input().strip() for _ in range(N_b)]))
  Qs = list(map(int, [input().strip() for _ in range(N_q)]))

  for q in Qs:
    min_a_l = -(2*(10**10)+1)
    min_b_l = -(2*(10**10)+1)
    min_a_r = 2*(10**10)+1
    min_b_r = 2*(10**10)+1
    for a in As:
      da = a - q
      if 0 <= da < min_a_r:
          min_a_r = da
          break
      if 0 > da >= min_a_l:
          min_a_l = da

    for b in Bs:
      db = b - q
      if 0<= db < min_b_r:
          min_b_r = db
          break
      if 0 > db >= min_b_l:
          min_b_l = db
    score = min([
      min_a_r if min_a_r > min_b_r else min_b_r,
      abs(min_a_l) if min_a_l < min_b_l else abs(min_b_l),
      2*min_a_r + abs(min_b_l) if min_a_r < abs(min_b_l) else min_a_r + 2*abs(min_b_l),
      2*abs(min_a_l) + abs(min_b_r) if abs(min_a_l) < abs(min_b_r) else abs(min_a_l) + 2*abs(min_b_r)])
    print(score)

  pass

if __name__=='__main__':
  main()

Fixed submission:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from bisect import bisect_left

def main():
  N_a, N_b, N_q = map(int, input().strip().split(' '))
  As = list(map(int, [input().strip() for _ in range(N_a)]))
  Bs = list(map(int, [input().strip() for _ in range(N_b)]))
  Qs = list(map(int, [input().strip() for _ in range(N_q)]))

  for q in Qs:
    min_a_l = -(2*(10**10)+1)
    min_b_l = -(2*(10**10)+1)
    min_a_r = 2*(10**10)+1
    min_b_r = 2*(10**10)+1
    a_index = bisect_left(As, q)
    if len(As) > a_index-1 >= 0:
      min_a_l = As[a_index-1] - q
    if a_index < len(As):
      min_a_r = As[a_index] - q

    b_index = bisect_left(Bs, q)
    if len(Bs) > b_index-1 >= 0:
      min_b_l = Bs[b_index-1] - q
    if b_index < len(Bs):
      min_b_r = Bs[b_index] - q

    score = min([
      min_a_r if min_a_r > min_b_r else min_b_r,
      abs(min_a_l) if min_a_l < min_b_l else abs(min_b_l),
      2*min_a_r + abs(min_b_l) if min_a_r < abs(min_b_l) else min_a_r + 2*abs(min_b_l),
      2*abs(min_a_l) + abs(min_b_r) if abs(min_a_l) < abs(min_b_r) else abs(min_a_l) + 2*abs(min_b_r)])
    print(score)

  pass

if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

def main():
  N_a, N_b, N_q = map(int, input().strip().split(' '))
  As = list(map(int, [input().strip() for _ in range(N_a)]))
  Bs = list(map(int, [input().strip() for _ in range(N_b)]))
  Qs = list(map(int, [input().strip() for _ in range(N_q)]))

  for q in Qs:
    min_a_l = -(2*(10**10)+1)
    min_b_l = -(2*(10**10)+1)
    min_a_r = 2*(10**10)+1
    min_b_r = 2*(10**10)+1
    for a in As:
      da = a - q
      if 0 <= da < min_a_r:
          min_a_r = da
      if 0 > da >= min_a_l:
          min_a_l = da

    for b in Bs:
      db = b - q
      if 0<= db < min_b_r:
          min_b_r = db
      if 0 > db >= min_b_l:
          min_b_l = db
    score = min([
      min_a_r if min_a_r > min_b_r else min_b_r,
      abs(min_a_l) if min_a_l < min_b_l else abs(min_b_l),
      2*min_a_r + abs(min_b_l) if min_a_r < abs(min_b_l) else min_a_r + 2*abs(min_b_l),
      2*abs(min_a_l) + abs(min_b_r) if abs(min_a_l) < abs(min_b_r) else abs(min_a_l) + 2*abs(min_b_r)])
    print(score)

  pass

if __name__=='__main__':
  main()

Fixed submission:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from bisect import bisect_left

def main():
  N_a, N_b, N_q = map(int, input().strip().split(' '))
  As = list(map(int, [input().strip() for _ in range(N_a)]))
  Bs = list(map(int, [input().strip() for _ in range(N_b)]))
  Qs = list(map(int, [input().strip() for _ in range(N_q)]))

  for q in Qs:
    min_a_l = -(2*(10**10)+1)
    min_b_l = -(2*(10**10)+1)
    min_a_r = 2*(10**10)+1
    min_b_r = 2*(10**10)+1
    a_index = bisect_left(As, q)
    if len(As) > a_index-1 >= 0:
      min_a_l = As[a_index-1] - q
    if a_index < len(As):
      min_a_r = As[a_index] - q

    b_index = bisect_left(Bs, q)
    if len(Bs) > b_index-1 >= 0:
      min_b_l = Bs[b_index-1] - q
    if b_index < len(Bs):
      min_b_r = Bs[b_index] - q

    score = min([
      min_a_r if min_a_r > min_b_r else min_b_r,
      abs(min_a_l) if min_a_l < min_b_l else abs(min_b_l),
      2*min_a_r + abs(min_b_l) if min_a_r < abs(min_b_l) else min_a_r + 2*abs(min_b_l),
      2*abs(min_a_l) + abs(min_b_r) if abs(min_a_l) < abs(min_b_r) else abs(min_a_l) + 2*abs(min_b_r)])
    print(score)

  pass

if __name__=='__main__':
  main()