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())
if n != 0:
  p = list(map(int,input().split()))
p_change = []
m = 0
if n == 0:
  print(x)
else:
    for i in p:
        p_change.append(abs(i-x))

    if x in p:
        for i in range(n):
            if i != 0 and p_change.count(i) != 2:
                m = i
                break
        if x-m in p_change:
            print(x+m)
        else:
            print(x-m)
    else:
        print(x)

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
    count2=X
    ans=0
    if seisuu[X]==0:
        print(X)
    else:
        while True:
            if count1>0 and count2<=100:
                if seisuu[count1]==0:
                    ans=count1
                    break
                if seisuu[count2]==0:
                    ans=count2
                    break
            else:
                if count1<=0:
                    ans=0
                    break
                if count2>100:
                    ans=101
                    break
            count1-=1
            count2+=1
        print(ans)

Submission status: Wrong Answer

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

def main():
    if n == 0:
        print(x)
        return

    ans_l = list(range(1, 101))

    diff_l = list(set(p) ^ set(ans_l))
    diff_l.sort()

    cnt = 100
    ans = 100
    for i in range(0, len(diff_l)):
        check = abs(diff_l[i]-x)
        if check < cnt:
            cnt = check
            ans = diff_l[i]
    print(ans)
    return

main()

Submission status: Wrong Answer

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

result = x
sa = 100
count = 0
for l in range(1,101):
    if l in p:
        continue
    
    if sa <= abs(x-l):
        result = count 
        break
    count = l
    sa = abs(x -l)
else:
    result = count
print(result)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n == 0:
    print(x)
    exit()
lst = [int(i) for i in input().split()]
n_lst = [int(i) for i in range(1,101)]
mn1 = -1
mn2 = -1
for i in range(x-1,99):
    if not(n_lst[i] in lst):
        mn1 = n_lst[i]
        break
n_lst = n_lst[::-1]
for i in range(100 - x, 99):
    if not(n_lst[i] in lst):
        mn2 = n_lst[i]
        break

if mn1 == mn2 ==-1:
    if x <= 50:
        print(0)
        exit()
    elif x > 50:
        print(101)
        exit()
if mn1 == -1 and mn2 != -1:
    if (x-1) - (mn2-x) > 0:
        print(mn2)
        exit()
    else:
        print(0)
        exit()
if mn2 == -1 and mn1 != -1:
    if (x-mn1) - (100-x) > 0:
        print(101)
        exit()
    else:
        print(mn1)
        exit()
if abs(mn1-x) >= abs(mn2-x):
    print(mn2)
else:
    print(mn1)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
x = a[0]
if a[1] == 0 :
    print(x)
else :
    b = list(map(int,input().split()))
    retu = []
    for i in range(1,101) :
        retu.append(i)
    for i in b :
        if i in retu :
            retu.remove(i)
    print(retu)
    k = 1000
    ans = i
    for i in retu :
        y = abs(i - x)
        if y < k :
            k = y
            ans = i

    print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import numpy as np

X, N = map(int, input().split())
p_array = np.array(list(map(int, input().split())))

if N ==0:
    print(X)

else:
    p_array = sorted(p_array)

    left = bisect.bisect_left(p_array, X) - 1
    right = left + 2

    i = left
    left_answer = X - 1
    if i < 0:
        pass
    else:
        while True:
            if i <= 0:
                left_answer -= 1
                break

            if p_array[i] == left_answer:
                i -= 1
                left_answer -= 1
            else:
                break
         
    j = right
    right_answer = X + 1
    if j > N:
        pass
    else: 
        while True:
            if j >= N:
                right_answer += 1
                break

            if p_array[j] == right_answer:
                j += 1
                right_answer += 1
            else:
                break


    if X - left_answer <= right_answer - X:
        print(left_answer)
    else:
        print(right_answer)

Submission status: Wrong Answer

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

n = X
i = 1

while 1 <= i <= 100:
    if n in p:
        if i%2 == 0:
            n = n + i
        else:
            n = n - i   
    else:
        print(n)
        break
    i = i + 1

Submission status: Wrong Answer

Solution code:
k,n=map(int,input().split())
l=list(map(int,input().split()))
a=[]
for i in range (500):
	a.append(0)
