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

    if n == 0:
        minimum = x
    else:
        if x in p_lst:
            minimum = x

        else:
            lst = []
            flag = False

            while True:
                x1 = x
                x2 = x
                x1 += 1
                x2 -= 1

                if x1 not in p_lst:
                    lst.append(x1)
                    flag = True
                if x2 not in p_lst:
                    lst.append(x2)
                    flag = True

                if flag:
                    break

            minimum = min(lst)

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
    print(X)
else:
    w=input()
    w=w.split()
    t=list(w)
    b=list(range(-100,101))
    tt=[int(a) for a in t]

    ttt=set(tt)
    bb=set(b)

    c=bb^ttt

    cc=list(c)

    u=1000

    for s in cc:
        if abs(s-X)<u:
            u=abs(s-X)
    if (X-u) in cc:
            print(X-u)
    else :
            print(X+u)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
    print(X)
else:
    w=input()
    w=w.split()
    t=list(w)
    b=list(range(1,101))
    tt=[int(a) for a in t]

    ttt=set(tt)
    bb=set(b)

    c=bb^ttt

    cc=list(c)

    u=1000

    for s in cc:
        if abs(s-X)<u:
            u=abs(s-X)
    if (X-u) in cc:
            print(X-u)
    else :
            print(X+u)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
w=input()
w=w.split()
t=list(w)
b=list(range(1,101))
tt=[int(a) for a in t]

ttt=set(tt)
bb=set(b)

c=bb^ttt

cc=list(c)

u=1000
for s in cc:
    if abs(s-X)<u:
        u=abs(s-X)
if (X-u) in cc:
    print(X-u)
else :
    print(X+u)

Submission status: Wrong Answer

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

if N==0:
  print(X)
  exit(0)
  
p = [int(i) for i in input().split()]

for i in range(X):
  for s in [-1,1]:
    a = X + i*s
    if a not in p:
      print(a)
      exit(0)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N>0:
  p = [int(i) for i in input().split()]
else:
  p = [-1]
  
p = sorted(p)
#print(p)

try:
  idx=p.index(X)
  for i in range(N):
    for o in [-1,+1]:
      idx2=idx+(i*o)
      #print(i, idx2, X+i*o, p[idx2])
      if idx2 < 0 or idx2 >= N or X+i*o!=p[idx2]:
        print(X+(i*o))     
        exit()

except ValueError:
  print(X)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N>0:
  p = [int(i) for i in input().split()]
else:
  p = [-1]
  
p = sorted(p)
#print(p)

try:
  idx=p.index(X)
  flag=False
  for i in range(N):
    for o in [-1,+1]:
      if idx+(i*o) < 0 or idx + (i*o) >= N:
        print(X+(i*o))
        flag=True
        break
      elif X+(i*o)!=p[idx+(i*o)]:
        print(X+(i*o))
        flag=True
        break
    if flag:
      break
except:
  print(X)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N>0:
  p = [int(i) for i in input().split()]
else:
  p = [-1]
  
p = sorted(p)

try:
  idx=p.index(X)
  for i in range(N):
    if idx-i<0:
      print(X-i)
      break
    elif idx+i>=N:
      print(idx, i)
      print(X+i)
      break
    elif X-i!=p[idx-i]:
      print(X-i)
      break
    elif X+i!=p[idx+i]:
      print(X+i)
      break
except:
  print(X)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N>0:
  p = [int(i) for i in input().split()]
else:
  p = [-1]
  
p = sorted(p)

