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:
x,n = map(int,input().split())
p = list(map(int,input().split()))

arr = []
incc = []
for i in range(101):
    for j in range(n):
        incc.append(p[j])
    if i in incc:
        continue
    else:
        arr.append(i)
arr.pop(0)
# print(arr)
        
for i in range(1,len(arr)):
    if n == 0:
        print(x)
        break
    elif x in arr:
        print(x)
        break
    elif x-i or x+i in arr:
        if not ((x-i) in arr):
            print(x-i)
            break
        elif not((x+i) in arr):
            print(x+i)
            break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
list_p = [i for i in range(-1, 102)] 
t = x
num = x

for i in p:
  list_p[i + 1] = -2

for i in range(len(list_p)):
  if(list_p[i] == -2):
    continue
  else:
    if(abs(list_p[i] - x) <= t):
       if(abs(list_p[i] - x) < t):
        t = abs(list_p[i] - x)
        num = list_p[i]
    elif(abs(list_p[i] - x) == t):
        t = abs(list_p[i] - x)
        num = min(num, list_p[i])

print(num)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
a,b = map(int, input().split()) 

if b==0:
    #print(a)
    exit()
num_list = list(map(int, input().split()))

    

num=[True]*101
#print(num)


for i in range(b):
    num[num_list[i]]=False


num[0]=False
#print(num)

count=0
min_min=100
min_max=100
i=a
#print()
#print(i)

flag_i=0
frag_j=0
if i==100 and num[100]==True:
    print(100)
    exit()
    
#elif i==100 and 100 in num_list:
    
if i==100:
    i=99
    
    
while 1:
    if i-1==99:
        flag_i=1
        min_min=99
        break
    elif num[i-1]==True:
        min_min=i-a
        break
    i+=1
j=a
#print(min_min)
#print(i)
count=0

while 1:
    if j-1==0:
        flag_j=1
        min_max=100
        break
    elif num[j-1]==True:
        min_max=a-j
    j-=1
#print(min_max)
#print(j)
if min_min<min_max:
    print(i)
    
else:
#   if flag_j==1:
#       j=j+1
    print(j-1)

Submission status: Wrong Answer

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

if N == 0:
    print(X)
    exit()
i = 1
while True:
    if X - i not in (p):
        print(X-i)
        exit()
    if X + i not in (p):
        print(X+i)
        exit()
    i += 1

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
 
ans = X
for i in range(1,N+1):
    a = X + i
    b = X - i
    if a not in P:
        ans = a
        if b not in P:
            ans = b
        break
    if b not in P:
        ans = b
        break
print(ans)

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

s = 1000000000

for i in range(-100,102):
    if i in p:
        continue
    s = min(abs(x-i),s)
    

#if not x-s in p:
#    print(x - s)
#else:
#    print(x + s)

Submission status: Wrong Answer

Solution code:
if __name__=="__main__":
    # Problem C
    X, N = map(int, (input().split(' ')))
    if N > 0:
        P = sorted(map(int, input().split(' ')))
        P_max = max(P)
        P_min = min(P)
        if X in P:
            for i in range(0, max(P_max-X + 1 , X-P_min +1)):
                if (X-i) not in P:
                    print(X-i)
                    break

                elif (X+i) not in P:
                    print(X+i)
                    break
        elif X not in P:
            print(X)
    else:
        print(X)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n==0:
  print(x)
else:
    l1 = list(map(int,input().split()))	
    l2 = list(range(1, 100))
    diff = set(l1) ^ set(l2)
    diff = list(diff)
    def sorting(numbers_array):
      return sorted(numbers_array, key=abs)
    sl = map(lambda a: a - x, diff)
    print(sorting(sl)[0])

Submission status: Wrong Answer

Solution code:
A, B = map(int, input().split())
if B == 0:
    print(A)
