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()))
else:
  print(X)
  exit()
list = []
list2 = []

for i in range(max(P)):
  if i not in P and i != X:
    res = abs(X - i)
    list.append(res)
    list2.append(i)
    
maxres = list.index(min(list))
print(list2[maxres])

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
import sys
INF=1e9
import bisect
def get_int(): return int(stdin.readline().strip())
def get_ints(): return map(int,stdin.readline().strip().split()) 
def get_array(): return list(map(int,stdin.readline().strip().split()))
def get_string(): return stdin.readline().strip()
def op(c): return stdout.write(c)
#from collections import defaultdict 
#for _ in range(int(stdin.readline())):
x,n=get_ints()
p=get_array()
if n==0:
    print(x)
else:
    p.sort()
i=bisect.bisect_left(p,x)
j=i
diff1=INF
ans=0
a=x
while True:
    a=a-1
    if a not in p:
        diff1=abs(x-a)
        break
diff2=0
b=x
while True:
    b=b+1
    if b not in p:
        diff2=abs(x-b)
        break
if diff1<=diff2:
    print(a)
else:
    print(b)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if(N==0):
  print(X)
  exit()
P= list(map(int,input().split()))
c=-100
ans=100
for i in range(200):
  a=0
  for i in range(200):
    if (abs(X-c)>=abs(X-c-a)):
      if not (c+a in P):
        
        if (abs(X-ans) >=abs(X-c-a)):
          ans=c+a
          
          
    a+=1
  c+=1
if (ans>X):
  if not(X-ans+X in P):
    ans=X-ans+X
print(ans)

Submission status: Wrong Answer

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

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

if n == 0:
    print (x)

li = []
# res = float('inf')
# for i in n:
#      std = abs(x - p_list[i])
#      if std <= res:
#          res = std    
def dfslower(std) :
    """
    argument x : 基準となる数字
    y 結果となりうる数字？
    return : 結果
    """
    if std  in p_list:
        return dfslower(std-1)
        #print(std)
    else:
        return std
        

def dfsupper(std) :
    """
    argument x : 基準となる数字
    y 結果となりうる数字？
    return : 結果
    """
    if std  in p_list:
        return dfsupper(std+1)
        #print(std)
    else:
        return(std)

mininte = dfslower(x)
maxinte =  dfsupper(x)

if abs(mininte-x)> abs(maxinte -x):
    print(maxinte)
elif abs(mininte-x) <= abs(maxinte -x):
    print(mininte)

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

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

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

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

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

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:
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(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:
s = {i+1 for i in range(-101,100)}
print(s)
x, n =map(int,input().split())

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

for i in range(n):
  s.discard(il[i])
s = list(s)

absmin = 100
ans = 0

for i in range(len(s)):
  j = abs(x-int(s[i]))
  if j < absmin:
    ans = s[i]
    absmin = j

print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
if n==0:
    print(x)
    exit()
res = []
for num in range(101):
    if x!=num and num not in p:
        res.append(abs(x-num))
if x-min(res) not in p:
    print(x-min(res))
else:
    print(x+min(res))

Submission status: Wrong Answer

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

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

for j in range(N):
    S.remove(A[j])
    


n=100   
x=0
for k in S:
    if abs(k - X) < n:
        n=abs(k - X)
        x=k
    elif n == abs(k - X):
        x=min(x,k)
print(x)

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 x-i in arr:
            print(x-i)
            break
        elif x+i in arr:
            print(x+i)
            break

Submission status: Wrong Answer

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

if len(P) == 0 or not X in P:
    print(X)
    sys.exit()

flg = 1000
ans = 1000
m = max(P)
itera = list(range(1, m + 1))
itera.reverse()

for i in itera:
    if not i in P and flg > abs(X - i):
        flg = abs(X - i)
        ans = min(ans, i)

if ans == 1000:
    if abs(X - m - 1) <= X:
        ans = m + 1
    else:
        ans = 0

print(ans)

Submission status: Wrong Answer

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

  if x<a[0]:
    print(x)
  elif x>a[-1]:
    print(x)
  else:
    bb=list(range((a[0]-1),(a[-1]+1)))
    b=list(range((a[0]-1),(a[-1])))
    for n in range(n):
      b.remove(a[n])
  
    f=len(b)


    d=abs(x-int(b[0]))
    ans=b[0]

    for n in range(f):
      c=abs(x-int(b[n]))
      if d>c:
        ans=b[n]
        d=c
  
    print(ans)

    print(bb)
except:
  print(x)

Submission status: Wrong Answer

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

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

for j in range(n):
    if x - j not in li:
        ans = x - j
        print(ans)
        exit()

    elif x + j not in li:
        ans = x + j
        print(ans)
        exit()

print(x)

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]) and R>0:
            break
        else: 
            R = abs(X-Q[c])
            c += 1
    print(Q[c-1])

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)
    k = 1000
    ans = 0
    for i in retu :
        y = abs(i - x)
        if y < k :
            k = y
            ans = i
    print(ans)

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)
    elif x-i or x+i in arr:
        if x-i in arr:
            print(x-i)
            break
        elif 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()))
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))], -2, -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(ans[ans2.index(min(ans2))])
   # print(min(ans))

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
A = list(map(int, input().split()))
if N == 0:
  print(X)
