Problem:


Score : 300 points

Problem Statement

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.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Wrong Answer

Solution code:

import itertools
from collections import deque,Counter
import bisect
import heapq

def IN(): return int(input())
def sIN(): return input()
def MAP(): return map(int,input().split())
def LMAP(): return list(map(int,input().split()))
def TATE(n): return [input() for i in range(n)]
MOD = 10**9 + 7

x,n = MAP()
p = LMAP()
if  n == 0:
  print(x)
  exit()
for i in range(1,200):
  a = x-i
  b = x+i
  if a not in p and b not in p and a >= 1 and b<=100:
    print(a)
    exit()
  if a not in p and b  in p and a >= 1:
    print(x-i)
    exit()
  if b not in p and a in p and b<=100:
    print(x+i)
    exit()

Submission status: Wrong Answer

Solution code:
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

x,n = readInts()
p = input()
if n==0:
	print(x)
	exit()
p = list(map(int, p.split()))

for i in range(1,101):
	l = max(1,x-i)
	r = x+i
	if l not in p:
		print(x-i)
		exit()
	if r not in p:
		print(x+i)
		exit()

Submission status: Wrong Answer

Solution code:
# print('input >>')
X, N = map(int,(input().split()))
ps = list(map(int,(input().split())))

all_num = [i for i in range(1, 101)]

for p in ps: # 10000
    all_num.remove(p)

diff = 1000
ans = 1000
anss = []

for num in all_num:
    my_diff = abs(num - X)
    if my_diff < diff:
        ans = num
        diff = my_diff

# print('-----output-----')
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if x in p:
    ans = None
    for i in range(1, max(x, 100 - x)):
        for j in [-1, 1]:
            y = x + i * j
            if y > 101 or y < 0:
                continue
            if y not in p:
                ans = y
                break
        if ans is not None:
            break
    print(ans)

else:
    print(x)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

x,n=mii()
arr0=limii()

if len(arr0)==0:
    print(x)
    exit()

arr=[]
for i in range(0,101):
    if i not in arr0:
        arr.append(i)
arr.sort()
ans=[10**100,10*100]

for i in reversed(arr):
    if abs(i-x)<ans[1]:
        
        if i<ans[0]:
            ans[0]=min(ans[0],i)
            ans[1]=abs(i-x)
    elif abs(i-x)==ans[1]:
        ans[0]=min(ans[0],i)
print(ans[0])

Submission status: Wrong Answer

Solution code:
X,N=map(int, input().split())
p=list(map(int, input().split()))

if len(p)==0:
    print(X)
    exit()

for i in range(N):
    if p.count(X-i)==0:
        print(X-i)
        exit()
    if p.count(X+i)==0:
        print(X+i)
        exit()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = set(map(int, input().split()))

for i in range(N//2+1):
    if X-i not in p:
        print(X-i)
        break
    elif X+i not in p:
        print(X+i)
        break

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = [int(i) for i in input().split()]

check = [0 for i in range(100)]
for i in range(N):
    check[P[i]-1] = 1
    
dx_ls = [1000 for i in range(100)]
ans = []
for i in range(100):
    if check[i] == 0:
        dx_ls[i] = abs(X-(i+1))
            
dx_min = min(dx_ls)
for i in range(100):
    if dx_ls[i] == dx_min:
        ans.append(i+1)
        
print(min(ans))

Submission status: Wrong Answer

Solution code:
x, n = map( int, input().split() )
p = list( map( int, input().split() ) )

if len( p ) == 0:
    print( x )
    exit()

for i in range( n ):
    if ( x - i ) not in p:
        print( x - i )
        break
    elif ( x + i ) not in p:
        print( x + i )
        break

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())

if n == 0:
    print(x)
else:
    p = list(map(int,input().split()))

    p.sort()
    trgt = x
    roop_flg = True
    while roop_flg:
        if trgt not in p:
            break
        else:
            trgt = trgt -1
            if trgt not in p:
                break
            trgt = trgt + 2

    print(trgt)

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
if n==0:
    print(x)
    sys.exit()