x=0
for i in range(n):
	x=l[i]-k
	
	if x<0:
		a[2*abs(x)-1]=1
		
		
	else :
		a[2*x]=1
for i in range(200):
	if(a[i]==0):
		break
if(i%2==0):
	x=i/2
	print(int(k+x))
else:
	x=(i+1)/2
	print(int(k-i))

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(A)-1
		ymax = max(A)
		Y = {}
		for y in range(ymin, ymax):
			if y in A:
				None
			else:
				key = abs(X-y)
				if key in Y:
					Y[key] = Y[key] + [y]
				else:
					Y[key] = [y]
		key = min(Y.keys())
		print(min(Y[key]))
resolve()

Submission status: Wrong Answer

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

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

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

else:
  P = list(map(int,input().split()))
  P_set = list(set(P))
  
  
  ans_chk = 0
  
  if ( X < P_set[0] or X > P_set[N-1] ):
    #print("X < P_set[0] or X > P_set[N-1]")
    print(X)
    ans_chk = 1
  
  if ( ans_chk==0 ):
    for i in range(N):
      if ( P_set[i] == X ):
        X_i = i
        break
      elif ( P_set[i] > X ):
        #print("P_set[i] > X")
        print(X)
        ans_chk = 1
        break
  
  if ( ans_chk==0 ):
    
    if ( X_i > N-(X_i+1) ): # 上の数が少ない → 下は1回多くする
      M = N-(X_i+1)
      temp_ans = X + N-(X_i+1) +1
      #print("temp_ans =",temp_ans)
      
      for i in range(1,M+1):
        if ( P_set[ X_i -i ] != X-i ):
          print(X-i)
          ans_chk = 1
          break
        elif ( P_set[ X_i +i ] != X+i ):
          print(X+i)
          ans_chk = 1
          break
      
      if ( ans_chk==0 ):
        if ( P_set[ X_i -(M+1) ] != X-(M+1) ):
          print( X-(M+1) )
          ans_chk = 1
  
  
    else: # 下の数が少ないor同数 → そのまま
      M = X_i
      temp_ans = X - X_i -1
      #print("temp_ans =",temp_ans)
    
      for i in range(1,M+1):
        if ( P_set[ X_i -i ] != X-i ):
          print(X-i)
          ans_chk = 1
          break
        elif ( P_set[ X_i +i ] != X+i ):
          print(X+i)
          ans_chk = 1
          break
  
  if ( ans_chk==0 ):
    print(temp_ans)

Submission status: Wrong Answer

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

array = [[0]]*100
if n == 0:
    print(x)
else:
    for i in range(100):
        array[i] = 0
    tmp = input().split(' ')
    for i in range(n):
        array[int(tmp[i])-1] = 1
    
    dif_tmp = 999
    ret = 999
    for i in range(100):
        if array[99-i] == 0:
            if abs(x-(99-i)) <= dif_tmp:
                ret = 99-i
                dif_tmp = abs(x-(99-i))
    for i in range(1,100):
        if abs(x+i) <= dif_tmp:
            ret = -i-1
            dif_tmp = abs(x+i)
    print(ret+1)

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()))
if x == 1:
    print(0)
    sys.exit()

a = []
b = []

for i in range(0, 100):
    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:
import sys

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

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

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

ans = 1000

p.sort()
min = [1000, 1000]

for i in range(100):
  if i in p:
    continue
  hoge = abs(x - i)
  if min[0] > hoge:
    min[0] = hoge
    min[1] = i