try:
  idx=p.index(X)
  for i in range(N//2+2):
    if idx-i<0:
      print(X-i)
      break
    elif idx+i>=N:
      print(idx, i)
      print(X+i)
      break
    elif X-i!=p[idx-i]:
      print(X-i)
      break
    elif X+i!=p[idx+i]:
      print(X+i)
      break
except:
  print(X)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N>0:
  p = [int(i) for i in input().split()]
else:
  p = [-1]
  
p = sorted(p)

try:
  idx=p.index(X)
  for i in range(N//2+1):
    if idx-i<0:
      print(X-i)
      break
    elif idx+i>=N:
      print(X+i)
      break
    elif X-i!=p[idx-i]:
      print(X-i)
      break
    elif X+i!=p[idx+i]:
      print(X+i)
      break
except:
  print(X)

Submission status: Wrong Answer

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

if n == 0:
  print(x)
else:
  lis = list(map(int, input().split()))
  if x not in lis:
    print(x)
  else:
    y = x + 1
    z = x - 1
    while True:
      print(y,z)
      if y in lis and z in lis:
        y += 1
        z -= 1
      elif z not in lis:
        print(z)
        break
      elif y not in lis:
        print(y)
        break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
lis =  []
lis2 = []

if n == 0:
  print(x)
else:
  lis = list(map(int, input().split()))
  lis.sort()
  if x not in lis:
    print(x)
  else:
    y = x + 1
    z = x - 1
    while True:
      if y in lis and z in lis:
        y += 1
        z += 1
      elif z not in lis:
        print(z)
        break
      elif y not in lis:
        print(y)
        break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
lis =  []
lis2 = []

if n == 0:
  print(x)
else:
  lis = list(map(int, input().split()))
  lis.sort()
  if x not in lis:
    print(x)
  else:
    y = x + 1
    z = x - 1
    while True:
      if y in lis and z in lis:
        y += 1
        z += 1
      elif y not in lis and z not in lis:
        print(z)
        break
      elif y not in lis:
        print(y)
        break
      elif z not in lis:
        print(z)
        break

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
dic = {}
lis = []
for i in range(0,102):
    if i not in p:
        dic[i] = abs(x-i)
        lis.append(i)
print(lis)

mini = min(dic.values())
for j in lis:
    if mini == dic[j]:
        print(j)
        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()


Flag = True
i = 0
while Flag:
    if not (x - i in p):
        print(x - i)
        break
    elif not (x + i not in p):
        print(x + i)
        break
    i += 1

Submission status: Wrong Answer

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

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

Flag = True
i = 1
while Flag:
    if x - i not in p:
        print(x - i)
        break
    elif x + i not in p:
        print(x + i)
        break
    i += 1

Submission status: Wrong Answer

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

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

ans = x
for i in range(x, 101):
    if i not in p:
        ans = i
        break

ans2 = x
for i in range(x-1, -1, -1):
    if i not in p:
        ans2 = i
        break

#print(ans,ans2)
tmp1 = abs(ans - x)
tmp2 = abs(x - ans2)

if (tmp1 < tmp2):
    print(ans)
elif (tmp1 == tmp2):
    print(min(ans, ans2))
else:
    print(ans2)

Submission status: Wrong Answer

Solution code:
inp = [int(a) for a in input().split()]
X = inp[0]
N = inp[1]
if N == 0:
  print(X)
else:
  P = [int(b) for b in input().split()]

  found = 0
  num = 1
  answer = X
  while(found == 0):
    if not (X - num in P):
      found = 1
      answer = X - num
    elif not (X + num in P):
      found = 1
      answer = X + num
    num += 1
  print(answer)

Submission status: Wrong Answer

Solution code:
inp = [int(a) for a in input().split()]
X = inp[0]
N = inp[1]
if N == 0:
  print(X)
else:
  P = [int(b) for b in input().split()]

  found = 0
  num = 1
  answer = X
  while(answer == X):
    if not (X - num in P):
      answer = X - num
    elif not (X + num in P):
      answer = X + num
    num += 1
  print(answer)

Submission status: Wrong Answer

Solution code:
X = [int(a) for a in input().split()][0]
P = [int(b) for b in input().split()]

found = 0
num = 1
answer = X
while(answer == X):
  if not (X - num in P):
    answer = X - num
  elif not (X + num in P):
    answer = X + num
  num += 1
print(answer)

Submission status: Wrong Answer

Solution code:
import sys
X,N = map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
A = sorted(list(map(int,input().split())))

nl = []
a = 0
for i in range(-200,200):
  if i in A:
    a = a
  else:
    nl.append(i)
 
nnl = []
for i in nl:
  nnl.append(abs(i-X))

if X in nnl:
  print(X-1)
elif nnl.count(min(nnl)) != 2:
  print(X+min(nnl))
else:
  print(X-min(nnl))

Submission status: Wrong Answer

Solution code:
import sys
X,N = map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
A = sorted(list(map(int,input().split())))

nl = []
a = 0
for i in range(A[0]-10,A[-1]+10):
  if i in A:
    a = a
  else:
    nl.append(i)
 
nnl = []
for i in range(len(nl)):
  nnl.append(abs(nl[i]-X))

if nnl.count(min(nnl)) != 2:
  print(X+min(nnl))
else:
  print(X-min(nnl))

Submission status: Wrong Answer

Solution code:
import sys
X,N = map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
A = sorted(list(map(int,input().split())))

nl = []
a = 0
for i in range(A[0]-10,A[-1]+10):
  if i in A:
    a = a
  else:
    nl.append(i)
 
nnl = []
for i in range(len(nl)):
  nnl.append(abs(nl[i]-X))

if nnl.count(min(nnl)) == 2:
  print(X-min(nnl))
else:
  print(min(nnl)+X)

Submission status: Wrong Answer

Solution code:
import sys
X,N = map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
A = sorted(list(map(int,input().split())))

nl = []
a = 0
for i in range(A[0]-1,A[-1]+2):
  if i in A:
    a = a
  else:
    nl.append(i)
 
nnl = []
for i in range(len(nl)):
  nnl.append(abs(nl[i]-X))

if nnl.count(min(nnl)) == 2:
  print(X-min(nnl))
else:
  print(min(nnl)+X)

Submission status: Wrong Answer

Solution code:
import sys
X,N = map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
A = sorted(list(map(int,input().split())))

nl = []
a = 0
for i in range(A[0]-1,A[-1]+2):
  if i in A:
    a = a
  else:
    nl.append(i)
 
nnl = []
for i in range(len(nl)):
  nnl.append(abs(nl[i]-X))
  
print(min(nnl)+X)

Submission status: Wrong Answer

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

candidates = []

x = X
while(True):
    if not x in p:
        candidates.append(x)
        break
    else:
        x += 1
x = X
while(True):
    if not x in p:
        candidates.append(x)
        break
    else:
        x -= 1

print(min(candidates))

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)
p = list(map(int, input().split()))
a = [i for i in range(101)]
b = sorted(list(set(a) - set(p)))
min_v = 1000
min_id = 0
for i in range(len(b)):
  if abs(x - b[i]) < min_v:
    min_v = abs(x - b[i])
    min_id = i
print(b[min_id])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)
p = list(map(int, input().split()))
a = [i for i in range(101)]
b = sorted(list(set(a) - set(p)))
print(b)
min_v = 1000
min_id = 0
for i in range(len(b)):
  if abs(x - b[i]) < min_v:
    min_v = abs(x - b[i])
    min_id = i