else:
    p=list(map(int,input().split()))
    res=1000
    ans=0
    for i in range(1,101):
        p.append(i)
        if len(p)==len(set(p)):
            if res>abs(x-i):
                res=abs(x-i)
                ans=i
        del p[-1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
x,n  = map(int,input().split())
if n==0:
    print(x)
    exit()
p = [int(i) for i in input().split()]

max_ = max(p)

a= [i+1 for i in range(max_)]
for i in p:
    a[i-1]=100000
min_=100000
m=0
for i in a:
    b = abs(i-x)
    if min_ > b:
        min_=b
        m = i
print(m)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N != 0:
    P = [int(i) for i in input().split()]
else:
    P = []
m = float("inf")
ans = 0
l = set(range(-100, 101)) - set(P)
for p in sorted(l):
    d = abs(p-X)

    if d < m:
        m = d
        ans = p

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

X,N = map(int, input().split())
if N == 0:
    print(X)
    exit()

A = list(map(int, input().split()))
Min = 101

cnt = -100
for i in range(1,202):
    if cnt in A:
        cnt += 1
        continue
    if abs(cnt-X) < Min:
        ans = cnt
        Min = abs(cnt-X)
    cnt += 1
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
# x, y, z = map(int, input().split())
arr = list(map(int, input().split()))
# sm = sum(arr)
# m = max(arr)
# s = input()
b = 1000
p = -1
if n == 0:
	print(x)
else:
	for i in range(1, 102):
		if abs(x-i) < b and i not in arr:
			p = i
			b = abs(x-i)
	print(p)

Submission status: Wrong Answer

Solution code:
import sys
X,N = map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
p = list(map(int,input().split()))

num1 = X-1
num2 = X+1
while 1:
  if num1 == 0:
    print(num1)
    break
  if num1 in p and num2 not in p:
    print(num2)
    break
    
  elif num1 not in p and num2 in p:
    print(num1)
    break
  elif num1 not in p and num2 not in p:
    print(num1)
    break
  else:
    num1 -= 1
    num2 += 1

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
ab = min(abs(101 - x),abs(x))
if abs(101 - x) >= abs(x):
    answer = 0
else:
    answer = 101
for i in range(1,101):
    if i in p:
        continue
    else:
        if ab > abs(x - i):
            ab = abs(x - i)
            answer = i
print(answer)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
if N==0:print(X); exit()
diff = float('inf')
ans = X
A = [0]*101
for p in P:
    A[p] += 1
for i in range(X,101):
    if A[i]==0:
        ans = i
        diff = i-X
        break
for i in range(X,-1,-1):
    if A[i]==0:
        if abs(X-i)<=diff:
            ans = i
        break
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    l = [int(i) for i in range(100, -1, -1)]
    for i in range(n):
        l.remove(p[i])
    ans = 101
    for i in range(len(l)):
        if ans >= abs(l[i]-x):
            ans = abs(l[i]-x)
        else:
            return l[i-1]
    



print(solve())

Submission status: Wrong Answer

Solution code:
x, n = map(int,input().split())
P = list(map(int,input().split()))
Q = []
ans = 100
for i in range(100):
    if i+1 in P:continue
    else:
        Q.append(i+1)
for j in Q:
    d = abs(j - x)
    ans = min(d, ans)

l = x -ans
m = x + ans
if l > 0 and l in Q:
    print(l)
else:
    print(m)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
m = float("inf")
for i in range(1, 101):
    if i not in p:
        if abs(i-x) < m:
            ans = i
            m = abs(i-x)

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())

if n == 0:
    print(x)
    exit()

else:
    p = list(map(int, input().split()))
    li = [i for i in range(-101, 101) if i not in p]
    li.sort(reverse = True)

    tmp1 = float('inf')
    ans = float('inf')

    for i in li:
        if abs(i - x) <= tmp1:
            if i < ans:
                ans = i
                tmp1 = abs(i - x)

    print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())

