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: Accepted

Solution code:
import numpy as np
import itertools

x,n = map(int,input().split())
li = list(map(int,input().split()))
li.sort()
if x in li:
    idx = li.index(x)
    i = 0
    while(1):
        i = i+1
        if(idx-i<0):
            print(x-i)
            break
        if(li[idx-i]!=x-i):
            print(x-i)
            break
        if(idx+i>=len(li)):
            print(x+i)
            break
        if(li[idx+i]!=x+i):
            print(x+i)
            break
else:
    print(x)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
a_list=list(map(int,input().split()))
if N==0:
    print(X)
else:
    if X in a_list:
        for i in range(N//2+2):
            #print(i)
            if X-i in a_list:
                
                if X+i in a_list:
                    a=1
                else:
                    print(X+i)
                    break
            else:
                print(X-i)    
                break        
    else:
        print(X)

Submission status: Accepted

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

if N == 0:
    print(X)
    exit()

if X not in p:
    print(X)    
else:
    i = 1
    while p[p.index(X)] + i in p:
        i += 1
    up = p[p.index(X)] + i
    
    i = 1
    while p[p.index(X)] - i in p:
        i += 1
    down = p[p.index(X)] - i

    if abs(down-X) <= abs(up-X):
        print(down)
    else:
        print(up)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n!=0:
    p=list(map(int,input().split()))
    k=[i for i in range(0,102)]
    kset=set(k)
    pset=set(p)
    ansbook=kset-pset
    ansbook=list(ansbook)
    ansbook=ansbook[::-1]
    ans1=100000
    ans=0
    for i in ansbook:
        if abs(i-x)<=ans1:
            ans1=abs(i-x)
            ans=i
    print(ans)
else:
    print(x)

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl
x,n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    i = 0
    p.sort()
    a = bl(p, x)
    if a == n:
        print(x)
    elif p[a] != x:
        print(x)
    else:
        while(True):
            i += 1
            if p[bl(p, x-i)] != x-i:
                print(x-i)
                break
            else:
                a = bl(p, x+i)
                if a == n:
                    print(x+i)
                    break
                elif p[a] != x+i:
                    print(x+i)
                    break

Submission status: Accepted

Solution code:
X,N =map(int,input().split())
pb = list(map(int,input().split()))
p =[]
for i in range(0,102):
    p.append(i)
An = []
ab =[]
Answer =[]
for i in range(1,N+1):
    p.remove(pb[i-1])
for j in range(len(p)):
    An.append(p[j])
    ab.append(abs(p[j]-X))
abmi = ab[0]
for i in range(len(p)):
    if abmi > ab[i]:
        Answer = []
        Answer.append(An[i])
        abmi = ab[i]
    if abmi == ab[i]:
        Answer.append(An[i])
print(min(Answer))

Submission status: Accepted

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

best = 100000000
ret = x

if n:
	mn = min(ps)
	mx = max(ps)
	s = set(ps)
	for i in range(mn, mx+1):
		if i not in s:
			d = abs(x-i)
			if d < best:
				best = d
				ret = i
	if ret == x:
		up = abs(mx + 1 - x)
		down = abs(mn - 1 - x)
		ret = mn-1 if down <= up else mx+1
	if x not in s:
		ret = x

print(ret)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
a = list(map(int, input().split()))
o = [0] * 102
for i in a:
    o[i] = 1

ans = 1000
dis = 1000
for i in range(0, len(o)):
    if o[i] == 0:
        if dis > abs(x - i):
            ans = i
            dis = abs(x-i)

print(ans)

Submission status: Accepted

Solution code:
import sys
x,n = map(int, sys.stdin.readline().rstrip("\n").split())
p = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
num = [i for i in range(-200,200)]
for i in range(n):
    num.remove(p[i])
if not num:
    pass
elif x in num:
    print(x)
else:
    d = 1
    while True:
        if x-d in num:
            print(x-d)
            break
        elif x+d in num:
            print(x+d)
            break
        else:
            d += 1

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P =  set(map(int, input().split()))
Nums = set(range(-100, 200))
Nums = Nums - P
sorted(Nums)


minNum = 99999
minIndex = 0
for n in Nums:
    if minNum == abs(X-n):
        break
    if abs(X - n)< minNum:
        minNum = abs(X-n)
        minIndex = n

print(minIndex)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
ps=list(map(int,input().split()))
c=0
while True:
    if not x-c in ps:
        print(x-c)
        exit()
    elif not x+c in ps:
        print(x+c)
        exit()
    c+=1

Submission status: Accepted

Solution code:
from sys import stdin

x, n = [int(x) for x in stdin.readline().rstrip().split()]
if n > 0:
    P = [int(x) for x in stdin.readline().rstrip().split()]

    memos = [False] * 102

    for p in P:
        memos[p] = True

    tgt = x
    offset = 1
    look_down = True
    while True:

        if memos[tgt] == False:
            break
        if look_down:
            look_down = False
            tgt = x-offset
        else:
            look_down = True
            tgt = tgt + offset + offset
            offset += 1

    print(tgt)
else:
    print(x)

Submission status: Accepted

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

int_set = set(list(range(-1,102)))

for x in input().split():
    int_set.remove(int(x))

for i in range(200):
    if X - i in int_set:
        print(X - i)
        break
    elif X + i in int_set:
        print(X + i)
        break

Submission status: Accepted

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

def search(x, li):
  for i in range(int(len(li)/2)+2):
    if x-i not in li:
      print(x-i)
      return
    if x+i not in li:
      print(x+i)
      return
  return

search(x, p)

Submission status: Accepted

Solution code:
target,n = map(int,input().split())
if n == 0:
  	print(target)
else:
    ary = list(map(int,input().split()))
    count = 0
    while True:
        if target - count not in ary:
            print(target - count)
            break
        elif target + count not in ary:
            print(target + count)
            break
        else:
            count += 1

Submission status: Accepted

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

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

l = list(map(int,input().split()))
#print(X,n)
#print(l)



l = sorted(l)
#print(l)
l_min = min(l)
l_max = max(l)

x = [i for i in range(l_min, l_max+1)]

x = [l_min-1] + x + [l_max+1]
#print(x)

y = []
for j in x:
    if j not in l:
        y.append(j)
#print(y)

ans = 0
tmp = 1000
for k in y:
    if tmp > abs(k - X):
        tmp = abs(k - X)
        ans = k

print(ans)

Submission status: Accepted

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

ans = 200
abs_ans = 200
for i in range(102):
    if i in P:
        continue
    if abs(x-i) < abs_ans:
        ans = i
        abs_ans = abs(x-i)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
set_p = set(p)

if X not in set_p:
    print(X)
else:
    tmp = set(range(0, 102))
    notinp = np.array(list(tmp - set_p))
    t = np.abs(np.array(notinp) - X)
    argmin = t.argmin()
    print(notinp[notinp == notinp[argmin]].min())

Submission status: Accepted

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

i = 0
ans = None if p else x

while(ans is None):
    xu, xd = x+i, x-i
    if xu not in p:
        ans = xu
    if xd not in p:
        ans = xd
    i=i+1

print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N>0:
  p=list(map(int,input().split()))
  for d in range(0,101):
    if (X-d) not in p:
      print(X-d)
      break
    elif (X+d) not in p:
      print(X+d)
      break
else:print(X)

Submission status: Accepted

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

for i in range(100):
    if p.count(x+i) == 0:
        a = x+i
        break

for i in range(100):
    if p.count(x-i) == 0:
        b = x-i
        break

if abs(a-x) < abs(b-x):
    print(a)
else:
    print(b)

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
if N > 0:
  P = set([int(_) for _ in input().split()])
else:
  P = set()

l_cand = None
r_cand = None
i = 0
while (l_cand is None) and (r_cand is None):
  if X - i not in P and l_cand is None:
    l_cand = X - i
  if X + i not in P and r_cand is None:
    r_cand = X + i
  i += 1
  
if l_cand is not None:
  print(l_cand)
else:
  print(r_cand)

Submission status: Accepted

Solution code:
import numpy as np

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


possible=[]

for i in range(min(Pn)-1,max(Pn)+2) if N!=0 else [X]:
    if i not in Pn:
        possible.append(i)

idx = np.abs(np.asarray(possible) - X).argmin()

print(possible[idx])

Submission status: Accepted

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

allowed = []
for i in range(102):
    if i not in ps:
        allowed.append(i)

for j in range(len(allowed)-1):
    if x-allowed[j+1] == 0:
        print(x)
        exit()
    elif (x-allowed[j]) * (x-allowed[j+1]) > 0:
        continue
    else:
        if x-allowed[j] <= allowed[j+1] - x:
            print(allowed[j])
        else:
            print(allowed[j+1])

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = [int(_) for _ in input().split()]
    for i in range(100):
        if x-i not in p:
            print(x-i)
            break
        if x+i not in p:
            print(x+i)
            break

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
if n == 0:
    print(x)
    exit()
if x not in p:
    print(x)
    exit()
dif = 2**60
ans = 2**60
for u in range(201):
    if u in p:
        continue
    else:
        tmp = abs(x-u)
        if tmp < dif:
            dif = tmp
            ans = u
for a in range(1,201):
    if a+x == dif:
        ans = -a
        break
print(ans)

Submission status: Accepted

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

p = [int(x) for x in input().split()]
ans = 10**9

if x not in p:
    ans = x
else:
    for i in range(1, 101):
        minus = x-i
        plus = x+i
        if minus not in p:
            ans = minus
            break
        elif plus not in p:
            ans = plus
            break
print(ans)

Submission status: Accepted

Solution code:
import sys

x,n = map(int,input().split())
if n != 0:
    l = list(map(int,input().split()))
else:
    print(x)
    sys.exit()

if x not in l:
    print(x)
    sys.exit()

tmp = []
for i in range(x-60,x+60):
    tmp.append(i)

ans = []
for j in tmp:
    if j not in l:
        ans.append(j)

tmp1 = 100
for k in ans:
    tmp2 = abs(x-k)
    if tmp2 != 0:
        if tmp1 >= tmp2:
            tmp1 = tmp2

ans2 = []
for m in ans:
    a = abs(m-x)
    if a == tmp1:
        ans2.append(m)

print(min(ans2))

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  anss=x
else:
  p=list(map(int,input().split()))
  pp=list(set(list(range(-100,105)))-set(p))
  ans=1000
  anss=1000
  for j in range(len(pp)):
    if abs(pp[j]-x)<ans:
      ans=abs(pp[j]-x)
      anss=pp[j]
    elif abs(pp[j]-x)==ans and pp[j]<anss:
      ans=abs(pp[j]-x)
      anss=pp[j]
print(anss)

Submission status: Accepted

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

px=[]
for i in range(n):
    #abs_px.append(abs(p[i]-x))
    px.append(p[i]-x)
k=0
cnt=0
while cnt<n:
    px.append(k)
    if px.index(k) == n:
        print(x+k)
        break
    else:
        px.pop(n)
        cnt+=1
        if k>=0:
            k=-1*(k+1)
        else:
            k*=-1
        if cnt==n:
            print(x+k)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

X, N = map(int, input().split())
plist = list(map(int, input().split()))
diff = []
for i in range(0, 102):
    if i not in plist:
        diff.append(i)

diff.sort()
diff = [(item, abs(item - X)) for item in diff]

nearest = -1
min_v = 1000
for idx, item in diff:
    if item < min_v:
        min_v = item
        nearest = idx

print(nearest)

Submission status: Accepted

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

num_set = set(range(-201, 201))

ans_list = list(num_set - p)
min_diff = None
min_ans = None
for ans in reversed(ans_list):
    diff = abs(ans - X)
    if min_diff is None or diff <= min_diff:
        min_diff = diff
        min_ans = ans

print(min_ans)

Submission status: Accepted

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

if p.count(x)==0:
  print(x)
else:
  a = 1
  while True:
    x1,x2 = x-a,x+a
    if p.count(x1)==0:
      print(x1)
      break
    elif p.count(x2)==0:
      print(x2)
      break
    else:
      a += 1

Submission status: Accepted

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

ans_1=X
ans_2=X


for j in range(100):
    for i in range(N):
        if ans_1 in p:
            ans_1+=1
        else:
            break


for j in range(100):
    for i in range(N):
        if ans_2 in p:
            ans_2-=1
        else:
            break



if abs(ans_2-X)-abs(ans_1-X)>0:
    print(ans_1)
else:
    print(ans_2)

Submission status: Accepted

Solution code:
X,N=map(int, input().split())
a=list(map(int, input().split()))
d=0
u=0
i=1
if(N==0):
    print(X)
else:
    if X in a:
        while(d==0) and (u==0):
            if X-i in a:
                if X+i in a:
                    i +=1
                else:
                    u +=1
            else:
                d +=1
        if(d==1):
            print(X-i)
        elif(u==1):
            print(X+i)
    else:
        print(X)

Submission status: Accepted

Solution code:
X , N  =  map ( int , input().strip().split(" ") ) ;
s = input().strip() ;

if len(s) == 0 :
	set1 = set() ;
else :
	L   =  list ( map ( int , s.split(" ") ) ) ;
	set1 = set ( L ) ;

v1 = None ;
while v1 is None :
	for x in range ( 0 , 101 ) :
		if X + x in set1 : continue ;
		v1 = x; 
		break ;
v2 = None ;
while v2 is None :
	for x in range ( 0 , 101 ) :
		if X-x  in set1 : continue ;
		v2 = x; 
		break ;
if v1 < v2 :
	print ( X + v1 ) ;
else :
	print ( X - v2 ) ;

Submission status: Accepted

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

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

s=p.index(x)
for i in range(1,n+1):
  if p[s-i]!=x-i:
    print(x-i)
    exit()
  elif s+i>n-1:
    print(p[-1]+1)
    exit()
  elif s+i<=n-1:
    if p[s+i]!=x+i:
      print(x+i)
      exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N > 0:
    p = list(map(int, input().split()))
elif N == 0:
    print(X)
    exit()
else :
    p = [int(input())]
if N == 100:
    if X <= 50:
        print(0)
    else:
        print(101)
    exit()

for i in range(X+1):
    if not i in p:
        x = i

for i in range(X,101):
    if not i in p:
        y = i
        break
    elif i == 100:
        y = 101

if (X-x) == (y-X):
    print(x)
elif (X-x) > (y-X):
    print(y)
else:
    print(x)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
lis = []
if(n!=0):
    lis = list(map(int,input().split()))
ans = 0
msf = 1000
for i in range(101):
    tmp1 = x-i
    if tmp1 not in lis:
        print(x-i)
        exit()
    tmp2 = x+i
    if tmp2 not in lis:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
Ps=list(map(int,input().split()))
numlist=[]
for i in range(102):
    numlist.append(i)
for p in Ps:
    numlist.remove(p)
import bisect
a=bisect.bisect_left(numlist,x)
b=a-1
if abs(numlist[a]-x)>=abs(numlist[b]-x):
    print(numlist[b])
else:
    print(numlist[a])

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N ==0:
  print(X)
else:
  List = list(map(int, input().split()))
  res = X
  Flag =True
  for k in range(N):
    if List[k] == X:
      Flag = False
  if Flag:
    print(res)
  else:
    for i in range(1,103):
      med_p = X+i
      med_n = X-i
      Flag_p = False
      Flag_n = False
      for j in range(N):
        if List[j] == med_p:
          Flag_p = True
        elif List[j] == med_n:
          Flag_n = True
        else:
          pass
      if Flag_p and Flag_n:
        pass
      elif not Flag_p and Flag_n:
        res = med_p
        break
      elif Flag_p and not Flag_n:
        res = med_n
        break
      else:
        res = med_n
        break
    print(res)

Submission status: Accepted

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

def b():
    if(N==0):
        return X
    for n in range(0,N+1):
        a=X-n
        if(a not in P):
            return a
        a=X+n
        if(X+n not in P):
            return a
print(b())

Submission status: Accepted

Solution code:
import numpy as np

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

        l = []
        for i in range(-100,120):
            if i not in p:
                l.append(i)
        
        l2 = []
        if x not in p:
            print(x)
        else:
            for j in range(1,101):
                nump = x+j
                numm = x-j
                if numm in l:
                    l2.append(numm)
                if nump in l:
                    l2.append(nump)
                if len(l2)>0:
                    break
            print(l2[0])

        
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    ans = 1e18
    for i in range(102):
        if i not in p:
            ans = min(ans, abs(x-i))
    if x-ans not in p:
        print(x-ans)
    else:print(x+ans)
if n == 0:
    print(x)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
X, N = [int(s) for s in input().split()]
if N == 0:
    print(X)
    exit()
P = [int(s) for s in input().split()]
Y = list(range(-10, 120))
for a in sorted(map(lambda x: (abs(x - X), x), Y), key=lambda x: [x[0], x[1]]):
    if not a[1] in P:
        print(a[1])
        exit()

print(X)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
li = list(map(int,input().split()))
countUp = a
countDown = a
ans = 0
while True:
  if countDown not in li:
    ans = countDown
    break 
  countDown = countDown - 1
  if countUp not in li:
    ans = countUp
    break
  countUp = countUp + 1 

print(ans)

Submission status: Accepted

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

d=150
pa = 0
px =range(102)
py = list(set(px) - set(p))

for i in py:

    if d> abs(i-x):
        pa = i
        d = abs(i-x)
    elif d == abs(i-x):
        if i < pa:
            pa =i



print(pa)

Submission status: Accepted

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

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

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

large = 0
for i in range(101):
    if not x + i in p:
        large = x + i
        break

small = 0
for i in range(101):
    if not x - i in p:
        small = x - i
        break

if abs(x - large) == abs(x - small):
    print(small)
elif abs(x - large) < abs(x - small):
    print(large)
else:
    print(small)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p_list = sorted(list(map(int, input().split())), reverse = True)



if (not X in p_list) or (N == 0):
    ans = X
else:
    p_min, p_max = p_list[-1], p_list[0]
    if X < p_min:
        ans = p_min - 1
    else:
        m = min(abs(X - p_min), abs(X - p_max))
        for i in range(1, m + 2):
            if not X - i in p_list:
                ans = X - i
                break
            if not X + i in p_list:
                ans = X + i
                break

print(ans)

Submission status: Accepted

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

p = list(map(int,input().split()))
dev = []
mini = 0

for i in range(N):
    dev.append(abs(X-p[i]))

#print(dev)
for i in range(N):
    if mini == dev[i]:
        break
else:
    print(X)
    exit()

mini +=1
while True:
    check = 0
    temp = 0
    for i in range(N):
        if mini==dev[i]:
            if check == 1:
                mini +=1
                break
            else:
                check +=1
                temp = p[i]
    else:
        if X-temp < 0 or temp ==0:
            print(X-mini)
            exit()
        else:
            print(X+mini)
            exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 14 21:22:01 2020

@author: Kei
"""

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

p = []*N

if (N != 0):
    p = list(map(int,input().split()))

goal_p = X
goal_m = X
sw_p = 0
sw_m = 0

if (N ==0):
    print(X)
else:
    while(1):
        sw_p = 0
        sw_m = 0
        
        for i in range(0,N):
            if(goal_p == p[i]):
                sw_p =1
        
        for i in range(0,N):
            if(goal_m == p[i]):
                sw_m =1
        
        if(sw_m == 0):
            print(goal_m)
            break
        
        if(sw_p == 0):
            print(goal_p)
            break
        
        goal_p += 1
        goal_m -=1

Submission status: Accepted

Solution code:
import sys

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

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

tmp = x
for i in range(100):
  if not((x-i) in p):
    print(x-i)
    sys.exit()
  elif not((x+i) in p):
    print(x+i)
    sys.exit()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
b = [1]*201
for a in p:
    b[a]=0

wk = 999
idx = 0
for i in range(201):
    if wk > abs(x - b[i]*i):
        wk1 = abs(x - b[i]*i)
        idx = i
    wk = wk1

print(idx)

Submission status: Accepted

Solution code:
# = int(input())
X, N = map(int, input().split())
p = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
zero = [0]*101
minimum = 101

if N == 0:
    print(X)
    exit()

for i in range(N):
    zero[p[i]] = 1

for i in range(101):
    if zero[i] == 0:
        if abs(X-i) < minimum:
            minimum = abs(X-i)
            count = i

for i in range(101, 120):
    if abs(X-i) < minimum:
        minimum = abs(X-i)
        count = i

for i in range(10):
    if abs(X+i) < minimum:
        minimum = abs(X+i)
        count = -i

print(count)

Submission status: Accepted

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

for i in range(100):
  y1 = x+i
  y2 = x-i
  if y2 not in p:
    print (y2)
    exit()
  if y1 not in p:
    print (y1)
    exit()

Submission status: Accepted

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

def Main(X, N, P):
    if N == 0:
        return X
    anss = []
    for i in range(102):
        if i in P:
            continue
        else:
            ab = 1000
            for e in P:
                ab = min(ab, abs(i-e))
            anss.append((i, ab))
    anss.sort(key = lambda x: x[1])
    ans = []
    mi = anss[0][1]
    for el in anss:
        if el[1] == mi:
            ell = (abs(X-el[0]), el[0])
            ans.append(ell)
        else:
            break
    ans.sort()
    return ans[0][1]
            
        
                    
out = Main(X, N, P)
print(out)

Submission status: Accepted

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

ans = 300
for i in range(-200, 201):
    if i not in list:
        if abs(x-i) < abs(x-ans):
            ans = i

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

a = input()
a, b = a.split()
a = int(a)
if int(b) == 0:
  print(a)
  exit()
n = input()
n = [int(i) for i in n.split()]
li = list(range(-250, 250))
for i in n:
  li.remove(i)
mini = [np.inf, 0]
for i in li:
  if abs(i - a) == mini[0]:
    if i < mini[1]:
      mini = [abs(i - a), i]
  elif abs(i - a) < mini[0]:
    mini = [abs(i - a), i]
print(mini[1])

Submission status: Accepted

Solution code:
X,N = (int(x) for x in input().split())
if N==0:
    print(X)
else:
    P = [int(x) for x in input().split()]
    Target = X
    if Target not in P:
        print(Target)
    else:
        Count = 0 
        Flag  = True
        while Flag:
            Count += 1
            Target = [X-Count,X+Count]
            if Target[1] not in P:
                Flag = False
                Disp = Target[1]
            if Target[0] not in P:
                Flag = False
                Disp = Target[0]
        print(Disp)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
cnt = 0
for i in range(101):
    if (x - i) not in p:
        print(x - i)
        break
    elif (x + i) not in p:
        print(x + i)
        break

Submission status: Accepted

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

i=[0]*201
for n in range(201):
    i[n]=n-99

ans=list(set(i) ^ set(p))
ans.sort()
dif=100
count=0
for j in range(201-N):
    dif_now=abs(X-ans[j])
    if dif>dif_now:
        dif=dif_now
        count=ans[j]
print(count)

Submission status: Accepted

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

num = 0
while True:
    if X+num in p_n:
        pass
    else:
        print(X +num)
        break
    num += 1
    if X - num in p_n:
        pass
    else:
        print(X - num)
        break

Submission status: Accepted

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

ans = X

for i in range(0,101):
        if (X - i) not in P:
                ans = X - i
                break
        elif (X + i) not in P:
                ans = X + i
                break
print(ans)

Submission status: Accepted

Solution code:
x, n =map(int, input().split())
l = list(map(int, input().split()))
if n == 0:
    print(x) 
else:
    for i in range(n//2 + 2):
        if not(x - i in l):
            print(x-i)
            break
        elif not (x + i in l):
            print(x+i)
            break

Submission status: Accepted

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

if N!=0:
    p = list(map(int,input().split()))
else:
    p=[]

d = {n: 1 for n in p}

a = X
b = X
while True:
    if d.get(a) != 1:
        print(a)
        break
    elif d.get(b) != 1:
        print(b)
        break
    else:
        a -= 1
        b += 1

Submission status: Accepted

Solution code:
import numpy as np


def main(X, N, a):
    a.append(10000000000)
    a.append(-10000000000)
    a.sort()
    maxn = a[0]-1
    for i in range(len(a)-1):

        if a[i] >= X:
            if a[i+1]-a[i] > 1:
                if X-maxn>a[i]+1-X:
                    maxn = a[i]+1
                break
            if X-maxn < a[i]-X:
                break
        else:
            if a[i+1]-a[i] > 1:
                if a[i+1] > X and a[i] < X:
                    maxn = X
                    break
                maxn = a[i+1]-1

    return maxn


X, N = map(int, input().split())
try:
    a = list(map(int, input().split()))
except:
    a = []
print(main(X, N, a))

Submission status: Accepted

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

for i in range(101):
    sub = x - i
    if sub not in ps:
        print(sub)
        break

    add = x + i
    if add not in ps:
        print(add)
        break

Submission status: Accepted

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

P_sub_abs = [abs(i - X) for i in P]
if(P_sub_abs.count(0) == 0):
    print(X)
    exit()
for i in range(1, 100):
    if(P_sub_abs.count(i) == 1):
        list = [X - i, X + i]
        list.remove(P[P_sub_abs.index(i)])
        print(list[0])
        exit()
    elif(P_sub_abs.count(i) == 0):
        print(X - i)
        exit()

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
diff = 10000
d = {}
if n == 0:
  print(m)
else:
  for a in arr:
    if diff > abs(m - a):
      diff = abs(m - a)
    d[a] = 1
  n = 0
  while True:
    if d.get(m + n, 0) == 0 and d.get(m  - n, 0) == 0:
      print(min((m  - n, m  + n )))
      break
    if d.get(m  + n, 0) == 0:
      print(m + n)
      break
    elif d.get(m - n, 0) == 0:
      print(m - n)
      break
    n += 1

Submission status: Accepted

Solution code:
numbers = [int(i) for i in input().split()]
sequences = [int(i) for i in input().split()]
x = numbers[0]
y = numbers[0]
a = True
if numbers[0] not in sequences:
    print(numbers[0])
    a = False
while a:
    x += 1
    y -= 1
    if y not in sequences:
        print(y)
        break
    elif x not in sequences:
        print(x)
        break

Submission status: Accepted

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

def is_in_p(j):
    flag = True
    for p_i in p:
        if p_i == j:
            flag = False
    return flag

abs_min = 101 
min_num = 0

for j in range(102):
    if abs(X - j) < abs_min and is_in_p(j):
        abs_min = abs(X - j)
        min_num = j
print(min_num)

Submission status: Accepted

Solution code:

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



#print(plist)
l=list(range(-2,105))

if N >0:
    plist=list(map(int,input().split()))

    for i in range(len(plist)):
        l.remove(plist[i])


#print(l)
ans=[]
for i in range(len(l)):
    ans.append(abs(l[i]-X))

print(l[ans.index(min(ans))])

Submission status: Accepted

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

p_hash = {}
for p in p_list:
  p_hash[p] = True

i = 0
while True:
  left = x - i
  if p_hash.get(left) is None:
    print(left)
    break
  right = x + i
  if p_hash.get(right) is None:
    print(right)
    break
  i = i + 1