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:
from math import ceil

X, N = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l2 = [abs(int(x)-X) for x in l]
l2.sort()
t = 0
for i in range(N):
    if ceil(i/2) != l2[i]:
        t = ceil(i/2)
        break
if X - t not in l:
    print(X - t)
else:
    print(X + t)

Submission status: Wrong Answer

Solution code:
d = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

int_x = int(d[0])
int_n = int(d[1])




ans = 100000
tmp = abs(int_x - ans)
for i in range(101):
  if tmp > abs(int_x - i):
    if not i in p:
      ans = i
      tmp = abs(int_x - ans)

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = (int(each) for each in input().split())
if n == 0:
    print(x)
else:
    p = [int(each) for each in input().split()]
    candidate = 0
    for i in range(max(p)+1):
        if i not in p and abs(i-x) < abs(candidate-x):
            candidate = i
            # print('replaced')
    print(candidate)

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
tmp=[]
if n==0:
    print(x)
    sys.exit()
for i in range(1,101):
    ans=x-i
    if not ans in p:
        print(ans)
        sys.exit()
    an=x+i
    if not an in p:
        print(an)
        sys.exit()

Submission status: Wrong Answer

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

p.sort()
s = 0
t = 0

for i in range(0,100-x):
    if x+i not in p:
        s = x+i
        break

for j in range(0,-100,-1):
    if x+j not in p:
        t = x+j
        break

if abs(x-s) < abs(x-t):
    print(s)
else:
    print(t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=[int(n) for n in input().split()]
arr=list(map(int,input().strip().split()))
if(m==0):
    print(n)
else:
    j=n
    s1=205
    while(j>=1):
        flag=0
        for i in range(m):
            if(arr[i]==j):
                flag=1
                break
        if(flag==1):
            j=j-1
        else:
            s1=j
            break
    j=n
    s2=206
    while(j<101):
        flag=0
        for i in range(m):
            if(arr[i]==j):
                flag=1
                break
        if(flag==1):
            j=j+1
        else:
            s2=j
            break
    if(s1==205 and s2==206):
        print(0)
    else:
        a=abs(n-s1)
        b=abs(n-s2)
        if(a<=b and a<102):
            print(s1)
        elif(a>b and b<102):
            print(s2)

Submission status: Wrong Answer

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):
  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: Wrong Answer

Solution code:
X,N=map(int,input().split())
p=sorted(map(int,input().split()))
m=100
ans=X
for i in range(101):
    diff=abs(X-i)
    if i not in p and diff<m:
        m=diff
        ans=i
print(ans)

Submission status: Wrong Answer

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 = tgt-offset
        else:
            look_down = True
            tgt = offset + offset
            offset += 1

    print(tgt)
else:
    print(x)

Submission status: Wrong Answer

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


def f(X, N, listp):

    if N == 0:
        return X

    up_list = []
    down_list = []
    for p in listp:
        if p > X:
            up_list.append(p)
        if p < X:
            down_list.append(p)

    up_list = sorted(up_list)
    down_list = sorted(down_list, reverse=True)


    up_res = 10000
    for i, p in enumerate(up_list):
        if p != X+i+1:
            up_res = X+i+1
            break

    down_res = -10000
    for i, p in enumerate(down_list):
        if p != X-i-1:
            down_res = X-i-1
            break


    if abs(X - up_res) < abs(X - down_res):
        return up_res
    else:
        return down_res


print(f(X, N, listp))

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
sa = float("inf")
for i in range(-1, 101):
    if i not in p:
        sa = min(sa, abs(i - x))
if sa + x not in p and x - sa not in p:
    print(min(sa + x, x - sa))
elif sa + x in p:
    print(x - sa)
else:
    print(x + sa)

Submission status: Wrong Answer

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

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

min_near = 0
big_near = 0

m = x
while min_near == 0:
    m -= 1
    if not m in ps:
        min_near = m