if n == 0:
    print(x)
else:
    l = list(map(int, input().split()))
    l.sort()
    small = x
    large = x
    while small in l and large in l:
        small -= 1
        large += 1
    if x - small > large - x:
        print(large)
    else:
        print(small)

Submission status: Wrong Answer

Solution code:
X,N=map(int, input().split())
if N==0:
  print(X)
  exit()
P=list(map(int, input().split()))  
ans=-1
for i in range(-1,101):
  if i not in P:
    if abs(X-i)<abs(X-ans):
      ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
x,n=[int(_) for _ in input().split()]
p=[int(_) for _ in input().split()]
p.sort()

pinv=[True for i in range(101)]

for i in p:
    pinv[i]=False

ab=1000
ans=-1
for i in range(101):
    if (i<0 or pinv[i]) and abs(x-i)<ab:
        ab=abs(x-i)
        ans=i

print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
A = list(map(int, input().split()))
total = [i for i in range(1, 101)]
for i in range(len(A)):
    total[A[i]-1] = 10000
dif = [0]*100
for i in range(100):
    dif[i] = abs(X-total[i])
min_index = dif.index(min(dif))
print(min_index+1)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


x, n = MI()
pl = list(MI())

nums = set(list(range(1, 102))) - set(pl)

dmin = 1000000
for p in nums:
    d = abs(x - p)
    if d < dmin:
        temp = []
        temp.append(p)
        dmin = d
    elif d == dmin:
        temp.append(p)

print(min(temp))

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p_li = set(map(int,input().split()))
p = set(range(101))
kouho = p - p_li
ans = 10000
sa_min = 1000000
for i in list(kouho):
    sa = abs(X-i)
    if sa_min > sa:
        ans = i
        sa_min = sa
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))

li = []
for i in range(-1, 101):
    if i not in P:
        li.append(i)

ans = -1
minimum_num = 200

for n in li:
    num = abs(n - X)
    if num < minimum_num:
        minimum_num = num
        ans = n

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
listP = list(map(int, input().split()))

listP.sort()

minD = 100
val = 1
bef = None
for p in listP:
    if bef == None:
        bef = p
    else:
        if p-1 == bef:
            pass
        else:
            if bef < x < p:
                val = p
            elif x <= bef:
                if abs(bef+1-x) < minD:
                    minD = abs(bef+1-x)
                    val = bef+1
            else:
                if abs(p-1-x) < minD:
                    minD = abs(p-1-x)
                    val = p-1
        bef = p
if bef == None or bef < x:
    val = x

print(val)

Submission status: Wrong Answer

Solution code:
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())


# for _ in range(ii()):
    
x,n=mi()
a=li()
y=[]
for i in range(x,0,-1):
    if i not in a:
        y.append(i)
        break
for i in range(x,102):
    if i not in a:
        y.append(i)
        break
if len(y)==1:
    print(y[0])
else:
    if abs(y[0]-x)<abs(y[1]-x):
        print(y[0])
    elif(abs(y[0]-x)==abs(y[1]-x)):
        print(min(y))
    else:
        print(y[1])

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())

exist = [False] * 101
p = list(map(int, input().split()))

for i in range(N):
    exist[p[i]] = True

for i in range(100):
    if X - i <= 0:
        print(X-i)

    if X + i > 100:
        print(X+i)

    if not exist[max(0, X-i)]:
        print(X-i)
        exit()

    if not exist[min(X+i, 100)]:
        print(X+i)
        exit()

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
elif n == 100:
    print(0)
    exit()
p = list(map(int,input().split()))
t = list(range(1,101))
u = set(t)-set(p)
u = list(u)
u.sort()
dif = 2**60
ans = 2**60
for a in u:
    tmp = abs(a-x)
    if dif > tmp:
        ans = a
        dif = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
X,Y = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
tmp = 10**9+7
P = set(list(range(0,101))) - set(P)
P = list(P)
P.sort(reverse=True)


ans = 0
for i in P:
    if abs(i-X) <= tmp:
        ans = i
        tmp = abs(i-X)
        