else:
    L = list(map(int,input().split()))
    K = L.copy()
    L = [abs(i - A) for i in L]
    L = sorted(L)
    #print(L)
    X = []
    for i in range(1,B+1):
        X+=[i//2]
    for i in range(B):
        if L[i] != X[i]:
            break
    s,t = A-X[i],A+X[i]
    #print(s,t)
    if (s in K) ==True:
        print(t)
    else:
        print(s)

Submission status: Wrong Answer

Solution code:
def readInts():
 return list(map(int, input().split()))

def main():
  a = input()
  a =a.split(" ")
  p = readInts()
  x = int(a[0])
  n = int(a[1])
  i= x -1
  j = x + 1
  
  while i  in p:
    i -=1
    
  while j  in p:
    j += 1
 
  if abs(x-i) <= abs(x-j):
    print(i)
  else:
    print(j)
  
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
a,b = map(int, input().split()) 

if b==0:
    #print(a)
    exit()
num_list = list(map(int, input().split()))

    

num=[True]*101
#print(num)


for i in range(b):
    num[num_list[i]]=False


num[0]=False
print(num)

count=0
min_min=100
min_max=100
i=a
#print()
#print(i)

flag_i=0
frag_j=0
if i==100 and num[100]==True:
    print(100)
    exit()
    
#elif i==100 and 100 in num_list:
    
if i==100:
    i=99
    
    
while 1:
    if i-1==99:
        flag_i=1
        min_min=99
        break
    elif num[i-1]==True:
        min_min=i-a
        break
    i+=1
j=a
#print(min_min)
print(i)
count=0

while 1:
    if j-1==0:
        flag_j=1
        min_max=100
        break
    elif num[j-1]==True:
        min_max=a-j
    j-=1
#print(min_max)
print(j)
if min_min<min_max:
    print(i)
    
else:
#   if flag_j==1:
#       j=j+1
    print(j-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
x,y =map(int, input().split())
p =list(map(int, input().split()))

n = []
b=10000

for c1 in range(101):
    if c1 not in p:
        if(abs(x-b) > abs(x-c1)):
            b=c1
print(b)

Submission status: Wrong Answer

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

arr = []

if n == 0:
    print(x)
else:
    tmp = input()
    num = tmp.split(' ')
    num_li = [int(i) for i in num]
    arr.extend(num_li)

    min = x
    max = x
    for i in range(10000):

        min -= 1
        max += 1

        if min not in arr:
            print(min)
            break

        if max not in arr:
            print(max)
            break

Submission status: Wrong Answer

Solution code:
x,n = list(map(int,input().split()))
if n >0 :
  p = list(map(int,input().split()))
y = 200
#ans = x
if n == 0:
  print(x)
else:
  for i in range(-100,102):
    if i != x:
      if p.count(i) == 0:
        #print('i=',i,abs(x-i))
        if abs(x-i) < y:
          ans = i
          y = abs(x-i)
          #print('i=',i,'abs=',abs(x-i),'ans=',ans)
  print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
m=100
j=0
for i in range(1,101):
    if abs(x-i)<m and str(i) not in str(p):
        m=abs(x-i)
        j=i
print(j)

Submission status: Wrong Answer

Solution code:
X, N = map(int,input().split())
P = list(map(int,input().split()))
P.sort()
diff = 10**10
ans = -1
for p in range(101):
    if p in P:
        continue
    if abs(X-p) < diff:
        diff = abs(X-p)
        ans = p
print (ans)

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()))
p.sort()
wk = 101
an = 0
if n ==100:
    print(0)
    sys.exit()
for i in range(102):
    if x!=i:
        if p.count(i)==0:
            if abs(x-i)<wk:
                an =i
                wk = abs(x-i)
            else:
                print(an)
                sys.exit()
print(an)

Submission status: Wrong Answer

Solution code:
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    read = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    read = raw_input
readint = lambda: int(rr())
readlist = lambda: map(int, read().split())

####
def solve((X, N), A):
    Aset = set(A)
    ans = 1234
    for p in range(101):
        if p not in Aset:
            d = abs(p - X)
            if d < ans:
                ans = d
                ansi = p
    return ansi

print solve(readlist(), readlist())

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
if n==0:
    print(x)
a,b = x,x
while True:
    a+=1
    b-=1
    if a not in p:
        print(a)
        break
    elif b not in p:
        print(b)
        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()))
    m=10000
    ans=N
    for i in range(-101,101):
        if m>abs((i)-X) and not i in p:
            m=abs((i)-X)
            ans=i
    print(ans)

Submission status: Wrong Answer

Solution code:
if __name__=="__main__":
    # Problem C
    X, N = map(int, (input().split(' ')))
    if N > 0:
        P = sorted(map(int, input().split(' ')))
        P_max = max(P)
        P_min = min(P)
        if X in P:
            for i in range(1, max(P_max-X + 1 , X-P_min +1)):
                if (X-i) not in P:
                    print(X-i)
                    break

                elif (X+i) not in P:
                    print(X+i)
                    break
        elif X not in P:
            print(X)
    else:
        print(X)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

x,n=(int(y) for y in input().split())

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

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

st = []
for i in range(n):
  st.append(s[i] - x)