b = x
while big_near == 0:
    b += 1
    if not b in ps:
        big_near = b


min_diff = x - min_near
big_diff = big_near - x

if (min_diff > big_diff):
    # big_diffの方が差が小さければbig_near
    print(big_near)
else:
    # それ以外はmin_near
    print(min_near)

Submission status: Wrong Answer

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

for i in range(101):
    if (i in p):
        continue
    else:
        tmp=(x-i)**2
        if tmp<ans:
            ans=tmp
            c=i
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    p.sort()

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

    for i in range(n):
        low = x - i
        if (low not in p):
            print(low)
            sys.exit()
        up = x + i
        if (up not in p):
            print(up)
            sys.exit()
    
main()

Submission status: Wrong Answer

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

X_max = X
X_min = X

while True:
    if N == 0 or (X in p == False):
        print(X)
        break
        break
    X_max += 1
    X_min -= 1
    if (X_min in p) == False:
        print(X_min)
        break
        break
    if (X_max in p) == False:
        print(X_max)
        break
        break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted([i for i in range(101)], reverse=True)

ans = {'diff':1000, 'ans':0}

for i in q:
    if not i in p:
        if abs(x-i) <= ans['diff']:
            ans['diff'] = abs(x-i)
            ans['ans'] = i

print(ans['ans'])

Submission status: Wrong Answer

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

else:
    print(x)

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int,input().split())
    li = list(map(int,input().split()))
    li2 = []
    ans = 0
    for i in range(101):
        check = True
        for j in li:
            if j == i:
                check = False
        if check:
            li2.append(i)
    for i in li2:
        if abs(ans - x) > abs(i - x):
            ans = i
    print(ans)
 
 
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N ==0:
    print(X)
else:
    p = list(map(int,input().split()))
    min1=[]
    x_min = 100
    num_list = list(range(101))
    for i in range(N):
        num_list.remove(p[i])
    for j in reversed(num_list):
        x = abs(j-X)
        if x_min >= x:
            x_min =  x
            close=j
    print(close)

Submission status: Wrong Answer

Solution code:

import numpy as np
from functools import *

import sys
sys.setrecursionlimit(100000)



def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


def acinput():
    return list(map(int, input().split(" ")))


X,N=acinput()
if N>0:
    p=sorted(acinput())
else:
    print(X)
    sys.exit()

res=-1
res_v=10**9
for i in range(1,101):
    #print(res,res_v)
    d=abs(X-i)
    if res_v>=d and not (i in p):
        if i<X:
            res_v=d
            res=i
        elif d<res_v:
            res_v=d
            res=i
        
print(res)        
#print(res_v)

Submission status: Wrong Answer

Solution code:
def main():
  X, N = map(int, input().split())
  if N == 0:
    return X
  
  P = list(map(int, input().split()))
  
  if X < min(P) or X > max(P):
    return X
  
  delta = []
  for n in range(min(P), max(P) + 1):
    if n in P:
      delta.append(float('inf'))
    else:
      delta.append(abs(X - n))
  minD = min(delta)
  for i, d in enumerate(delta):
    if d == minD:
      return min(P) + i
  

print(main())

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 = high = low = 0
while True:
    if X + diff not in P:
        high = X + diff
    if X - diff not in P:
        low = X - diff
    if high == 0 and low == 0:
        diff += 1
        continue

    if high == low:
        print(low)
    elif low == 0:
        print(high)
    else:
        print(low)
    break

Submission status: Wrong Answer

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,101):
            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: Wrong Answer

Solution code:


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

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

an = [0]*101

#an[x]=-1 if n != 0 else 0

for pi in pn:
    an[pi] = -1


dist = 10000
ans = 99999
for i, ai in enumerate(an):
    if ai == -1:
        continue

    if dist > abs(i-x):
        dist = abs(i-x)
        ans = i


print(ans)