print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
List=list(map(int,input().split()))
num=list(range(1,101))
min_num=0
for i in range(len(List)):
    if num.count(List[i])>=1:
        num.remove(List[i])
for i in range(len(num)):
    if (abs(num[i]-x)<abs(min_num-x)) or (abs(num[i]-x)==abs(min_num-x) and num[i]<min_num):
        min_num=num[i]
print(min_num)

Submission status: Wrong Answer

Solution code:

def main():
  x, n = list(map(int, input().split()))
  if n == 0:
    print(x)
  pp = list(map(int, input().split()))
  
  i = 0
  while True:
    if x-i not in pp:
      print(x-i)
      exit()
    if x+i not in pp:
      print(x+i)
      exit()
    i += 1
  
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import sys
X, N = map(int, input().split())
p = list(map(int, input().split()))
P = set(p)
a = 1000
c = -101
if N == 0:
    print(X)
    sys.exit()
for i in range(-1, 102):
    if i == X:
        continue
    if i in P:
        continue
    if abs(i - X) == a:
        c = min(c, i)
    elif abs(i - X) < a:
        c = i
        a = abs(i - X)
print(c)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if x in p:
    ans = None
    for i in range(1, max(x, 100 - x)):
        for j in [-1, 1]:
            y = x + i * j
            if y > 100 or y < 1:
                continue
            if x + i * j not in p:
                ans = x + i * j
                break
        if ans is not None:
            break
    print(ans)

else:
    print(x)

Submission status: Wrong Answer

Solution code:
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
X,N = LI()
p = set(LI())
ans,distance = 0,float('INF')
for x in range(101)[::-1]:
    if x in p:
        continue
    now_distance = abs(X-x)
    if now_distance<=distance:
        ans = x
        distance = now_distance
print(ans)

Submission status: Wrong Answer

Solution code:
targ, length = map(int, input().split(' '))

banned = [False] * 100

bans = input()
if bans != '':
    for ban in bans.split(' '):
        banned[int(ban) - 1] = True

for dist in range(100):
    if targ - dist > 0 and not banned[targ - dist - 1]:
        print(targ - dist)
        exit()
    elif targ + dist <= 100 and not banned[targ + dist - 1]:
        print(targ + dist)
        exit()

Submission status: Wrong Answer

Solution code:
x, n = map(int,input().split())
if n != 0:
  a = list(map(int,input().split()))
b = [i for i in range(-100,101)]
c = [1000]

for i in range(n):
    b.remove(a[i])

for i in range(len(b)):
  if abs(b[i] - x) < abs(c[0] - x):
      c = [b[i]]
  elif abs(b[i] - x) == abs(c[0] - x):
      c.append(b[i])
  else:
      pass

print(min(c))

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
lst = list(map(int, input().split()))
num = []
for i in range(1, 101):
  num.append(-i)
for i in range(101):
  if not i in lst:
    num.append(i)

dis = 10000
ans = num[0]
for p in num:
  if abs(p-x) < dis:
    dis = abs(p-x)
    ans = p
  elif abs(p-x) == dis and p < ans:
    ans = p
    
print(ans)

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())

Z = Y - 2 * X

b = Z / 2
a = X - b

if (a >= 0 and b >= 0 and a % 1 == 0 and b % 1 == 0):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(100)
    exit()

p = list(map(int , input().split()))
ps = set(p)
o = [-1]
for i in range(100+1):
    if i in ps:
        continue
    o.append(i)

m = 1000
ans = -1
for oi in reversed(o):
    if abs(x - oi) <= m:
        ans = oi
        m = abs(x - oi)

print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = [int(i) for i in input().split()]
ans = -1
for i in range(1,100):
    if i in P:
        pass
    else:
        if abs(X-ans) > abs(X-i):
            ans = i
print(ans) if N != 0 else print(X)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
t=101
for i in range(1,101):
    if i not in P:
        if abs(X-t)>abs(X-i):
            t=i
print(t)