print(min[1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!


x,n = map(int, input().split())
def deflis(n):
    tempn=int(n)
    return tempn-x
num_list = list(map(deflis, input().split()))
num_list.sort()
count=0
maxans=1
minans=-1
maxflag=False
minflag=False
minlist=[]
maxlist=[]
for num in num_list:
    if(num<0):
        minlist.append(num)
    else:
        maxlist.append(num)

for mintemp in range(len(minlist)):
    if(minlist[len(minlist)-mintemp-1]==minans):
        minans=minans-1
for maxtemp in maxlist:
    if(maxtemp==maxans):
        maxans=maxans+1

if(abs(minans)>abs(maxans)):
    print(x+maxans)
else:
    print(x+minans)

Submission status: Wrong Answer

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

def main():
    if n == 0:
        print(x)
        return

    ans_l = list(range(1, 100))

    diff_l = list(set(p) ^ set(ans_l))
    diff_l.sort()

    cnt = 100
    ans = 100
    for i in range(0, len(diff_l)):
        check = abs(diff_l[i]-x)
        if check < cnt:
            cnt = check
            ans = diff_l[i]
    print(ans)
    return

main()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
Q = [i for i in range(-100, 101) if i not in P]

c = 0
R = 1000
if N == 0:
    print(X)
else:
    while c <= len(Q)-1:
        if R <= abs(X-Q[c]):
            break
        else: 
            R = abs(X-Q[c])
            c += 1
    print(Q[c-1] if c>0 else Q[0])

Submission status: Wrong Answer

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

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

arr = [0]*101
tmp=float('inf')
for i in range(len(P)):
  target=P[i]
  arr[target]=1

near=float('inf')
idx =0
for i in range(len(arr)):
  if arr[i] == 0:
    if near > abs(X-i):
      near = abs(X-i)
      idx = i
if idx == 0:
  print(idx)
elif (idx +1 in P) or (idx-1 in P):
  print(idx)
else:
  print(-idx)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N == 0 :
    print(X)
else :
    P = list(map(int,input().split()))
    a = list(range(0,101))
    ab = 100
    an = []
    for i in range(N):
        a.remove(P[i])
    for j in range(100 - N):
        ab = min(ab,abs(X - a[j]))
    if X - ab in a :
        print(X - ab)
    elif X + ab in a:
        print(X + ab)

Submission status: Wrong Answer

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

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

a = [i for i in range(-110,210)]

for j in p:
    d = a.index(j)
    a.pop(d)

if (x in a):
    pass
else:
    a.append(x)
    a.sort()

idx_x = a.index(x)

'''
if (idx_x == 0):
    print(a[idx_x+1])
    sys.exit()
if (idx_x == len(a)-1):
    print(a[-2])
    sys.exit()
'''
lesser = a[idx_x-1]
greater = a[idx_x+1]

dl = abs(x - lesser)
dg = abs(greater - x)

if (dl <= dg):
    print(lesser)
else:
    print(greater)

Submission status: Wrong Answer

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

    b = 1000
    for i in range(x, 101):
        if p.count(i) == 0:
            b = i
            break

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

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 != 0:
    p = [int(i) for i in input().split()]
    ary = [i for i in range(1,101)]
    min = abs(X-ary[0])
    index = ary[0]
    for j in range(N):
        if p[j] in ary:
            ary.remove(p[j])
    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 math

X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
# print(X, N, p)

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

p.sort()

minimum = p[0]
maximum = p[len(p) - 1]
# print(minimum, maximum)

if X < minimum or maximum < X:
    print(X)
    exit()

diff_min = abs(X - minimum - 1)
diff_max = abs(X - maximum + 1)
answer = minimum - 1 if diff_min < diff_max else maximum + 1
for candidate in range(minimum, maximum):
    if candidate in p: continue

    diff_answer = abs(X - answer)
    diff_candidate = abs(X - candidate)
    # print(candidate, diff, answer)
    if diff_candidate == diff_answer:
        answer = min(answer, candidate)
    elif diff_candidate < diff_answer:
        answer = candidate

print(answer)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)

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

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


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

l=[0] * 100

for i in p:
    l[i-1] =1

diff=1000
ans=100
for i in range(100):
    if l[i] == 0 and diff > abs(x-(i+1)):
        diff= abs(x-(i+1))
        ans=i+1

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin


X,N=[int(x) for x in stdin.readline().rstrip().split()]
P=[int(x) for x in stdin.readline().rstrip().split()]
l=[i for i in range(-100,101) if i not in P]
abslist = list(map(lambda a:abs(a-X),l))
print(l[abslist.index(min(abslist))])

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = map(int, input().split())
p = list(map(int, input().split()))
cnt1 = []
cnt2 = []
for i in range(-100,101):
  if not i in p:
    cnt1.append(i)
    cnt2.append(abs(X-i))
cnt2_ = np.array(cnt2)
b = np.argmin(cnt2_)
print(cnt1[b])

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(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:
import sys

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

a = []
b = []

for i in range(0, 100):
    if i not in p:
        a.append(abs(x - i))
        b.append(i)
        print(a,b)
ans = min(a)
bb = a.index(ans)
print(b[bb])

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()
mi=abs(X+1)
cotae=-1
for i in range(1,101):
  if(i in P):
    continue
  if(abs(X-i)<mi):
    mi=abs(X-i)
    cotae=i
print(cotae)

Submission status: Wrong Answer

Solution code:
str1 = input()
str2 = input()

A = str1.split(" ")
B = str2

res = 0
#print(A[1])
if A[1] == "0":
    res = A[0]
else:
#    print("A[1]!=0")
    B = B.split(" ")
    intB = []
    for i in B:
        intB.append(int(i))
    intB.sort(reverse=True)

    X = int(A[0])
    N = int(A[1])

    res = 0
    diff = 999999

    # 1~100の配列を作る
    l = list(range(-101, 102))

    # 入力内容を削る
    for i in range(0, N):
        l.pop(intB[i]+101)

    print(l)
    for i in l:
        if 0 == abs(X - int(i)):
            diff = 0
            res = i
            break
        elif diff > abs(X - int(i)):
            diff = abs(X - int(i))
            res = i
#            print(diff, res)


print(res)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if(n == 0):
    print(x)
elif(n == 100):
    ff = 101-x
    gg = x
    if(ff < gg):
        print(101)
    else:
        print(0)
else:
    p = list(map(int, input().split()))
    if(not(x in p)):
        print(x)
    else:
        m = [i for i in range(1, 101)]

        o = list(set(m) - set(p))
        ans = 1
        dif = x-1
        for i in range(len(o)):
            if(dif > abs(x-o[i])):
                ans = o[i]
                dif = abs(x-o[i])
        print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
try:
  p = list(map(int, input().split()))
except EOFError:
  p = []

int_list = [i for i in range(-100,101)]
forbidden_list = list(set(int_list) - set(p))
num_X = int_list.index(X)
c = 10000000

if X in forbidden_list:
  print(X)
elif X == 0:
  print(-1)
else:
  for i in range(len(forbidden_list) - 1):
    a = abs(X - forbidden_list[i])
    b = abs(X - forbidden_list[i + 1])
    if a == b:
      print(forbidden_list[i])
      break
    elif c > a:
      c = a
    elif c <= a and b > a:
      print(forbidden_list[i - 1])
      break
    else:
      print(forbidden_list[i])
      break

Submission status: Wrong Answer

Solution code:
X , N = map(int, input().split())
p = list(map(int,input().split()))
ans = []
if N == 0:
    print(X)
elif X not in  p:
    print(X)
else:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],101):
        if i not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], -100, -1):
        if i not in p:
            ans.append(i)
            break
    
    ans = sorted(ans)
    ans2 = [abs(i-X) for i in ans]
    print(ans[ans2.index(min(ans2))])