Submission status: Wrong Answer

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(1, 101))
    notinp = np.array(list(tmp - set_p))
    if len(notinp) == 0:
        print(0)
    else:
        t = np.abs(np.array(notinp) - X)
        argmin = t.argmin()
        print(notinp[notinp == notinp[argmin]].min())

Submission status: Wrong Answer

Solution code:
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
b=sorted(b)
base = 1000
for i in range(1, 101):
  if abs(a[0]-base)>abs(a[0]-i) and i not in b:
    base = i
print(base)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
ans1 = 999999
for i in range(20,-1,-1):
    if i not in p:
        if abs(x - i) <= abs(x - ans1):
            ans1 = i
print(ans1)

Submission status: Wrong Answer

Solution code:
X,N=map(int, input().split())
p=list(map(int, input().split()))
seisuu=[0 for i in range(0,101)]
if N==0:
    print(X)
else:
    for i in range(0,N):
        seisuu[p[i]]=1
    count1=X-1
    count2=X+1
    ans=0
    if seisuu[X]==0:
        print(X)
    else:
        while True:
            if count1>=0 and count2<=100:
                if seisuu[count1]==0:
                    ans=count1
                    break
                elif seisuu[count2]==0:
                    ans=count2
                    break
            else:
                if count1<0:
                    ans=count1
                    break
                elif count2>100:
                    ans=count2
                    break
            count1-=1
            count2+=1
        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(0,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())
P = [int(x) for x in input().split()]

a = X
i = 0
for i in range(200):
    if P.count(a) == 0:
        print(a)
        break
    else:
        i += 1
        a = a - i
        if P.count(a) == 0:
            print(a)
            break
        else:
            i += 1
            a = a + i
            if P.count(a) == 0:
                print(a)
                break

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if (N == 0):
  print(X)
else:
  nums = list(map(int, input().split()))
    
  nums.sort()
  low = nums[0]
  high = nums[-1]
  minDiff = 100000000
  minNum = -1
  for i in range(low+1, high):
    if i in nums:
      continue
    else:
      Dif = abs(X-i)
    if (Dif < minDiff):
      minDiff = Dif
      minNum=i

  if (minNum == -1):
    print(X)
  else:
    print(minNum)

Submission status: Wrong Answer

Solution code:
d = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

int_x = int(d[0])
int_n = int(d[1])




ans = 100
tmp = abs(int_x - ans)
for i in range(101):
  if tmp > abs(int_x - i):
    if not i in p:
      ans = i
      tmp = abs(int_x - ans)

print(ans)

Submission status: Wrong Answer

Solution code:
#H, W = map(int,input().split())
#N = int(input())
#al = list(map(int,input().split()))
X, N = map(int,input().split())
pl = list(map(int,input().split()))

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

anslst = []
for n in lst:
    if not n in pl:
        anslst.append(n)


an = 101
idx = 0
for i in range(len(anslst)):
    tmp = abs(X - anslst[i])
    if tmp < an:
        an = tmp
        idx = i


ans = anslst[idx]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X,N = list(map(int,input().split()))
if N == 0:
  print(X)
  exit()
P = sorted(list(map(int,input().split())))
ans1 = P[0] - 1
ans2 = P[-1] + 1
isx = 0
for i in range(1,N):
  if (P[i]-X) > 0:
    if not isx:
      ans1 = X
      break
    else:
      break
  if P[i-1] != (P[i]-1):
    ans1 = P[i] -1
  if P[i] == X:
    isx = 1
    break

for i in range(1,N):
  if (P[-i]-X) < 0:
    if not isx:
      ans1 = X
      break
    else:
      break
  if P[-i+1] != (P[-i]+1):
    ans2 = P[-i] + 1
  if P[-i] == X:
    isx = 1
    break

if not isx:
  print(X)
  exit()

aa1 = abs(X-ans1)
aa2 = abs(X-ans2)
if aa1 == aa2:
  print(ans1)