ss = np.abs(st)
ss.sort()

for t in range(n):
  if ss[t] != t:
    ans = t
    break
fans = x - t
ffans = x + t
if fans in s and ffans in s:
  print(fans)
elif fans in s:
  print(ffans)
else:
  print(fans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
elif N == 100:
    print(0)

else:
    p = list(map(int, input().split()))
    abs_list = []
    re_list = []
    min = 1000
    min_index = 0

    for i in range(250):
        abs_list.append(-100+i)
    for j in p:
        abs_list.remove(j)
    for i in range(len(abs_list)):

        re_list.append(abs(abs_list[i] - X))
    for i in range(len(re_list)):
        if min > re_list[i]:
            min = re_list[i]
            min_index = i
    if re_list[min_index] > X:
        print(0)
    else:
        print(abs_list[min_index])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
minn = 10000000
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))
for i in range(101):
    if i not in p:
        tmp = abs(x-i)
        if minn > tmp:
            ans = i
            minn = tmp
        elif minn == tmp:
            ans = min(i, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
def readInts():
 return list(map(int, input().split()))

def main():
  a = input()
  a =a.split(" ")
  p = readInts()
  x = int(a[0])
  n = int(a[1])
  i= x -1
  j = x + 1
  
  while i not in p:
    i -=1
    
  while j not in p:
    j += 1
  
  if abs(x-i) <= abs(x-j):
    print(i)
  else:
    print(j)
  
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
def resolve():
	X, N = map(int, input().split())
	if N == 0:
		print(X)
	else:
		A = list(map(int, input().split()))
		ymin = min(min(A), X)-1
		ymax = max(max(A), X)
		Y = {}
		for y in range(ymin, ymax):
			if y in A:
				None
			else:
				key = int(abs(X-y))
				if key in Y.keys():
					Y[key] = Y[key] + [y]
				else:
					Y[key] = [y]
		key = min(Y.keys())
		print(min(Y[key]))
resolve()

Submission status: Wrong Answer

Solution code:
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
list_p = [i for i in range(-1, 102)] 
t = x
num = x

if(x == n):
  print(x - 1)
  sys.exit()

for i in p:
  list_p[i + 1] = -2

for i in range(len(list_p)):
  if(list_p[i] == -2):
    continue
  else:
    if(abs(list_p[i] - x) <= t):
      t = abs(list_p[i] - x)
      num = min(num, list_p[i])

print(num)

Submission status: Wrong Answer

Solution code:
if __name__=="__main__":
    # Problem C
    X, N = map(int, (input().split(' ')))
    if N > 0:
        P = sorted(map(int, input().split(' ')))
        P_max = max(P)
        P_min = min(P)
        if X in P:
            for i in range(1, max(P_max-X + 1 , X-P_min +1)):
                if (X-i) not in P:
                    print(X-i)
                    break

                elif (X+i) not in P:
                    print(X+i)
                    break
        elif X not in P:
            print(X)
        else:
            print(" ")
    else:
        print(X)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


cand_1 = x
while (1):
    cand_1 -= 1
    if cand_1 not in pn:
        #print(cand)
        #exit()
        break
cand_2 = x
while (1):
    cand_2 += 1
    if cand_2 not in pn:
        break

print(min(cand_1, cand_2))

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input(). split())
l = [0]*n
m = [0]*100
ans = 0
p = list()
if n > 0:
  p = list(map(int, input(). split()))
else:
  print(x)
  sys.exit()
for i in range(n):
  l[i] = abs(x-p[i])
  m[l[i]] += 1
if m[0] == 0:
  print(x)
for j in range(1, 100):
  if m[j] != 2:
    a = x-j
    A = x+j
    b = p.count(a)
    B = p.count(b)
    if b == 0:
      ans = a
      if j > x:
        ans = 0
    else:
      ans = A
      if j > x:
        ans = 0
    break
print(ans)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
list2 = set(map(int, input().split()))
list1=list(range(-100,101,1))
result = list(set(list1) - set(list2))
for i in range(200):
    if a-i in result:
        print(a-i)
        exit()
    elif a+i in result:
        print(a+i)
        exit()

Submission status: Wrong Answer

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


if len(p) != 0:
    if (1 <= X <= 100) and (0 <= N <= 100) and (max(p) <= 100 and 1 <= min(p)):

        
        ans = X-1
        bns = X+1
        if N != 0:
    
            for i in range(N):
                if ans not in p:
                    print(ans)
                    break
            
                if ans in p:
                    ans-=1         
                    if ans not in p:
                        print(ans)
                        break
                
                if bns not in p:
                    print(bns)
                    break
            
                if bns in p:
                    bns+=1
                    if bns not in p:
                        print(bns)
                        break
        elif N ==0:
            print(X)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
 