Submission status: Wrong Answer

Solution code:
XN = input().split()
X = int(XN[0])
N = int(XN[1])
if N == 0:
    print(X)
else:
    p = input().split()
    A = [None]*N
    for i in range(N):
        A[i] = abs(int(p[i])-X)
    print(A)
    j = 0
    while j in A:
        j += 1
    if j == 0:
        print(X)
    elif j == 1:
        print(X-j)
    else:
        if A.count(j-1) == 2:
            print(X-j)
        else:
            if str(X-(j-1)) in p:
                print(X+(j-1))
            else:
                print(X-(j-1))

Submission status: Wrong Answer

Solution code:
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
x,n=get_ints()
p=get_array()
ans1=x 
ans2=x
for j in range(x,0,-1):
    if j not in p:
        ans1=j 
        break
        
for k in range(x,102):
    if k not in p:
        ans2=k 
        break
if ans2-x<x-ans1:
    print(ans2)
elif x-ans1<ans2-x:
    print(ans1)
else:
    print(ans1)

Submission status: Wrong Answer

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


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

    for i in range(100):
        abs_list.append(i + 1)
    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
    print(abs_list[min_index])

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
Q = [i for i in range(-100, 101) if i not in P]

c = 0
R = 1000
if N == 0:
    print(X)
else:
    while c <= len(Q)-1:
        if R <= abs(X-Q[c]):
            break
        else: 
            R = abs(X-Q[c])
            c += 1
    print(Q[c-1])