else:
    while X in A:
        if X + 1 in A:
            print(X+2)
        elif X-1 in A:
            print(X+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()))
  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:
      pass

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x, n = input().split(' ')
line = input()
if line == '':
    print(x)
    exit()

x = int(x)

alist = line.split(' ')
for i in range(int(n)):
    alist[i] = int(alist[i])
if not x in alist:
    print(x)
    exit()

blist = [i for i in range(1,102)]
bset = set(blist)
aset = set(alist)
cset = bset-aset
clist = list(cset)
clist.append(x)
clist.sort()

count = 0
for i,v in enumerate(clist):
    if v == x:
        count = i
if count == 0:
    print(clist[1])
elif count == len(clist)-1:
    print(clist[-2])
else:
    minx = x - clist[count-1]
    maxx = clist[count+1]-x
    if minx > maxx:
        print(clist[count+1])
    else:
        print(clist[count-1])

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
m=float("inf")
m1=float("inf")
if n==0:
    print(x)
else:
    for i in range(x,x-50,-1):
        if i not in p:
            m=i
            break
    for i in range(x+1,x+50):
        if i not in p:
            m1=i
            break
    diff=abs(x-m)
    diff1=abs(x-m1)
    if diff<diff1:
        print(m)
    elif(diff>diff1):
        print(m1)
    else:
        print(min(m,m1))

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    a = x - 1
    b = x + 1
    if a not in p and b not in p:
        print(a)
    elif a not in p and b in p:
        print(a)
    elif a in p and b not in p:
        print(b)
    else:
        while True:
            c = 0
            d = 0
            if a not in p:
                c = abs(a - x)
            if b not in p:
                d = abs(b - x)
            if c != 0 and d == 0:
                print(a)
                quit()
            elif c == 0 and d != 0:
                print(b)
                quit()
            elif c != 0 and d != 0:
                print(a)
                quit()
            else:
                a -= 1
                b += 1

Submission status: Wrong Answer

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

P.sort()
ans = abs(10000000)
for i in range(-101, 101):
  if not i in P:
    ans = min(ans, abs(i-X))

if not X-ans in P:
  print(X-ans)
else:
  print(X+ans)

Submission status: Wrong Answer

Solution code:
import sys

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

ans1 = int()
ans2 = int()

p.sort()

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

for i in range(n):
    if x == p[i]:
        for j in range(x + 1, 100):
            if j not in p:
                ans1 = j
                break
        for k in reversed(range(x,)):
            if k not in p:
                ans2 = k
                break

if ans1 - x < x - ans2:
    print(ans1)
else:
    print(ans2)

Submission status: Wrong Answer

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

  if x<a[0]:
    print(x)
  elif x>a[-1]:
    print(x)
  else:
    bb=list(range((a[0]-1),(a[-1]+1)))
    b=list(range((a[0]-1),(a[-1]+2)))
    for n in range(n):
      b.remove(a[n])
  
    f=len(b)


    d=abs(x-int(b[0]))
    ans=b[0]

    for n in range(f):
      c=abs(x-int(b[n]))
      if d>c:
        ans=b[n]
        d=c
  
    print(ans)

    print(bb)
except:
  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()))
    a = list(range(1000))
    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:
X, N = map(int,input().split())