if N == 0:
    print(X)
    exit()
 
P = list(map(int,input().split()))
    
s = sorted(P)
 
ss = []
for i in range(s[0],s[N-1]+1):
    ss.append(i)

    
result = list(set(ss) - set(s))

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

if not result:
    print(X)
else:
    print(result[ans.index(min(ans))])

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
m = {}
for i in range(101):
    if i in P:
        continue
    ab = abs(i - X)
    m[i] = ab
# min_kv_list = [kv for kv in m.items() if kv[1] == min(m.values())]
min_k_list = [kv[0] for kv in m.items() if kv[1] == min(m.values())]
print(min(min_k_list))

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()
list = []
list2 = []
for i in range(-5,max(P)+50):
  if i not in P and i != X:
    res = abs(X - i)
    list.append(res)
    list2.append(i)
    
maxres = list.index(min(list))
if list2[maxres] != 0:
  print(list2[maxres])
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N > 0:
    l = list(map(int, input().split()))
    A = [0] * N
    ok = 0

    for i in range(N):
        A[i] = abs(l[i] - X)

    S = A.count(0)
    if S == 0:
        print(X)
        ok = 1

    if ok == 0:
        for i in range(1, 101):
            S = A.count(i)
            if S == 0:
                print(X - 1)
                break
            if S == 1:
                if l.count(X - i) == 0:
                    print(X - i)
                    break
                else:
                    print(X + i)
                    break
            else:
                pass

else:
    print(X)

Submission status: Wrong Answer

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

for i in range(101):
    if not i in p:
        tmp = abs(x-i)
        if minn > tmp:
            ans = i
            minn = tmp
        elif minn == tmp:
            ans = min(i, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input(). split ())
c = map(int,input(). split ())
if b == 0:
  print(a)
count = 0
for i in list(c):
  if not i == a:
    count += 1
    
if count == 1:
  print(a)

Submission status: Wrong Answer

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

D = 10000
res = 0
for i in range(-100,100+1):
  if i in P:
    continue
  X2 = abs(X-i)
  if X2 < D:
    D = X2
    res = i
#
print(res)

Submission status: Wrong Answer

Solution code:
X_N = [int(i) for i in input().split()]
X = X_N[0]
N = X_N[1]

if N == 100:
    index = 0

elif N != 0 and N !=100:
    p = [int(i) for i in input().split()]
    ary = [i for i in range(1,101)]
    for j in range(N):
        if p[j] in ary:
            ary.remove(p[j])
    min = abs(X-ary[0])
    if ary[0]!=None:
        index = ary[0]
    for j in range(1,len(ary)):
        if min > abs(X-ary[j]):
            min = abs(X-ary[j])
            index = ary[j]

elif N == 0:
    index = X

print(index)

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input(). split())
l = [0]*n
m = [0]*100
ans = 0
p = list()
if n > 0:
  p = list(map(int, input(). split()))
else:
  print(x)
  sys.exit()
for i in range(n):
  l[i] = abs(x-p[i])
  m[l[i]] += 1
if m[0] == 0:
  print(x)
for j in range(1, 100):
  if m[j] != 2:
    a = x-j
    A = x+j
    b = p.count(a)
    B = p.count(b)
    if b == 0:
      ans = a
      if abs(x-a) > x:
        ans = 0
    else:
      ans = A
      if abs(x-A) > x:
        ans = 0
    break
print(ans)

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

s = 1000000000

for i in range(-100,101):
    if i in p:
        continue
    s = min(abs(x-i),s)
    

if not x-s in p and x-s > 0:
    print(x - s)
else:
    print(x + s)

Submission status: Wrong Answer

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

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

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

ans = 1001001
tmp = 1001001
for i in range(p[0]-1, p[-1]+1):
    if i in p: continue
    if abs(x-i) < tmp:
        tmp = abs(x-i)
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
oin = input()
x, n = int(oin.split(" ")[0]), int(oin.split(" ")[1])
if n == 0:
  print(x)
  exit()
p = input().split(" ")
xpo = x+1
xdetect = list(range(0, 101))
if x == 1 and 1 in p:
  print(0)
  exit()
def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
for b in p:
  try:
    xdetect.remove(int(b))
  except ValueError:
    continue