Submission status: Wrong Answer

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

def main():
    if n == 0:
        print(x)
        return

    ans_l = list(range(1, 100))

    diff_l = list(set(p) ^ set(ans_l))
    diff_l.sort()
    print(diff_l)

    cnt = 100
    ans = 100
    for i in range(0, len(diff_l)):
        check = abs(diff_l[i]-x)
        if check < cnt:
            cnt = check
            ans = diff_l[i]
    print(ans)
    return

main()

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(1,101):
    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 = []
p = list(map(int, input().split()))
i = 0
j = 0
ans = 0
if(n == 0):
    print(x)
for i in range(200):
    X = x + ((-1) ** (i)) * int((i + 1) / 2)
    for j in range(n):
        if(X == p[j]):
            ans = 1
            break
        ans = 0
    if(ans == 0):
        print(X)
        break

Submission status: Wrong Answer

Solution code:
lst = []
l = []
str = input()
l = str.split(' ')
n = int(l[0])
no = int(l[1])
if no==0:
  print(n)
 

else:  
  str1 = input()
  lst = str1.split(' ')
  for i in range(0,no):
    lst[i] = int(lst[i])
  for i in range(1,100):
    if n-i not in lst:
      print(n-i)
      break
    if n+i not in lst:
      print(n+i)
      break

Submission status: Wrong Answer

Solution code:
def main():
  X, N = map(int, input().split())
  if N == 0:
    print(X)
    return
  p = tuple(map(int, input().split()))  
  if X not in p:
    print(X)
  
  not_p = list(set([i for i in range(max(p)+2)]) - set(p))
  not_p_X = [abs(X - i) for i in not_p]
  print(not_p[not_p_X.index(min(not_p_X))])
    
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(A)-1
		ymax = max(A)
		Y = {}
		for y in range(ymin, ymax):
			if y in A:
				None
			else:
				key = abs(X-y)
				if key in Y:
					Y[key] = min(Y[key], y)
				else:
					Y[key] = y
		key = min(Y.keys())
		print(Y[key])
resolve()

Submission status: Wrong Answer

Solution code:
xn=input()
x,n=xn.split()
if n=='0':
  print(int(x))
else:
  p=input()
  p={int(i) for i in p.split()}
  s={i for i in range(-100,100)}
  s_p=list(s-p)
  d=[abs(i-int(x)) for i in s_p]
  print(s_p[d.index(min(d))])

Submission status: Wrong Answer

Solution code:
import math
from sys import stdin

X,N=[int(x) for x in stdin.readline().rstrip().split()]
P=[int(x) for x in stdin.readline().rstrip().split()]
l=[i for i in range(-1,101) if i not in P]
abslist = list(map(lambda a:abs(a-X),l))
print(l[abslist.index(min(abslist))])

Submission status: Wrong Answer

Solution code:
import sys
def main():
    x_num, n = map(int, input().split())
    if n == 0:
        print(x_num)
        sys.exit()
    
    p_nums = list(map(int, input().split()))
    
    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:
                print(down_num)
                sys.exit()
        else:
            if down_num in p_nums:
                print(up_num)
                sys.exit()
            elif up_sub == down_sub:
                print(min(up_num, down_num)) 
                sys.exit()
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def do():
    n,m=map(int,input().split())
    l=list(map(int,input().split()))
    k1 = 0
    k2 = 0
    v1 =0
    v2=0
    if m==0:
        return n
    for i in range(n,0,-1):
        k2+=1
        if i not in l:
            k1=i
            break

    for j in range(n,100+1):
        v2+=1
        if j not in l:
            v1=j
            break
    if k2>v2:
        if v1!=0:
           return v1
        else:
            return k1
    elif k2==v2:
        return min(v1,k1)
    else:
        if k1!=0:
           return k1
        else:
           return v1



print(do())

Submission status: Wrong Answer

Solution code:
X , N = map(int, input().split())
p = list(map(int,input().split()))
ans = []
if N == 0:
    print(X)
elif X not in  p:
    print(X)
else:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],101):
        if i not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], -100, -1):
        if i not in p:
            ans.append(i)
            break
    
    ans = sorted(ans)
    ans2 = [abs(i-X) for i in ans]
    #ans2 = sorted(ans2)
    print(min(ans))
   # print(ans[ans2.index(min(ans2))])
   # print(min(ans))

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
elif x==0 and n==1:
    lst=list(map(int,input().split()))[:n]
    print(lst[0]-1)
else:
    lst=list(map(int,input().split()))[:n]
    for j in range(1,100000):
        x1=abs(abs(x)+abs(j))
        x2=abs(abs(x)-abs(j))
        if x2 not in lst:
            print(x2)
            break
        elif x1 not in lst:
            print(x1)
            break
        else:
            continue

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
if a[1] == 0:
    print(a[0])
else:
    b = list(map(int, input().split()))
    b.sort()
    c = []
    outside = min(b)
    while(len(c) == 0 or abs(outside - a[0]) <= abs(a[0] - min(b))):
        if outside not in b:
            c.append(outside)
        outside += 1
    res = 1000001
    out = 0
    for i in range(len(c)):
        if (abs(c[i] - a[0]) < res):
            res = abs(c[i] - a[0])
            out = c[i]
    print(out)

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] = -1

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

print(num)

Submission status: Wrong Answer

Solution code:
INF=200
def near_abs(minp,P):
    d=0
    while True:
      val=minp-d
      if val<1:
        break
      if val not in P:
        return val
      val=minp+d
      if val>100:
        break
      if val not in P:
        return val
      d+=1

X,N=map(int,input().split())
if N==0:
  print(X)
else:
  *p,=map(int,input().split())
  dp = [INF]*N
  dp[0]=abs(p[0]-X)
  minp=p[0]
  for i in range(1,N):
    dp[i]=abs(p[i]-X)
    if dp[i]<dp[i-1]:
      minp=p[i]
  print(near_abs(minp,p))

Submission status: Wrong Answer

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

if N ==0:
    print(X)
else:
      for i in range(1,N+1):
        if X -i not in n:
            print(X-i)
            break
        elif X + i not in n:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)

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

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

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

l=[0] * 100

for i in p:
    l[i-1] =1

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

print(ans)

Submission status: Wrong Answer

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

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

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

allList=[]

for i in range(-201,301):
    allList.append(i)

diff = set(allList) ^ set(p)



diff = list(diff)
diff.append(x)
diff = sorted(diff)

# print(diff)

ind = diff.index(x)
# print(ind)

# if x == 100:
    

a = diff[ind-1]
b = diff[ind+1]
# print(a,b)

ax = abs(x-a)
bx = abs(x-b)

# print(ax,bx)

if ax==bx:
    if a < b:
        print(a)
    else:
        print(b)

if ax > bx:
    print(b)
else:
    print(a)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

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(n):
    if not (x-i) in p:
      print(x-i)
      break
    elif not (x+i) in p:
      print(x+i)
      break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if(n == 0):
    print(x)
elif(n == 100):
    ff = 101-x
    gg = x
    if(ff < gg):
        print(101)
    else:
        print(0)
else:
    p = list(map(int, input().split()))
    m = [i for i in range(1, 101)]

    o = list(set(m) - set(p))
    ans = 1
    dif = x-1
    for i in range(len(o)):
        if(dif > abs(x-o[i])):
            ans = o[i]
            dif = abs(x-o[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
lst = []
l = []
str = input()
l = str.split(' ')
n = int(l[0])
no = int(l[1])
if no==0:
  print(n)
 

else:  
  str1 = input()
  lst = str1.split(' ')
  for i in range(0,no):
    lst[i] = int(lst[i])
  for i in range(1,100):
    
    if n+i not in lst:
      print(n+i)
      break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if(n == 0):
    print(x)
elif(n == 100):
    ff = 101-x
    gg = x
    if(ff < gg):
        print(101)
    else:
        print(0)
else:
    p = list(map(int, input().split()))
    m = [i for i in range(1, 101)]

    o = list(set(m) - set(p))
    ans = 1
    dif = x
    for i in range(len(o)):
        if(dif > abs(x-o[i])):
            ans = o[i]
            dif = abs(x-o[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 10**18
l = []
if x not in p:
  print(x)
else:
  for i in range(0,100):
    if (abs(i - x) < abs(ans - x)) and (i not in p):
      ans = i
  print(ans)