print(b[min_id])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)
p = list(map(int, input().split()))
a = [i for i in range(-100,101)]
b = sorted(list(set(a) - set(p)))
min_v = 1000
min_id = 0
for i in range(len(b)):
  if abs(x - b[i]) < min_v:
    min_v = abs(x - b[i])
    min_id = i
print(b[min_id])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)
p = list(map(int, input().split()))
a = [i for i in range(-100,101)]
b = sorted(list(set(a) - set(p)))
min = 1000
min_id = 0
for i in range(len(b)):
  if abs(x - b[i]) < min:
    min = abs(x - b[i])
    min_id = i
print(b[min_id])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)
p = list(map(int, input().split()))
a = [i for i in range(-102,101)]
b = sorted(list(set(a) - set(p)))
for i in range(len(b)):
  if x <= b[i]:
    if abs(b[i-1]-x) <= abs(b[i]-x):
      print(b[i-1])
      exit(0)
    else:
      print(b[i])
      exit(0)
print(b[-1])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)
p = list(map(int, input().split()))
a = [i for i in range(-100,101)]
b = sorted(list(set(a) - set(p)))
for i in range(1,len(b)):
  if x <= b[i]:
    if abs(b[i-1]-x) <= abs(b[i]-x):
      print(b[i-1])
      exit(0)
    else:
      print(b[i])
      exit(0)
print(b[-1])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)
p = list(map(int, input().split()))
a = [i for i in range(1,101)]
b = list(set(a) - set(p))
for i in range(len(b)):
  if x < b[i]:
    if abs(b[i-1]-x) <= abs(b[i]-x):
      print(b[i-1])
      break
    else:
      print(b[i])
      break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dist = 0

if N == 0:
    print(X)
    dist_max = -1
else:
    dist_max = max(abs(max(p) - X), abs(min(p) - X))

while dist <= dist_max + 1:
    if (X - dist in p) and (X + dist in p):
        dist += 1
        continue

    if not (X - dist in p):
        print(X - dist)
        break
    elif not (X + dist in p):
        print(X + dist)
        break

Submission status: Wrong Answer

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

dist = 0

if N == 0:
    print(X)
    dist_max = -1
else:
    dist_max = max(abs(max(p) - X), abs(min(p) - X))

while dist <= dist_max:

    if (X - dist in p) and (X + dist in p):
        dist += 1
        continue

    if not (X - dist in p):
        print(X - dist)
        break
    elif not (X + dist in p):
        print(X + dist)
        break

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N>0:
  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:
  print(X)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