Submission status: Wrong Answer

Solution code:
x,n=[int(i) for i in input().split()]
p=[int(i) for i in input().split()]
np=[i for i in range(0,101) if not i in p]
r=0
for i in np:
    if abs(x-i)<abs(x-r):
        r=i
print(r)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
ans=100
for i in range(101):
    if p.count(i)==0:
        if abs(ans-x)>abs(i-x):
            ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
'''
Author : Shubhanshu Jain;
'''

import math
import random;
from collections import defaultdict 
mod =1000000007
r1 = lambda : int(input());
rm = lambda : map(int,input().split());
rms = lambda : map(str,input().split());
rls = lambda : list(rm())

def solve():
    x,n = rm();
    ls = rls();
    ar = [0]*101;
    for i in ls:
        ar[i]= 1;
    f = x;end = x;
    # ar[x]=1
    while(f>=1 or end<=100):
        if(f>=1 and ar[f]==0):
            print(f);
            break;
        if(end<=100 and ar[end]==0):
            print(end);
            break;
        f-=1;
        end+=1;
            
        





def def_value(): 
	return "nan"
	
solve();

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
q = set(range(1, 100))
r = q - set(p)
max = 1000
ans = X

if N == 0:
    print(X)
else:
    for i in r:
        if abs(X - i) < max:
            max = abs(X - i)
            ans = i

    print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
l = []
if len(l) == 0:
    if X != N:
        print(X)
    else:
        print(X-1)
    exit()
for i in range(-100, max(p)):
    if not i in p:
        l.append(i)
print(l)

ans_n = 100
ans = 0
for i in range(len(l)):
    if ans_n > abs(X-l[i]):
        ans_n = abs(X-l[i])
        ans = l[i]

print(ans)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
if b==0:
  print(a)
  exit()
s=list(map(int,input().split()))

lst=[i for i in range(1,101)]

for j in range(b):
  lst.remove(s[j])

n=100
for k in lst:
  m=abs(a-k)
  n=min(n,m)

if (a-n) in lst:
  print(a-n)
  exit()
else:
  print(a+n)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
l=list(map(int,input().split()))
l=set(l)
k=0
a=x
b=x
while True:
  if a+k not in l:
    print(a+k)
    exit()
  if a-k not in l:
    print(a-k)
    exit()
  k+=1

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
import random
from decimal import Decimal


X, N = [int(x) for x in stdin.readline().rstrip().split()]
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

ans = 10**9
ans1 = 0
for i in range(-100, 100):
    if i not in p:
        if i < 0:
            if ans > abs(X-i):
                ans = X-i
                ans1 = i
                # print(i)
        else:
            if ans > abs(X-i):
                ans = X-i
                ans1 = i
                # print(i)
print(ans1)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
ps = list(map(int, input().split()))
anss = [101] * 101
for i in range(1, 101):
  if (i not in ps):
    anss[i] = abs(x - i)
m = min(anss)
for i, ans in enumerate(anss):
  if ans == m:
    print(i)
    exit()

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

x,n = na()
p = na()
q = [i for i in range(-1,101) if i not in p]
r = []

for i in range(len(q)):
    r.append(abs(q[i]-x))

if n == 0:
    print(x)
    exit()

k = min(r)
if x-k in q:
    print(x-k)
else:
    print(x+k)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
P = set(list(map(int, input().split())))
ans = 0
diff = x
for a in range(101):
    if a not in P:
        tmp = abs(a-x)
        if diff > tmp:
            diff = tmp
            ans = a
print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
a=[int(i) for i in input().split()]
ans=float("inf")
anss=0
for i in range(-100,101):
    if i not in a:
        if abs(x-i)<ans:
            ans=abs(x-i)
            anss=i
print(anss)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  lst=sorted(map(int,input().split()))
  dis=200
  ans=100
  for i in range(101):
    temp=abs(x-i)
    if temp<dis and i not in lst:
      dis=temp
      ans=i
  print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
if P == []:
  print(X)
  exit()
