Problem: Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.  Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Submission attempts (in order):
import sys

def Forbidden_List(x,n,p):
  k = [abs(s - x) for s in p]
  for i in range(n):
    if i not in k: 
      return 10 - i
  return 10 - n

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

import sys

def Forbidden_List(x,n,p):
  k = [abs(s - x) for s in p]
  for i in range(n):
    if i not in k: 
      return 10 - i
  return 10 - n

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
     	inp2 = input().rstrip().split()
       	p = list(map(int,inp2))

        print(Forbidden_List(x,n,p))

import sys

def Forbidden_List(x,n,p):
  #k = [abs(s - x) for s in p]
  #print(k)
  print(x)
  for i in range(n):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

import sys

def Forbidden_List(x,n,p):
  k = [abs(s - x) for s in p]
  for i in range(n):
    if i not in k: 
      return 10 - i
  return 10 - n

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    inp2 = input().rstrip().split()
    
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else:
        p = list(map(int,inp2))

        print(Forbidden_List(x,n,p))

import sys

def Forbidden_List(x,n,p):
  #k = [abs(s - x) for s in p]
  #print(k)
  print(x)
  for i in range(n//2 + n%2):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i
  return x - n//2 - n%2

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

import sys

def Forbidden_List(x,n,p):
  #k = [abs(s - x) for s in p]
  #print(k)
  print(x)
  for i in range(n//2 + n%2):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i
  return x - n

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

import sys

def Forbidden_List(x,n,p):
  print(x)
  for i in range(n//2 + n%2):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i
  return x - n//2 + n%2

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

 import sys
  
def Forbidden_List(x,n,p):
  k = [abs(s - x) for s in p]
  for i in range(n):
    if i not in k: 
      return 10 - i
  return 10 - n
 
if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    inp2 = input().rstrip().split()
    
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else:
        p = list(map(int,inp2))
 
        print(Forbidden_List(x,n,p))

import sys

def Forbidden_List(x,n,p):
  k = [abs(s - x) for s in p]
  print(k)
  for i in range(n):
    if i not in k: 
      return x - i
  return x - n

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

import sys

def Forbidden_List(x,n,p):
  for i in range(n//2 + n%2 + 1):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Accepted