xp =x; xm =x
for i in range(n):
    if not (xm in p):
        print(xm)
        break
    if not (xp in p):
        print(xp)
        break
    xp += 1
    xm -= 1

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
xp =x; xm =x
for i in range(6):
    if not (xm in p):
        print(xm)
        break
    if not (xp in p):
        print(xp)
        break
    xp += 1
    xm -= 1

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N>0:
  P=list(map(int,input().split()))
  L=[abs(X-i) for i in P]
  l=min(L)
  if X-l in P:
    print(X-l)
  else:
    print(X+l)
else:
  print(X)

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split(' '))
if n == 0:
    print(x)
    exit()
else:
    li = list(map(int, input().split(' ')))
small, large = min(li), max(li)
res = 10000000
for i in range(small, large+1):
    if i not in li:
        if abs(i-x) < res:
            res = abs(i-x)
if (x-res) not in li:
    print(x-res)
else:
    print(x+res)

Submission status: Wrong Answer

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

for i in range(N):
    if not (X-i in p):
        print(X-i)
    elif not (X+i in p):
         print(X+i)

Submission status: Wrong Answer

Solution code:
def Judge():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))
    if N == 0:
        return X
    for i in range(1,N):
        if not (X-i in p):
            return (X-i)
        elif not (X+i in p):
            return (X+i)

print(Judge())

Submission status: Wrong Answer

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

ne = [i for i in range(-200, 200) if i not in p]
a = []
ans = 100
for i in range(len(ne)):
    b = abs(ne[i]-x)
    if b <= ans:
        a.append(ne[i])
        ans = b
print(a[-1])

Submission status: Wrong Answer

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

ne = [i for i in range(-101, 101) if i not in p]
a = []
ans = 100
for i in range(len(ne)):
    b = abs(ne[i]-x)
    if b <= ans:
        a.append(ne[i])
        ans = b
print(a[-1])

Submission status: Wrong Answer

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

ne = [i for i in range(101) if i not in p]
a = []
ans = 100
for i in range(len(ne)):
    b = abs(ne[i]-x)
    if b <= ans:
        a.append(ne[i])
        ans = b
print(a[-1])

Submission status: Wrong Answer

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

ne = [i for i in range(101) if i not in p]
a = []
ans = 100
for i in range(len(ne)):
    b = abs(ne[i]-x)
    if b < ans:
        a.append(ne[i])
        ans = min(b, ans)
print(a[-1])

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
if n > 0:
	l = list(map(int,input().split()))
else:
	l = []
tl = []
for i in range(0,101):
	if i not in l:
		tl.append(i)
tlabs = []
for i in tl:
	tlabs.append(abs(x - i))
ans = tl[tlabs.index(min(tlabs))]
print(ans)

Submission status: Wrong Answer

Solution code:
l=input()
ls=l.split(" ")
X=int(ls[0])
N=int(ls[1])
lstr=input()
lst=lstr.split(" ")
fl=[]
if(N!=0):
    for a in lst:
         fl.append(int(a))
else:
    print(X)
for a in range(len(fl)):
    if(X-a not in fl):
         print(X-a)
         break
    if(X+a not in fl):
         print(X+a)
         break

Submission status: Wrong Answer

Solution code:
l=input()
ls=l.split(" ")
X=int(ls[0])
N=int(ls[1])
lstr=input()
lst=lstr.split(" ")
fl=[]
if(lstr!=""):
    for a in lst:
         fl.append(int(a))
else:
    print(X)
for a in range(len(fl)):
    if(X-a not in fl):
         print(X-a)
         break
    if(X+a not in fl):
         print(X+a)
         break

Submission status: Wrong Answer

Solution code:
l=input()
ls=l.split(" ")
X=int(ls[0])
N=int(ls[1])
lstr=input()
lst=lstr.split(" ")
fl=[];
if(fl!=[]):
    for a in lst:
         fl.append(int(a))
else:
    print(X)
for a in range(len(fl)):
    if(X-a not in fl):
         print(X-a)
         break
    if(X+a not in fl):
         print(X+a)
         break

Submission status: Wrong Answer

Solution code:
import sys
x,n = map(int,input().split())
if n == 0:
    print(x)
    sys.exit(0)
    
p = list(map(int,input().split()))
p.sort()
a = []
j = 0
for i in range(n):
    while (j < p[i]):
        a.append(j)
        j += 1 
    j += 1