for n in range(1,101):
  if X - n not in P:
    ans = X - n
    break
  if X + n not in P:
    ans = X + n
    break

print(ans)

Submission status: Wrong Answer

Solution code:
X, N = list(map(int, input().split()))
if N==0:
    print(X)
else:
    ps = list(map(int, input().split()))
    sub_abs = 0
    while True:
        if (X-sub_abs) not in ps:
            print(X-sub_abs)
            break
        if (X+sub_abs) not in ps:
            print(X+sub_abs)
        sub_abs += 1

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N>1:
    p_set = set(map(int,input().split()))
else:
    p_set = set()

min_dist_xp = 1000
for p in reversed(range(0,102)):
    if p not in p_set:
        dist_xp = abs(X-p)
        if dist_xp<=min_dist_xp:
            min_dist_xp = dist_xp
            ans = p

print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))

res = 10**15
for i in range(1,120):
  if i in P: continue
  if abs(i-X) < abs(res-X):
    res = i
print(res)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
import sys
if N != 0:
    p = list(map(int,input().split()))
else:
    print(X)
    sys.exit()
    
for i in range(1,101):  
    tmp_r = 10**9+7
    tmp_l = 10**9+7
    r_flag = 0
    l_flag = 0
    
    if X+i not in p:
        tmp_r = X+i
        r_flag = 1
    if X-i not in p:
        tmp_l = X-i
        l_flag = 1
        
    if r_flag == 1 or l_flag == 1:
        print(min(tmp_r,tmp_l))
        sys.exit()

Submission status: Wrong Answer

Solution code:
x,n,*a=map(int,open(0).read().split())
b=[1]*101
for i in a:
    b[i]=0
c=1000 
ans=0
for i in range(101):
    if b[i] and c>=abs(x-i):
        c=abs(x-i)
        ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n==0:
    print(x)
else:
    p = list(map(int,input().split()))
    p.sort()
    if not(x in p):
        print(p)
    else:
        i=1
        while True:
            if not(x-i in p):
                print(x-i)
                break
            elif not(x+i in p):
                print(x+i)
                break
            i= i+1

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
else:
  print(x)
  exit()
if x not in p:
  print(x)
for i in range(1,100000000000):
  p_=x-i
  q=x+i
  if p_ not in p:
    print(p_)
    exit()
  if q not in p:
    print(q)
    exit()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())

if n == 0:
    print(x)
    exit()
P = list(map(int, input().split()))

for s in range(-101, 101):
    if s not in P:
        ans = s
        break

for s in range(-101, 101):
    if s not in P:
        if abs(ans-x) > abs(s-x):
            ans = s
        elif abs(ans-x) == abs(s-x):
            ans = min(ans, s)

print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
ans=0
ans1=100
for i in range(1,101):
    if i in p:
        a=p.pop(0)
        continue
    A=abs(X-i)
    if ans1>A:
        ans1=A
        ans=i
    elif ans1==A:
        ans=min(ans,i)
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

X, N = map(int, input().split())
P = list(map(int, input().split()))

not_inc = []

for i in range(-100, 100):
  if i not in P:
    not_inc.append(i)

not_inc_gap = [abs(not_inc[i] - X) for i in range(len(not_inc))]

index = np.argmin(not_inc_gap)

if N == 0:
  print(X)
else:
  print(not_inc[index])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))

tmp = x
x_2 = x

if n == 0:
    print(x)
    exit()

if x not in p:
    print(x)
    exit()

else:
    x -= 1
    if (x_2 + 1) not in p:
        print(x+1)
        exit()

    else:
        x_2 += 1

while True:
    if(x - 1) not in p:
        print(x-1)
        exit()

    else:
        x -= 1
        if (x_2 + 1) not in p:
            print(x_2+1)
            exit()

        else:
            x_2 += 1

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())

p = list(map(int, input().split()))

c = float('inf')
ans = 0
for i in range(-10, 101):
    if i not in p:
        if c > abs(x - i):
            c = abs(x - i)
            ans = i

print(ans)