Problem p03112 (python)

Fixed submission:
import bisect
A,B,Q = map(int, input().split())
SList=[]
TList=[]
for i in range(A):
  SList.append(int(input()))
for i in range(B):
  TList.append(int(input()))


  
for i in range(Q):
  x=int(input())
  kouho=[]
  insert_indexS=bisect.bisect_left(SList,x)
  if not insert_indexS==0:
    kyoriS0 = x-SList[insert_indexS-1]
    insert_indexT=bisect.bisect_left(TList,SList[insert_indexS-1])
    if not insert_indexT==0:
      kyoriS00 = kyoriS0+SList[insert_indexS-1]-TList[insert_indexT-1]
      kouho.append(kyoriS00)
    if not insert_indexT==len(TList):
      kyoriS01 = kyoriS0+TList[insert_indexT]-SList[insert_indexS-1]
      kouho.append(kyoriS01)
  if not insert_indexS == len(SList):
    kyoriS1=SList[insert_indexS]-x
    insert_indexT=bisect.bisect_left(TList,SList[insert_indexS])
    if not insert_indexT==0:
      kyoriS10 = kyoriS1+SList[insert_indexS]-TList[insert_indexT-1]
      kouho.append(kyoriS10)
    if not insert_indexT==len(TList):
      kyoriS11 = kyoriS1+TList[insert_indexT]-SList[insert_indexS]
      kouho.append(kyoriS11)

  insert_indexT=bisect.bisect_left(TList,x)
  if not insert_indexT==0:
    kyoriT0 = x-TList[insert_indexT-1]
    insert_indexS=bisect.bisect_left(SList,TList[insert_indexT-1])
    if not insert_indexS==0:
      kyoriT00 = kyoriT0+TList[insert_indexT-1]-SList[insert_indexS-1]
      kouho.append(kyoriT00)
    if not insert_indexS==len(SList):
      kyoriT01 = kyoriT0+SList[insert_indexS]-TList[insert_indexT-1]
      kouho.append(kyoriT01)
  if not insert_indexT == len(TList):
    kyoriT1=TList[insert_indexT]-x
    insert_indexS=bisect.bisect_left(SList,TList[insert_indexT])
    if not insert_indexS==0:
      kyoriT10 = kyoriT1+TList[insert_indexT]-SList[insert_indexS-1]
      kouho.append(kyoriT10)
    if not insert_indexS==len(SList):
      kyoriT11 = kyoriT1+SList[insert_indexS]-TList[insert_indexT]
      kouho.append(kyoriT11)
  print(min(kouho))

Buggy submission (verdict: Runtime Error):
import bisect
A,B,Q = map(int, input().split())
SList=[]
TList=[]
for i in range(A):
  SList.append(int(input()))
for i in range(B):
  TList.append(int(input()))


  
for i in range(Q):
  x=int(input())
  kouho=[]
  insert_indexS=bisect.bisect_left(SList,x)
  if not insert_indexS==0:
    kyoriS0 = x-SList[insert_indexS-1]
    insert_indexT=bisect.bisect_left(TList,SList[insert_indexS-1])
    if not insert_indexT==0:
      kyoriS00 = kyoriS0+SList[insert_indexS-1]-TList[insert_indexT-1]
      kouho.append(kyoriS00)
    if not insert_indexT==len(TList):
      kyoriS01 = kyoriS0+TList[insert_indexT]-SList[insert_indexS-1]
      kouho.append(kyoriS01)
  if not insert_indexS == len(SList):
    kyoriS1=SList[insert_indexS]-x
    insert_indexT=bisect.bisect_left(TList,SList[insert_indexS])
    if not insert_indexT==0:
      kyoriS10 = kyoriS1+SList[insert_indexS]-TList[insert_indexT-1]
      kouho.append(kyoriS10)
    if not insert_indexT==len(TList):
      kyoriS11 = kyoriS1+TList[insert_indexT]-SList[insert_indexS]
      kouho.append(kyoriS11)

  insert_indexT=bisect.bisect_left(TList,x)
  if not insert_indexT==0:
    kyoriT0 = x-TList[insert_indexT-1]
    insert_indexS=bisect.bisect_left(SList,TList[insert_indexT-1])
    if not insert_indexS==0:
      kyoriT00 = kyoriT0+TList[insert_indexT-1]-SList[insert_indexS-1]
      kouho.append(kyoriT00)
    if not insert_indexT==len(TList):
      kyoriT01 = kyoriT0+SList[insert_indexS]-TList[insert_indexT-1]
      kouho.append(kyoriT01)
  if not insert_indexT == len(TList):
    kyoriT1=TList[insert_indexT]-x
    insert_indexS=bisect.bisect_left(SList,TList[insert_indexT])
    if not insert_indexS==0:
      kyoriT10 = kyoriT1+TList[insert_indexT]-SList[insert_indexS-1]
      kouho.append(kyoriT10)
    if not insert_indexS==len(SList):
      kyoriT11 = kyoriT1+SList[insert_indexS]-TList[insert_indexT]
      kouho.append(kyoriT11)
  print(min(kouho))