Problem p02641 (python)

Fixed submission:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False
  
if(n==1):
  if(x==p[0]):
    ans = x-1
    judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(l_list == []):
      ans = max(s_list)
    if(s_list == []):
      ans = min(l_list)
    else:
      if(abs(x-min(l_list)) > abs(x-max(s_list))):
        ans = max(s_list)
      elif(abs(x-min(l_list))==abs(x-max(s_list))):
        ans=max(s_list)
      else:
        ans=min(l_list)  

print(ans)

Buggy submission (verdict: Runtime Error):
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(l_list == [] and s_list == []):
      ans = x-1
    else:
      if(abs(x-min(l_list)) > abs(x-max(s_list))):
        ans = max(s_list)
      elif(abs(x-min(l_list))==abs(x-max(s_list))):
        ans=max(s_list)
      else:
        ans=min(l_list)  

print(ans)

Buggy submission (verdict: Runtime Error):
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(l_list == []):
      ans = max(s_list)
    if(s_list == []):
      ans = min(l_list)
    else:
      if(abs(x-min(l_list)) > abs(x-max(s_list))):
        ans = max(s_list)
      elif(abs(x-min(l_list))==abs(x-max(s_list))):
        ans=max(s_list)
      else:
        ans=min(l_list)  

print(ans)

Buggy submission (verdict: Runtime Error):
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(l_list != []):
      if(abs(x-min(l_list)) > abs(x-max(s_list))):
        ans = max(s_list)
      elif(abs(x-min(l_list))==abs(x-max(s_list))):
        ans=max(s_list)
      else:
        ans=min(l_list)  

print(ans)

Buggy submission (verdict: Runtime Error):
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True
  if(n!=1):
    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(abs(x-min(l_list)) > abs(x-max(s_list))):
      ans = max(s_list)
    elif(abs(x-min(l_list))==abs(x-max(s_list))):
      ans=max(s_list)
    else:
      ans=min(l_list)  

print(ans)

Buggy submission (verdict: Runtime Error):
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True
  for i in range(n):
    for j in range(n):
      if(x+i==p[j]):
        check=False
    if(check):
      l_list.append(x+i)
    check=True
  if(abs(x-min(l_list)) > abs(x-max(s_list))):
    ans = max(s_list)
  elif(abs(x-min(l_list))==abs(x-max(s_list))):
    ans=max(s_list)
  else:
    ans=min(l_list)

print(ans)

Buggy submission (verdict: Runtime Error):
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

  for i in range(n):
    for j in range(n):
      if(x+i==p[j]):
        check=False
    if(check):
      l_list.append(x+i)
    check=True
  if(abs(x-min(l_list)) > abs(x-max(s_list))):
    ans = max(s_list)
  elif(abs(x-min(l_list))==abs(x-max(s_list))):
    ans=max(s_list)
  else:
    ans=min(l_list)
  
print(ans)