print(getNearestValue(xdetect, x))

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
X,N = (int(i) for i in input().split())
if N !=0:
    p = list(map(int, input().split()))
elif N ==0:
    p=[-1]
p.sort()
p_100 =[i for i in range(1,101)]

#
ans =[]
for i in range(1,101):
    if i not in p:
        ans.append((abs(i-X),i))
ans.sort()
if len(ans) >=2:
    print(min(ans[0][1],ans[1][1]))
elif len(ans) ==0:
    print(0)
else:
    print(ans[0][1])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
seisulist = list(map(int, input().split()))
if n != 0 and max(seisulist) >= x:
    size = max(seisulist) + 1
else:
    size = x + 1
numlist = [i for i in range(0,size) if i not in seisulist]
xretu = [x]*len(numlist)
hikizan = [abs(s-t) for (s, t) in zip(numlist, xretu)]
sa = min(hikizan)
if x-sa not in seisulist:
    print(x-sa)
else:
    print(x+sa)

Submission status: Wrong Answer

Solution code:
#%%

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

if n == 0:
	print(x)

else:
	p = list(map(int, input().split()))
	n = list(range(101))

	a = 0
	b = 0

	i = 0
	for i in range(len(p)):
  		if p[i] in n:
          	  n.remove(p[i])

	j = 0
	for j in range(len(n)):
    	  if n[j] < x:
        	a = n[j]
        
	k = 0
	n.reverse()
	for k in range(len(n)):
    	  if n[k] > x:
        	b = n[k]
        
	if x - a > b - x:
    	  print (b)
	else:
    	  print (a)

Submission status: Wrong Answer

Solution code:
import sys
def main():
    x_num, n = map(int, input().split())
    
    p_nums = list(map(int, input().split()))
    
    if n == 0:
        print(x_num)
        sys.exit()
    
    i = 1
    while(True):
        up_num = x_num + i
        down_num = x_num - i
        
        up_sub = abs(x_num - up_num)
        down_sub = abs(x_num - down_num)
        
        if up_num in p_nums:
            if down_num in p_nums:
                i+= 1
                continue
            else:
                if down_num == 0:
                    i+= 1
                    continue
                print(down_num)
                sys.exit()
        else:
            if down_num in p_nums:
                if up_num == 0:
                    i+= 1
                    continue
                print(up_num)
                sys.exit()
            elif up_sub == down_sub:
                if down_num == x_num:
                    i+= 1
                    continue
                print(min(up_num, down_num)) 
                sys.exit()
        i += 1
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

p = set(map(int,input().split()))
not_p = list(set(range(0,100)) - p)

minV = 101
ans = 0
for i in not_p:
    if abs(X - i) < minV:
        minV = abs(X - i)
        ans = i
        
if minV == 101:
    if X < 51:
        ans = 0
    else:
        ans = 100
print(ans)

Submission status: Wrong Answer

Solution code:
def test(X, N, P):
  P_int = []
  
  for i in P:
    P_int.append(int(i))

  lis = []
  
  for i in list(range(101)):
    if i not in P_int:
      lis.append(i)
  
  min_adv = 1000
  min_num = 1000

  for i in lis:
    rec_adv = abs(X - i)

    if rec_adv < min_adv:
      min_num = i
      min_adv = rec_adv

  if N != 0:
    print(str(min_num))
  else:
    print(str(X))
    
X, N = input().split()
P = input().split()

test(int(X), int(N), P)

Submission status: Wrong Answer

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

p_ = [i for i in range(100)]
p_ = list(set(p_) - set(p))

list = []
list_ = []
for j in p_:
  C = abs(X-j)
  list.append(C)
  list_.append(X-j)
list.sort()

if list_.count(list[0]) == 0:
  print(X+list[0])
else:
  print(X-list[0])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def solution():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    else:
        numList = list(map(int, input().split()))

    a = [i for i in range(1, 101) if i not in numList]
    for i in range(len(a)):
        if i != len(a)-1:
            if a[i]<x and a[i+1] > x:
                if x-a[i] < a[i+1]-x:
                    print(a[i])
                    break
                else:
                    print(a[i+1])
                    break
            else:
                continue
        else:
            print(a[i])



solution()

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()))
p.sort()
wk = 101
an = 0
if n ==100:
    print(0)
    sys.exit()
for i in range(101):
    if x!=i:
        if p.count(i)==0:
            if abs(x-i)<wk:
                an =i
                wk = abs(x-i)
            else:
                print(an)
                sys.exit()
print(an)

Submission status: Wrong Answer