elif aa1 > aa2:
  print(ans2)
else:
  print(ans1)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
S=[0]*(101);a=1000;b=1000;c=10000
for i in range(N):
  S[P[i]]=1
#print(S)
if N==0:
  print(X)
else:
  i=X-1
  while i>=0:
    if S[i]==0:
      a=i
      break
    i=i-1
  i=X+1
  while i<=100:
    if S[i]==0:
      b=i
      break
    i=i+1
  #print(a,b)
  if abs(a-X)>abs(b-X):
    c=b
  else:
    c=a
  print(c)

Submission status: Wrong Answer

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

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

f = [1]*100
sa = 100
ans = 0

for i in p:
    f[i-1] = 0

for i in range(100):
    if f[i] == 1 and sa > abs(i+1-x):
        sa = abs(i+1-x)
        ans = i+1

if ans == 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
def around_nums(x):
    i = 1

    while(True):
        yield x - i
        yield x + i
        i += 1

x, n = tuple(map(int, input().split()))
temp = input()

if n > 0:
    nums = list(map(int, temp.split()))
    for n in around_nums(x):
        if not n in nums:
            print(n)
            break
else:
    print(x)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n ==0:
  print(x)
  exit()
q = [int(i) for i in input().split()]
p = sorted(abs(i-x) for i in q)
for i in range(n):
    if i != p[i]:
        if x - i not in q:
            print(x - i)
        else:
            print(x + i)
        exit()

Submission status: Wrong Answer

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

num_set = set(range(0, 101))

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

print(min_ans)

Submission status: Wrong Answer

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

ans=1000
m=-1
if abs(x-m)<=abs(x-100):
    m=-1
else:
    m=100
for i in range(100):
    if abs(x-ans)>abs(x-i) and i not in p:
        ans=i

if abs(x-ans)<abs(x-m):
    print(ans)
elif abs(x-ans)==abs(x-m):
    print(min(ans,m))
else:
    print(m)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
l = [int(x) for x in input().split()]
mp = [False]*101
for i in range(n):
    mp[l[i]] = True



queue = [x]
while(len(queue)>0):
    now = queue.pop(0)
    if(now <= 0 or now >=101):
        print(now)
        exit()
    if(mp[now]==False):
        print(now)
        exit()
    
    if(now==x):
        queue.append(now+1)
        queue.append(now-1)
    if(now < x):
        queue.append(now-1)
    if(now > x):
        queue.append(now+1)

Submission status: Wrong Answer

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

for i in range(1, 101):
  if (x-i) not in list:
    print(x-i)
    break
  if (x+i) not in list:
    print(x+i)
    break

Submission status: Wrong Answer

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

not_in_p = list(range(1,101))
for pn in p:
    if pn in not_in_p:
        not_in_p.remove(pn)
print(not_in_p)

diff_p = []
for not_in_pn in not_in_p:
    diff_p.append(abs(not_in_pn - X))
min_value_index =  [j for j, value in enumerate(diff_p) if value == min(diff_p)]

answer = 0
for index in min_value_index:
    if answer == 0:
        answer = not_in_p[index]
    elif answer > not_in_p[index]:
        answer = not_in_p[index]

print(answer)

Submission status: Wrong Answer

Solution code:
import sys

a = list(map(int, input().split()))
X = a[0]
N = a[1]

try:
  p = list(map(int, input().split()))
except EOFError:
  print(X)
  sys.exit()

flg = 0
i = 1
while (flg == 0):
  if (X - i not in p):
    print(X - i)
    flg = 1
    break
  elif (X + i not in p):
    print(X + i)
    flg = 1
    break
  i += 1

Submission status: Wrong Answer

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 a[0] != 0 and not a[1] in P:
        print(a[1])
        exit()

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()))