for i in range(j,101):
    a.append(j)
    j += 1 

#print(a)
def solve(a,x):
    if x < a[0]:
        if a[0] - x < x - 0:
            print(a[0])
        else:
            print(0)
        return
    if x > a[-1]:
        if x - a[-1] <= 101 - x:
            print(a[-1])
        else:
            print(101)
        return
    if (binary_search(a,x)):
        mid = binary_search(a,x) - 2
        minimum = abs(a[mid] - x)
        index = mid
        for i in range(1,5):
            #print(a[mid + i])
            if mid + i >= len(a):
                break
            if abs(a[mid + i] - x) < minimum:
                index = mid + i 
                minimum = abs(a[mid + i] - x)
        print(a[index])
        return
    

def binary_search(a,x):
    left = 0
    right = len(a)
    while (left + 1 < right):
        mid = (left + right)//2
        if x == a[mid]:
            print(a[mid])
            return 
        elif x < a[mid]:
            right = mid 
        else:
            left = mid + 1
    return mid 

solve(a,x)

Submission status: Wrong Answer

Solution code:
import sys
x,n = map(int,input().split())
if n == 0:
    print(x)
    sys.exit(0)
    
p = list(map(int,input().split()))
p.sort()
a = []
j = 0
for i in range(n):
    while (j < p[i]):
        a.append(j)
        j += 1 
    j += 1
for i in range(j,101):
    a.append(j)
    j += 1 

#print(a)
def solve(a,x):
    if x < a[0]:
        print(a[0])
        return
    if x > a[-1]:
        if x - a[-1] <= 101 - x:
            print(a[-1])
        else:
            print(101)
        return
    if (binary_search(a,x)):
        mid = binary_search(a,x) - 2
        minimum = abs(a[mid] - x)
        index = mid
        for i in range(1,5):
            #print(a[mid + i])
            if mid + i >= len(a):
                break
            if abs(a[mid + i] - x) < minimum:
                index = mid + i 
                minimum = abs(a[mid + i] - x)
        print(a[index])
        return
    

def binary_search(a,x):
    left = 0
    right = len(a)
    while (left + 1 < right):
        mid = (left + right)//2
        if x == a[mid]:
            print(a[mid])
            return 
        elif x < a[mid]:
            right = mid 
        else:
            left = mid + 1
    return mid 

solve(a,x)

Submission status: Wrong Answer

Solution code:
import bisect

X,N = (int(x) for x in input().split())
P = list(map(int, input().split()))
ALL = list(int(i) for i in range(0,101))
P.sort()
Q = list(set(P)^set(ALL))
number = bisect.bisect(Q,X)

if number==0:
  print(Q[0])
elif number==len(Q):
  print(Q[len(Q)-1])
elif X-Q[number-1]<=Q[number]-X:
  print(Q[number-1])
elif X-Q[number-1]>Q[number]-X:
  print(Q[number])

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def main():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return 0
    p_list = list(map(int, input().split()))
    
    ans = X
    i = 1
    while True:
        tmp_n = X - i
        if tmp_n not in p_list:
            ans = tmp_n
            break
        tmp_p = X + i
        if tmp_p not in p_list:
            ans = tmp_p
            break
        i += 1        
    
    print(ans)

main()

Submission status: Wrong Answer

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


if N == 0:
    print(X)

for i in range(102):
    if X - i not in p:
        print(X - i)
        exit()
    
    if X + i not in p:
        print(X + i)
        exit()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split(' '))
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    P_ls.sort(reverse=True)
    diff = -1
    for i in range(100, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X-i):
                    rst = i
    print(rst)

Submission status: Wrong Answer

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

def f(x):
    i = 0
    while i <= 100:
        if x-i not in p and x-i >= 0:
            return x-i
        elif x+i not in p and x+i <= 100:
            return x+i
        i += 1

print(x if n==0 else f(x))

Submission status: Wrong Answer

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

def f(x):
    i = 0
    while 1:
        if x-i not in p and x-i >= 0:
            return x-i
        elif x+i not in p and x+i <= 100:
            return x+i
        i += 1

print(x if n==0 else f(x))

Submission status: Wrong Answer

Solution code:
X,N,*P = map(int,open(0).read().split())
if P != []:
  P = sorted(list(P),reverse=True)
else:
  print(X)
  exit()

min_diff = 101
min_val = 101

if N == 100:
  if X <=50:
    ans = 0
  else:
    ans = 101