if N > 0:
    p = input().split()
    p = [int(i) for i in p]
    p.sort()
     
    if X > p[N - 1]:
        if X-1 == p[N-1]:
            ans = X + 1
        else :
            ans = X - 1
    else:


        for i in p:
            if X > i:
                continue
            else :
                roof = i
                num = p.index(i)
                break

        if num == 0:
            if X == roof:
                ans = X - 1
            else:
                ans = X
        
        

        if X != roof:
            ans = X

        else :
            if num == N - 1:
                if X - 1 == p[num - 1]:
                    ans = X + 1
                else :
                    ans = X - 1
            else:
                i = 1
                while True:
                    if X - i == p[num - i]:
                        if X + i == p[num + i]:
                            if num - i == 0:
                                ans = p[0] -1
                                break
                            if num + i == N - 1 and X - i - 1 == p[num - i - 1]:
                                ans = p[num + 1] + 1
                                break
                            
                            i += 1
                            continue
                        else :
                            ans = X + i
                            break
                    else :
                        ans = X - i
                        break

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

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

f = [1]*100
sa = x
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

print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map( int ,input().split())
if N == 0:
    print(X)
else:
    P = list(map( int , input().split()))
    M = max(P)
    near_M = 10001000
    for i in range(1,M+1):
        if i in P:
            continue
        near = abs(X-i)
        near_M = min(near,near_M)
        # print(near,near_M)
        if near != near_M:
            if near>near_M:
                print(X+near_M)
            else:
                print(X-near)
            break
        if near == 1 and near_M ==1:
            print(X-1)

Submission status: Wrong Answer

Solution code:
s = {i+1 for i in range(-2,100)}
#print(s)
x, n =map(int,input().split())

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

for i in range(n):
  s.discard(il[i])
s = list(s)

absmin = 100
ans = 0

for i in range(len(s)):
  j = abs(x-int(s[i]))
  if j < absmin:
    ans = s[i]
    absmin = j

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
nums=[int(x) for x in input().split()]
#print(nums)
if n == 0:
	print(x)
	exit()
min=x
gap=x
#print('Here')
for i in range(1,101):
	if i in nums:
		continue
	else:
		if abs(x-i) < gap:
			#print("min: ",min)
			#print(x-i)
			gap=x-i
			min = i
print(min)

Submission status: Wrong Answer

Solution code:
class int(int):  
  def times(self, callback):
    for times in range(0,self):
      callback()

class list(list):
  def maps(self, callback):
    return list(map(callback, self))

  def each(self, callback):
    list(map(callback, self))
    return self

  # index will sent to the function as a second parameter.
  def each_with_index(self,callback):
    list(map(callback, self, range(0,len(self))))
    return self

# Make sure you initialize object with class name.
# Ex: int(10).times, array = list([1,2,3,4,5])

target, length = input().split()
target = int(target)
length = int(length)
o_nums = list(input().split())

if length > 1:
  def convert(arg):
    return int(arg)

  o_nums = o_nums.maps(convert)
  diffs = list()
  nums = list()
  for exclude_num in range(min(o_nums), max(o_nums)+1):
    if exclude_num in o_nums:
      continue
    else:
      nums.append(exclude_num)
  
  if len(nums) == 0:
    print(target)

  else:
    for num in nums:
      diffs.append(target - num)

    def absm(arg):
      return abs(arg)

    diffs_abs = diffs.maps(absm)
    smallest_diff_index = diffs_abs.index(min(diffs_abs)) #絶対値が最も小さいもの

    if -(diffs_abs[smallest_diff_index]) in diffs: # ターゲットよりも小さい、最も差分が小さい値を探す
      index = diffs.index(-(diffs_abs[smallest_diff_index]))
      print(nums[index])
    else:
      print(nums[smallest_diff_index])

else:
  print(target)

Submission status: Wrong Answer

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

alpha = x
if not p:
  print(x)
for i in range(n):
  if alpha in p:
    alpha += (i+1)*(-1)**(i+1)
    continue
  else:
    print(alpha)
    exit()

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)
if diff_min == diff_max:
    answer = min(minimum - 1, maximum + 1)
else:
    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())
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 = 100
        dif = 100-x
        for i in range(len(o)-1, 0, -1):
            if(dif >= abs(x-o[i])):
                ans = o[i]
                dif = abs(x-o[i])
        print(ans)

Submission status: Wrong Answer

Solution code:
INF=200
def near_abs(minp,P):
    d=0
    while True:
      val=minp-d
      if val>=1:
         if val not in P:
            return val
      val=minp+d
      if val<=100:
         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:
def inp():
    ls=list(map(int,input().split()))
    return ls
x,n=map(int,input().split())
ls=inp()
ls.sort()
if n==0:
    print(x)
    exit(0)
else:
    a=x-1
    b=x+1
    flag=False
    flag1=flag2=False
    while(not flag):
        if a not in ls:
            flag=True
            flag1=True
        else:
            a-=1
        if b not in ls:
            flag = True
            flag2 = True
        else:
            b+=1
        if flag2 and flag1:
            if abs(x-a)<=abs(x-b):
                print(a)
            else:
                print(b)
            exit(0)
        elif flag1:
            print(a)
            exit(0)
        elif flag2:
            print(b)
            exit(0)

Submission status: Wrong Answer

Solution code:
import os
import sys
from io import BytesIO, IOBase
import math
import bisect

def inputIntArray():
    return list(map(int, input().rstrip().split()))


def inputArray():
    return input().rstrip().split()


def inputVars():
    return map(int, input().rstrip().split())


def inputNum():
    return int(input())


def main():
    x, n = inputVars()
    if n == 0:
        print(x)
        return
    arr = inputIntArray()
    minRes = x
    if x not in arr:
        print(x)
        return
    minRes = float('inf')
    arr.sort()
    if arr[0] >= x:
        print(x-1)
    else:
        for num in range(-x+1, 2*x):
            pos = bisect.bisect_left(arr, num)
            # if pos == len(arr) or arr[pos] != num:
            if num not in arr:
                minRes = num if abs(num-x) < abs(x-minRes) else minRes
    print(minRes)


#.........................................FAST INPUT OUTPUT.......................................
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#....................................END OF FAST I/O............................................

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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=0
minans=0
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:
import sys
# Xはもっとも近い整数，Nは与えられるP
X,N = map(int, input().split())

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

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

mainasu = X - 1
purasu = X + 1

if X in arr:
  if mainasu in arr:
    if purasu in arr:
      mainasu = mainasu - 1
      purasu = purasu + 1
      if mainasu in arr:
        if purasu in arr:
          mainasu = mainasu - 1
          purasu = purasu + 1
        else:
          print(purasu)
      else:
        print(mainasu)
    else:
      print(purasu)
  else:
    print(mainasu)
  
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()))
    M = max(P)
    near_M = 10001000
    for i in range(1,M+1):
        if i in P:
            continue
        near = abs(X-i)
        near_M = min(near,near_M)
        print(near,near_M)
        if near != near_M:
            if near>near_M:
                print(X+near_M)
            else:
                print(X-near)
            break
        if near == 1 and near_M ==1:
            print(X-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

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

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

    for i in range(1, N + 1):
        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())

if N == 0:
    print(X)
else:
    p = set(map(int, input().split()))

    num = set(range(-102, 102))

    l = list(num.difference(p))

    ans = 0
    absol = 102

    for i in l:
        a = abs(X - i)
        if a == 0:
            pass
        elif a < absol:
            absol = a
            ans = i
        else:
            pass

    print(ans)

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-i or x+i in arr:
        if x-i in arr:
            print(x-i)
            break
        elif x+i in arr:
            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, 101):
    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:
X, N = map(int, input().split())
A = list(map(int, input().split()))
if N == 0:
  print(X)
else:
    while X in A:
        if X + 1 is A:
            print(X+2)
        elif X-1 is A:
            print(X+1)

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = map(int, input().split())
if N==0:
  print(X)
  exit()
else:
  A = sorted(map(int, input().split()))

if A.count(X)==0:
  print(X)
  exit()

for k in range(N):
  if A.count(X-k)==0:
    print(X-k)
    exit()
  elif A.count(X+k)==0:
    print(X+k)
    exit()

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 = 0
    for i in range(x, -1, -1):
        if p.count(i) == 0:
            a = i
            break

    b = 0
    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)
    exit()
lst = list(map(int, input().split()))

def search(l, x, i=1):
    min_, max_ = x-i, x+i
    if not min_ in l and not max_ in l:
        return min_
    if not min_ in l:
        return min_
    if not max_ in l:
        return max_
    return search(l, x, i+1)

print(search(lst, x))

"""a, b = search(lst, x)
if abs(x-a) == abs(x-b):
    print(a)"""