a=[]
b=[]
p_min=min(p)-1
p_max=max(p)+1
for i in range(p_min,p_max):
    if  i not in p :
        a.append(abs(x-i))
        b.append(i)

ans=min(a)
bb=a.index(ans)
print(b[bb])

Submission status: Wrong Answer

Solution code:
#C
# -*- coding: utf-8 -*-


def serchBup(list,n):
    if n in list:
        return 1+serchBup(list,n+1)
    else:
        return 1
        
    
def serchBdown(list,n):
    if n in list:
        return -1+serchBup(list,n-1)
    else:
        return -1

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

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

    for i in range(n):
        if abs(x-p[i])<min:
            min  = abs(x-p[i])
            ans = p[i]
            pos=i

    if ans!=x:
        print(ans)
    else:
        tmp1=serchBup(p,ans+1)
        tmp2=serchBdown(p,ans-1)
        #print(tmp1,tmp2)
        if abs(tmp1) < abs(tmp2):
            print(ans+tmp1)
        else:
            print(ans+tmp2)

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
    a = 1
    while roop_flg:
        print(trgt)
        if trgt not in p:
            break
        else:
            if a > 0:
                trgt = trgt -a
                a = -(a+1)

            else:
                trgt = trgt -a
                a = -(a-1)


    print(trgt)

Submission status: Wrong Answer

Solution code:
# coding:utf-8
x, n = map(int, input().split())
p = list(map(int, input().split()))


if n == 0:
    print(x)
else:
    ps = sorted(p)
    tmp = [_ for _ in range(-101, 101)]
    ans_list = list(set(tmp) ^ set(ps))
    # print(tmp, ans_list)
    diff = []

    for i in ans_list:
        diff.append(abs(i - x))

    print(ans_list[diff.index(min(diff))])

Submission status: Wrong Answer

Solution code:
"""
6 5
4 7 10 6 
"""
x,n = map(int, raw_input().split(' '))

ais = map(int, raw_input().split(' ')) if n else []
ais.sort()


def f(x, u, v):
	#returns the number thats closest to x within range u,v
	if u + 1 == v: return (+float('inf'), +float('inf'))
	if u < x < v: return (0,x) 	
	if x >= v: return (abs(x - (v -1)), v-1)
	if x <= u: return (abs(x - (u +1)), u + 1)
res = (+float('inf'), +float('inf'))
ais = [0] + ais + [101]
for u,v in zip(ais,ais[1:]):
	res = min(res , f(x,u,v))

print res[1]

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys


def int1(x): return int(x) - 1
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def mi1(): return map(int1, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def lli(rows_number): return [li() for _ in range(rows_number)]


if __name__ == "__main__":
    x, n = mi()
    if n == 0:
        print(x)
        exit()
    p_l = li()
    a = list(range(1, max(p_l)+1))
    for p in p_l:
        try:
            a.remove(p)
        except ValueError:
            pass
    ans = 0
    min_dif = 10000
    for i in a:
        dif = abs(i-x)
        if dif <= min_dif:
            min_dif = dif
            ans = i
    print(ans)

Submission status: Wrong Answer

Solution code:

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

d=150
pa = 0
px =range(1,101,1)
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

if n == 100:
    if x<=50:
        print(0)
    else:
        print(101)

print(pa)

Submission status: Wrong Answer

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

ans = x

for i in range(n):
    tmp1 = x - i
    tmp2 = x + i
    if not tmp1 in p:
        ans = tmp1
    if not tmp2 in p:
        ans = min(ans , tmp2)
        break

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  X, N = map(int, input().split())
  if N == 0:
    return X
  
  P = list(map(int, input().split()))
  
  if X < min(P) or X > max(P):
    return X
  
  delta = []
  for n in range(min(P), max(P) + 1):
    if n in P:
      delta.append(float('inf'))
    else:
      delta.append(abs(X - n))
  print(list(range(min(P), max(P) + 1)))
  
  print(delta)
  
  minD = min(delta)
  for i, d in enumerate(delta):
    if d == minD:
      return min(P) + i
  

print(main())

Submission status: Wrong Answer

Solution code:
X, N = list(map(int, input().split()))
if N != 0:
	P = list(map(int, input().split()))
	ans = 0
	i = 1
	for _ in range(N // 2):
		L = X - i
		H = X + i
		if L not in P:
			print(L)
			break
		elif H not in P:
			print(H)
			break
		i += 1
else:
	print(X)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
nlist=list(map(int,input().split()))
Nlist=[]
if n==0:
    print(x)
    exit(0)

for i in range(-x,x):
    if i not in nlist:
        Nlist.append(i)
abslist=[abs(x-i) for i in Nlist]
#print(abslist)
if x-min(abslist)  not in nlist:
    print(x-min(abslist))
else:
    print(x+min(abslist))

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p_list = [int(x) for x in input().split()]
  x_list = list(range(101))
  for i in range(n):
    p_i = p_list[i]
    if p_i in x_list:
      x_list.remove(p_i)
  for i in range(51):
    x_hiku = x - i
    x_tasu = x + i
    if x_hiku in x_list:
      print(x_hiku)
      break
    elif x_tasu in x_list:
      print(x_tasu)
      break

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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 + diff + n, 0) == 0 and d.get(m - diff - n, 0) == 0:
      print(min((m - diff - n, m + diff + n )))
      break
    if d.get(m + diff + n, 0) == 0:
      print(m + diff + n)
      break
    elif d.get(m - diff - n, 0) == 0:
      print(m - diff - n)
      break
    n += 1

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0: print(X)
else:
    p=list(map(int,input().split()))
    ans=10000
    m=-100
    for i in range(-100,100):
        if m>(i+1)-X and (not i+1 in p):
            if abs(ans-X)!=abs((i+1)-X):
                ans=i+1
            m=abs((i+1)-X)
    print(ans)

Submission status: Wrong Answer

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

min_ = 100
for i in range(100):
    cur = i + 1
    if cur in P:
        continue
    diff = abs(X - cur)
    if diff < min_:
        min_ = diff

front = X - min_
back = X + min_
if front not in P:
    print(front)
else:
    print(back)

Submission status: Wrong Answer

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

tmp = [(abs(i-x), i) for i in range(-100, 101) if i not in ps]
min_d = min(tmp, key=lambda x: x[0])[0]

ans = min(filter(lambda x: x[0] == min_d, tmp), key=lambda x:x[1])

print(ans[1])

Submission status: Wrong Answer

Solution code:
import numpy as np

def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    P = set(map(int, input().split()))
    if x not in P:
        print(x)
        return

    P_not = np.array(list(set(list(range(1, 102))) - P))
    diff = np.abs(P_not - x)
    print(P_not[diff.argmin()])

resolve()

Submission status: Wrong Answer

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

diff = 1000
for i in range(-100, 101):
    if i in p:
        continue
    if abs(i - x) < diff:
        diff = abs(i - x)
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
num_list = list(map(int, input().split()))
dif = 101
o_list = []
num_list.sort(reverse=True)

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

for i in range(1, max(num_list)):
    if i not in num_list:
        o_list.append(i)
#
# for num in num_list:
#     if abs(x - num) <= dif:
#         if x not in num_list:
#             ans = x
ans = x
o_list.sort(reverse=True)

for num in o_list:
    if abs(x - num) <= dif:
        # if x not in num_list:
        dif = x -num
        ans = num

print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    X, N = list(map(int, input().split()))
    p = list(map(int, input().split()))
    q = p
    for i in range(N):
        q[i] = abs(X-p[i])
    
    if q.count(0) == 0:
        print(X)
    else:
        j = 1
        while True:
            if q.count(j) != 2:
                if X-j in p:
                    print(X+j)
                else:
                    print(X-j)
                break
            j += 1