else:
  for i in range(100,-1,-1):
    #print(i,min_val,min_val)
    if not i in P:
      if abs(X-i) <= min_diff and min_val >i:
      	min_diff = abs(X-i)
      	min_val = i
  ans = min_val
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int,input().split())
li = set(list(map(int,input().split())))
li = list(set(range(101)) - li)

li.sort(reverse=True)
n = 101

for i in li:
    m = abs(X - i)
    if m <= n:
        n = m
        k = i
print(k)

Submission status: Wrong Answer

Solution code:
def calc():
    x, n = list(map(int, input().split(" ")))
    p = map(int, input().split(" "))
    if n == 0: return x
    p = list(p)
    data = [i for i in list(range(0, 101)) if i not in p]
    # print(p)
    print("data", data)

    absd = [abs(x-i) for i in data]
    # print(absd)

    return (data[absd.index(min(absd))])

print(calc())

Submission status: Wrong Answer

Solution code:
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
x,n = MI()
if n == 0:
  print(x)
else:
  p = set(LI())
  li = set(range(0,101))
  new_li = li - p
  x_dis = []
  for k in new_li:
    x_dis.append(abs(k-x))
  ind = x_dis.index(min(x_dis))
  print(list(new_li)[ind])

Submission status: Wrong Answer

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

abs_list = []

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

for i in range(1,150):
    j,k = abs(X - i), X +i
    if j not in P:
        print(j)
        break
    if k not in P:
        print(k)
        break

Submission status: Wrong Answer

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

abs_list = []

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

for i in range(1,100):
    j,k = X - i, X +i
    if j not in P:
        print(j)
        break
    if k not in P:
        print(k)
        break

Submission status: Wrong Answer

Solution code:
import sys
x,n = map(int,input().split())
p = list(map(int,input().split()))
s = 100
min_i = -1

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

for i in range(1,102):
    if i not in p and abs(i-x) < s:
        s = abs(i-x)
        min_i = i

        
print(min_i)

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()))
    s = 100
    min_i = -1


    for i in range(-1,102):
        if i not in p and i == x:
            print(i)
            break
        elif i not in p and abs(i-x) < s:
            s = abs(i-x)
            min_i = i

        
    print(min_i)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
elif n == 100:
    print('')
else:
    p = list(map(int,input().split()))
    s = 100
    min_i = -1


    for i in range(0,101):
        if i not in p and i == x:
            print(i)
            break
        elif i not in p and abs(i-x) < s:
            s = abs(i-x)
            min_i = i

        
    print(min_i)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
elif n == 100:
    print('')
else:
    p = list(map(int,input().split()))
    s = 100
    min_i = 0


    for i in range(1,101):
        if i not in p and i == x:
            print(i)
            break
        elif i not in p and abs(i-x) < s:
            s = abs(i-x)
            min_i = i

        
    print(min_i)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    p = list(map(int,input().split()))
    s = 100
    min_i = 0


    for i in range(1,101):
        if i not in p and i == x:
            print(i)
            break
        elif i not in p and abs(i-x) < s:
            s = abs(i-x)
            min_i = i

        
    print(min_i)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    p = list(map(int,input().split()))
    s = 100
    min_i = 0


    for i in range(1,101):
        if i not in p and abs(i-x) < s:
            s = abs(i-x)
            min_i = i
        
    print(min_i)

Submission status: Wrong Answer

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

diff = 999
ans = 0

for i in range(-101, 101):
    if i not in p and diff > abs(x-i):
        diff = min(diff, abs(x-i))
        ans = i

print(ans)

Submission status: Wrong Answer

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

diff = 999
ans = 0

for i in range(101):
    if i not in p and i != x and diff > abs(x-i):
        diff = min(diff, abs(x-i))
        ans = i

print(ans)

Submission status: Wrong Answer

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

diff = 999
ans = 0

for i in range(-101, 101):
    if i not in p and i != x and diff > abs(x-i):
        diff = min(diff, abs(x-i))
        ans = i

print(ans)

Submission status: Wrong Answer

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

diff = 100
ans = 0

for i in range(101):
    if i not in p and diff > abs(x-i):
        diff = min(diff, abs(x-i))
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
X,N=[int(x) for x in input().split(" ")]
if N==0: 
    a=input()
    print(X)
else:
    a=[int(x) for x in input().split(" ")]
    i=1
    res=0
    if not X in a:
        res=X
    while True:
        X+=i*(-1)**i
        if not X in a:
            res=X
            break
        i+=1
    print(res)