Solution code:

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



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

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

else:
    for i in range(0,101):
        if l.count(int(X))<1:
            print(int(X))
            break 


        elif l.count(int(X-i))<1:
            print(int(X-i))
            break 

    

        if X+i<=100:
            if l.count(int(X+i))<1:
                print(int(X+i))
                break

Submission status: Wrong Answer

Solution code:
import numpy as np 

X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    l = list(map(int, input().split()))
    l = sorted(l)
    number_list = []
    for i in range(l[-1] * 100000):
        number_list.append(i+1)
    for k in l:
        if k in number_list:
            for num, li in enumerate(number_list):
                if li == k:
                    number_list.pop(num)
    number_list.append(X)
    number_list = sorted(number_list)
    for n,b in enumerate(number_list):
        if b == X:
            if np.abs(number_list[n-1] - X) > np.abs(number_list[n+1] - X):
                print(number_list[n+1])
                
            elif np.abs(number_list[n-1] - X) < np.abs(number_list[n+1] - X):
                print(number_list[n+1])
                
            elif np.abs(number_list[n-1] - X) == np.abs(number_list[n+1] - X):
                if number_list[n-1] > number_list[n+1]:
                    print(number_list[n+1])
                elif number_list[n-1] < number_list[n+1]:
                    print(number_list[n-1])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split(' '))
if n > 0:
    p = list(map(int, input().split(' ')))
    r = x + 1
    l = x - 1
  
    ansr = 0
    ansl = 0
    for i in range(102):
        if r not in p:
            break
        r += 1
    ansr = r
    for i in range(102):
        if l not in p:
            break
        l -= 1
    ansl = l
    vr = ansr - x
    vl = x - ansl
    if vr == vl:
        ans = ansl if ansl <= ansr else ansr
    else:
        ans = ansl if vl < vr else ansr
else:
    ans = x
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = map(int,input().split())
p = [map(int, input().split())]
mylist=list(np.arange(1,101))
new_list = set(mylist) - set(p)
a= []
for i in new_list:
    b = abs(i-X)
    a.append(b)
c = [i for i, v in enumerate(a) if v == min(a)]
print(c[0]+X)

Submission status: Wrong Answer

Solution code:
import numpy as np

i = input()
n = [int(x) for x in i.split(' ')]
l = input()
l = np.fromstring(l, dtype=int, sep=' ')

def final (babs, aabs):
  if babs > aabs:
      print(a)
  elif aabs > babs or aabs == babs:
    print(b)

if n[1] == 0:
  print(n[0])
elif n[1] == 100:
  if n[0] > 50:
    print('101')
  else:
    print('0')
elif n[0] not in l:
  print(n[0])
elif n[0] in l:
  if n[0] == 1:
    print('0')
  elif n[0] == 100:
    print('101')
  l = np.setdiff1d(l, [n[0]])
  
  pp = np.arange(1, 101)
  npp = np.setdiff1d(pp, l)

  npp = npp.tolist()
  
  if len(npp) > 0:
    ix = npp.index(n[0])
    if ix == 0:
      # before none
      a = npp[ix + 1]
      print(a)
    elif len(npp) == ix + 1:
      # after none
      b = npp[ix - 1]
      print(b)
    else:
      b = npp[ix - 1]
      babs = abs(n[0] - b)
      a = npp[ix + 1]
      aabs = abs(n[0] - a)
      final(babs, aabs)
  else:
    print(n[0])

Submission status: Wrong Answer

Solution code:
def fun(x):
  var=1
  first=0
  while True:
     if (x-var) not in n:
        first +=(x-var)
        # print("var is",var)
        return var
    
     var +=1

def funco(x):
  var=1
  first=0
  while True:
     if (x-var) not in n:
        first +=(x-var)
        # print("var is",var)
        return first
    
     var +=1
      
      

    

def fun2(x):
  var=1
  second=0
  while True:
    if (x+var) not in n:
       second +=(x+var)
      #  print("var is",var)
       return var

    var +=1

def fun2co(x):
  var=1
  second=0
  while True:
    if (x+var) not in n:
       second +=(x+var)
      #  print("var is",var)
       return second

    var +=1


def main(x):
  s=(fun(x))
  t=(fun2(x))
  # print(s)
  # print(t)
  if s>t:
    print(fun2co(x))
  else:
    print(funco(x))

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


if x[1]<=0:
  print(x[0])

else:
  n=list(map(int,input().split()))
  main(x[0])
# n.append(x[0])
# print(sorted(n))