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:
xn = input().split()
x = int(xn[0]) #これに近い値

try:
    data_str = input().split()
    data_2 = []
    data = [int(s) for s in data_str] #data_strをint型に変換
    data.sort() #小さい順
    #dataにない値が出るまでxから１引き続ける　１引き続けた値をaとする
    a = x-1
    #check
    while True: #while1
        while True: #while2
            for i in range(len(data)):
                if data[i] != a:
                    continue
                else:
                    a -= 1
                    break #forから抜け出す
            else:
                data_2.append(a)
                break #while2から抜け出す

        if len(data_2) == 1: #リストに１つデータが入っていたら　入ってないならwhile1ループ
            break #while1から抜け出す    


    #dataにない値が出るまでxかに１を足し続ける　１足し続けた値をbとする
    b = x + 1
    while True: #while1
        while True: #while2
            for i in range(len(data)):
                if data[i] != b:
                    continue
                else:
                    b += 1
                    break #forから抜け出す
            else:
                data_2.append(b)
                break #while2から抜け出す

        if len(data_2) == 2: #リストに2つデータが入っていたら　入ってないならwhile1ループ
            break #while1から抜け出す  


    #aとbの小さい方をprint
    if abs(x-a) <= abs(b-x):
        print(a)
    else:
        print(b)
except:
    print(x)

Submission status: Wrong Answer

Solution code:
xn=input().split()
x=int(xn[0])

data=input().split()
for i in range(100):
    for d in data:
        if int(d) == x-i:
            break
    else:
        print(x-i)
        break
    
    for d in data:
        if int(d) != x+i:
            break
    else:
        print(x+i)
        break

Submission status: Wrong Answer

Solution code:
xn=input().split()
x=int(xn[0])
n=int(xn[1])

data=input().split()
for i in range(100):
    for d in data:
        if int(d) != x-i:
            print(int(d))
            break
        elif int(d) != x+i:
            print(int(d))
            break
    else:
        continue
    break

Submission status: Wrong Answer

Solution code:
xn=input().split()
x=int(xn[0])
n=int(xn[1])

data=input().split()
for i in range(100):
    for d in data:
        if int(d) == x-i:
            print(int(d))
            break
        elif int(d) == x+i:
            print(int(d))
            break
    else:
        continue
    break

Submission status: Wrong Answer

Solution code:
def forbidden_list():
    # 入力
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    # 初期処理
    min_abs = list()
    # N = 0 の場合
    if N == 0:
        return X
    # X + i
    i = 1
    while True:
        if X + i in P:
            i += 1
        else:
            min_abs.append(X + i)
            break
    # X - i
    i = -1
    while True:
        if X + i in P:
            i -= 1
        else:
            min_abs.append(X + i)
            break
    # 複数整数から最小を求める
    return min(min_abs)

result = forbidden_list()
print(result)

Submission status: Wrong Answer

Solution code:
def forbidden_list():
    # 入力
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    # 初期処理
    min_abs = list()
    # N = 0 の場合
    if N == 0:
        return X
    # X + i
    i = 1
    while True:
        if X + i in P:
            i += 1
        else:
            min_abs.append(X + i)
            break
    # X - i
    i = 1
    while True:
        if X - i in P:
            i -= 1
        else:
            min_abs.append(X - i)
            break
    # 複数整数から最小を求める
    return min(min_abs)

result = forbidden_list()
print(result)

Submission status: Wrong Answer

Solution code:
xn=input().split()
x=int(xn[0])
n=int(xn[1])

data=input().split()
for i in range(100):
    for d in data:
        if int(d) == x-i:
            print(d)
            break
        elif int(d) == x+i:
            print(d)
            break
    break

Submission status: Wrong Answer

Solution code:
xn=input().split()
x=int(xn[0])
n=int(xn[1])

data=input().split()
for i in range(100):
    for d in data:
        if d == x-i:
            print(d)
            break
        elif d == x+i:
            print(d)
            break
    break

Submission status: Wrong Answer

Solution code:
xn=input().split()
x=int(xn[0])
n=int(xn[1])

data=input().split()
for i in range(100):
    for d in data:
        if d == x-i:
            print(d)
            break
        elif d == x+i:
            print(d)
            break

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)]
P = list(set(Q) - set(P))
P.sort()
dif = 100
for p in P:
    if abs(X-p) < dif:
        dif = abs(X-p)
        ans = p
print(ans)

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)]
P = list(set(Q) - set(P))
dif = 100
for p in P:
    if abs(X-p) < dif:
        dif = abs(X-p)
        ans = p
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

exist_P = defaultdict(int)

for p in P:
    exist_P[p] = 1

diff = X + 1
ans = -1
for i in range(0, 101):
    if exist_P[i] == 0:
        if abs(X - i) < diff:
            ans = i
            diff = abs(X - i)
print(ans)

Submission status: Wrong Answer

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

p.sort()

arr = [False] * 101

for i in range(len(p)):
    arr[p[i]] = True

dist = 10*10

ans = -99

search = list(range(-100,101))
search.reverse()

for i in search:
    if arr[i] == False:
        dist = min(abs(x - i), dist)
        if dist == 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()))

p.sort()

arr = [False] * 101

for i in range(len(p)):
    arr[p[i]] = True

dist = 10*10

ans = -99

search = list(range(101))
search.reverse()

for i in search:
    if arr[i] == False:
        dist = min(abs(x - i), dist)
        if dist == abs(x - i):
            ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=set(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:
import sys
X, N = map(int, input().split())
if N==0:
    tmp = input()
    print(X)
    sys.exit(0)

p = list(map(int, input().split()))
tmp = 10**9
ans = 0
for i in range(-1, 101):
    if i not in p:
        if tmp > abs(i-X):
            ans = i
            tmp = abs(i-X)
print(ans)

Submission status: Wrong Answer

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

ans = X
for i in range(N):
    if not X - i in p:
        ans = X - i
        break
    elif not X + i in p:
        ans = X + i
        break
    else:
        continue

print(ans)

Submission status: Wrong Answer

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

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

  for i in range(100):
    if x-i not in a:
      ans=x-1
      break
    elif x+i not in a:
      ans=x+i
      break
    
  print(ans)

Submission status: Wrong Answer

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

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

  for i in range(100):
    if x-i not in a:
      ans=x-1
      break
    if x+i not in a:
      ans=x+i
      break
    
  print(ans)

Submission status: Wrong Answer

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

for i in range(102):
  if x-i not in a:
    ans=x-1
    break
  if x+i not in a:
    ans=x+i
    break
    
print(ans)

Submission status: Wrong Answer

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

for i in range(100):
  if x-i not in a:
    ans=x-1
    break
  if x+i not in a:
    ans=x+i
    break
    
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
xhigh=0
xlow=0
if n==0:
    ans = x
else:
    if x not in p:
        ans=x
    else:
        xhigh=x+1
        xlow=x-1
        if xhigh in p and xlow in p:
            xhigh +=1
            xlow -=1
        else:
            if xlow in p:
                ans =xhigh
            else:
                ans = xlow
print(ans)

Submission status: Wrong Answer

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

P = set(P)

diff = float('INF')
ans = None
for i in range(-100, 101):
    if i in P:
        continue
    d = abs(X - i)
    if d < diff:
        diff = d
        ans = i

print(ans)

Submission status: Wrong Answer

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

a = set()
for i in range(-100, 101):
    a.add(i)
for v in p:
    a.remove(v)
a = list(a)
b = list(map(lambda v: abs(v - x), a))
print(a[b.index(min(b))])

Submission status: Wrong Answer

Solution code:
import sys



def check_number(p,numbers):
  for plis in p:
    if plis == numbers:
      return 1
  return 0


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

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


after_ans = X
i = 100


for i in range(X+1,X+100,1):#前半
  if check_number(p,i) == 0:
    after_ans = i
    after_abs = abs(X-i)
    break

for i in range(X-1,X-100,-1):#後半
  if check_number(p,i) == 0:
    before_ans = i
    before_abs = abs(X-i)
    break

if abs(after_abs) == abs(before_abs):
  answer = before_ans
elif abs(after_abs) > abs(before_abs):
  answer = before_ans
else:
  answer = after_ans

print( answer )

Submission status: Wrong Answer

Solution code:
T = list(map(int, input().split()))
S = list(map(int, input().split()))

X = T[0]
N = T[1]

cntup = X
cntdown = X
if N == 0:
    print(X)

for i in range(1,100):
    if cntup in S and cntdown in S:
        cntup += 1
        cntdown -=1
    elif cntup not in S and cntdown not in S:
        print(min(cntup,cntdown))
        break
    elif cntup in S and cntdown not in S:
        print(cntdown)
        break
    elif cntup not in S and cntdown in S:
        print(cntup)
        break

Submission status: Wrong Answer

Solution code:
T = list(map(int, input().split()))
S = list(map(int, input().split()))

X = T[0]
N = T[1]

cntup = X
cntdown = X
if N == 0:
    print(X)

for i in range(1,100):
    if cntup in S and cntdown in S:
        cntup += 1
        cntdown -=1
    elif cntup in S and cntdown not in S:
        print(cntdown)
        break
    elif cntup not in S and cntdown in S:
        print(cntup)
        break

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n,m=map(int,input().split())
a=list(map(int,input().split()))
if len(a)==0:
  print(n)
else:
  a.sort()
  if n not in a:
    print(n)
  else:
    cnt=0
    for i in range(101):
      if i in a:
        continue
      elif abs(cnt-n)>abs(i-n):
        cnt=i
    print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n,m=map(int,input().split())
a=list(map(int,input().split()))
if len(a)==0:
  print(n)
else:
  a.sort()
  if n not in a:
    print(n)
  else:
    cnt=0
    for i in range(100):
      if i in a:
        continue
      elif abs(cnt-n)>abs(i-n):
        cnt=i
    print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n,m=map(int,input().split())
a=list(map(int,input().split()))
if len(a)==0:
  print(n)
else:
  a.sort()
  if n not in a:
    print(n)
  else:
    cnt=0
    for i in range(100):
      if i in a:
        continue
      elif abs(cnt-n)>abs(i-n):
        cnt=i
      if cnt>n:
          break
    print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n,m=map(int,input().split())
a=list(map(int,input().split()))
if len(a)==0:
  print(n)
else:
  a.sort()
  if n not in a:
    print(n)
  else:
    cnt=0
    for i in range(100):
      if i in a:
        continue
      else:
        cnt=i
      if cnt>n:
          break
    print(cnt)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
if len(a)==0:
  print(n)
else:
  a.sort()
  if n not in a:
    print(n)
  else:
    cnt=0
    for i in range(n):
      if i in a:
        continue
      else:
        cnt=i
    print(cnt)

Submission status: Wrong Answer

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

    p.sort()

    if len(p) == 0:
        print(x)
        return

    diff_min = 1000
    min_n = 1000
    for _ in range(0, 101):
        diff = abs(_ - x)
        if diff < diff_min:
            if _ not in p:
                diff_min = diff
                min_n = _

    print(min_n)


main()

Submission status: Wrong Answer

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

    p.sort()

    if len(p) == 0:
        print(x)
        return

    diff_min = 1000
    min_n = 1000
    for _ in range(1, 101):
        diff = abs(_ - x)
        if diff < diff_min:
            if _ < p[0] or p[n-1] < _ or _ not in p:
                diff_min = diff
                min_n = _

    print(min_n)


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

temp = -1
for i in range(101):
  if(temp == -1):
    if(i not in p_list):
      temp = abs(X - i)
      ans = i
  elif(temp > abs(X-i) and i not in p_list):
   temp = 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()))

if n == 0:
    ans = x
else:
    ans = float('inf')

d = float('inf')

for i in range(n+1):
    tmpx = x + 1 + n//2 - i
    if not tmpx in p:
        tmpd = abs(x -tmpx) 
        if d >= tmpd:
            d = tmpd
            if ans >= tmpx:
                ans = tmpx

print(ans)

Submission status: Wrong Answer

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

if n == 0:
    ans = x

d = float('inf')

for i in range(n+1):
    tmpx = x + 1 + n//2 - i
    if not tmpx in p:
        tmpd = abs(x -tmpx) 
        if d >= tmpd:
            d = tmpd
            ans = tmpx

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

X, N = LI()
P = LI()
# u = X
# d = X
# Pに含まれない整数（負も含まれる）で最もXに近くて最小の値を探す

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

elif (N != 0) and (X not in P):
    print(X)
    sys.exit()

else:
    for i in range(N):
        a = (-1) ** i
        X = X + i * a

        if X not in P:
            print(X)
            sys.exit()

Submission status: Wrong Answer

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

if N != 0:
    if X in p:
        sorted_p = sorted(p)

        x = p.index(X)
            
        def checknum(d,loweridx,upperidx):
            upper = sorted_p[upperidx]
            lower = sorted_p[loweridx]
            if X-d == lower:
                if X+d == upper:
                    if loweridx == 0:
                        print(X-d-1)
                    elif upperidx == N-1 and sorted_p[loweridx-1] == X-d-1:
                        print(X+d+1)
                    else:
                        checknum(d+1,loweridx-1,upperidx+1)
                else:
                    print(X+d)        
            else:
                return print(X-d)

        if x == 0:
            print(X-1)
        elif x == N-1:
            if sorted_p[x-1] != X-1:
                print(X-1)
            else:
                print(X+1)
        else:
            checknum(1,x-1,x+1)
    else:
        print(X)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
l = list(map(int,input().split()))
s = set(l)
o = []
d = {}
for i in range(-101,101):
    if i not in s:
        g = abs(i-x)
        o.append(g)
        if g in d:
            h = d[g]
            h.append(i)
            d[g] = h

        else:
            d[g] = [i]

o.sort()
k = o[0]
n = d[k]
n.sort()
print(n[0])

Submission status: Wrong Answer

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

if N != 0:
    if X in p:
        sorted_p = sorted(p)

        x = p.index(X)
            
        def checknum(d,loweridx,upperidx):
            upper = sorted_p[upperidx]
            lower = sorted_p[loweridx]
            if X-d == lower:
                if X+d == upper:
                    if loweridx == 0:
                        print(X-d-1)
                    elif upperidx == N-1:
                        a=1
                        while(sorted_p[loweridx-a] == X-d):
                            a += 1
                        if sorted_p[loweridx-a] == X-d-1:
                            print(X+d+1)
                        else:
                            print(X-d-1)
                    else:
                        checknum(d+1,loweridx-1,upperidx+1)
                elif X-d == lower and X+d != upper:
                    print(X+d)        
            else:
                return print(X-d)

        if x == 0:
            print(X-1)
        elif x == N-1:
            a=1
            while(sorted_p[x-a] == X):
                a += 1
            if sorted_p[x-a] != X-1:
                print(X-1)
            else:
                print(X+1)
        else:
            checknum(1,x-1,x+1)
    else:
        print(X)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
x, n = map(int, input().split())
if n != 0:
    P = list(map(int, input().split()))
    P = sorted(P)
else:
    P = []

flag = False
ans = []
if x not in P or n == 0:
    ans.append(x)
elif n == 100:
    ans.append(0)
else:
    idx = bisect_left(P, x)
    for i in range(1, 110):
        for_num = P[idx] + i
        bac_num = P[idx] - i
        if for_num not in P:
            ans.append(for_num)
            flag = True
        if bac_num not in P:
            ans.append(bac_num)
            flag = True
        if flag:
            break

print(min(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()))
pp = list(set(sorted([i - x for i in p if i-x > 0])))
pm = list(set(sorted([abs(i - x) for i in p if i - x < 0])))
pp.append(9999)
pm.append(9999)
if (1 == 1):
    pass
else:
    print(x)
    exit()
a = 1
i = 0
while 1:
    if (pm[i] != a):
        print(x - a)
        exit()
    if(pp[i] != a):
        print(x + a)
        exit()
    a += 1
    i += 1

Submission status: Wrong Answer

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

k = 1
while(True):
    if not x-k in a:
        print(x-k)
        quit()
    if not x+k in a:
        print(x+k)
        quit()
    k += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
a = list(map(int,input().split()))
if x == n:
    print(x)
    quit()
k = 1
while(True):
    if not x-k in a:
        print(x-k)
        quit()
    if not x+k in a:
        print(x+k)
        quit()
    k += 1

Submission status: Wrong Answer

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

min_num = None
max_num = None

for i in range(x,-1000, -1):
  if i not in p:
    min_num = i
    break
    
for i in range(x, 1000):
  if i not in p:
    max_num = i
    break
    
print(abs(max_num -x ) , abs(min_num -x ))
if abs(max_num -x ) >=abs(min_num -x ):
  print(min_num)
else :
  print(max_num)

Submission status: Wrong Answer

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

i = 0
ans = []
flag = 0
while True:
    if (x + i) not in p:
        ans += [x+i]
        print(ans)
        flag = 1
    if (x - i) not in p:
        ans += [x-i]
        print(ans)
        flag = 1
    if flag == 0:
        i += 1
        print(ans)
    else:
        break

print(min(ans))

Submission status: Wrong Answer

Solution code:
def c170(x, n, plist):

    for i in range(n):
        if x-i not in plist:
            return x-i
        elif x+i not in plist:
            return x+i

def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    plist = list(map(int, input().split()))
    print(c170(x, n, plist))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans_i = 0
for i in range(N):
    if X-i not in p or X+i not in p:
        ans_i = i
        break

if X-ans_i not in p:
    print(X-ans_i)
elif X+i not in p:
    print(X+ans_i)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=set(map(int,input().split()))
tmp=1000000
ans=0
for i in range(1,110):
    if i not in p:
        if tmp>abs(i-x):
            ans=i
            tmp=abs(i-x)
print(ans)

Submission status: Wrong Answer

Solution code:

x,n = map(int,input().split())
if n == 0:
  print(x)
else:
  ps= set(map(int,input().split()))
  diff = 0
  while(True):
    diff +=1
    if x-diff not in ps:
      print(x -diff)
      break
    elif x + diff not in ps:
      print(x + diff)
      break

Submission status: Wrong Answer

Solution code:
n = input().split()
X, LEN = list(map(int, n))

nn = input().split()
nums = list(map(int, nn))

# print(X, LEN, nums)

# 近似値の探索
pos = X
neg = X
result = X

while True:
    if (len(nums) <= 0):
        break

    neg -= 1
    pos += 1

    if (not neg in nums):
        result = neg
        break
    if (not pos in nums):
        result = pos
        break
print(result)

Submission status: Wrong Answer

Solution code:
n = input().split()
X, LEN = list(map(int, n))

nn = input().split()
nums = list(map(int, nn))

# print(X, LEN, nums)

# 近似値の探索
pos = X
neg = X
result = X

while True:
    if (len(nums) <= 0):
        break

    pos += 1
    neg -= 1

    if (not neg in nums):
        result = neg
        break
    if (not pos in nums):
        result = pos
        break
print(result)

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()))
L=[]
A=[]
A_1=[]
for i in range(-100,200):
  L.append(i)
for i in P:
  L[i+100]=200
for i in L:
  A.append(abs(X-i))
A_1=sorted(A)
a=A_1[0]
for i in L:
  if i==X-a:
    print(i)
    sys.exit()
  elif i==X+a:
    print(X+a)
    break
print(a)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
P=list(map(int,input().split()))
Q=[-1,0]
for i in range(1,101):
    if i not in P:
        Q.append(i)
ans=10**9
A=[]
for i,q in enumerate(Q):
    A.append([i,abs(q-x)])
A.sort(key=lambda x:(x[1],x[0]))
print(Q[A[0][0]])

Submission status: Wrong Answer

Solution code:
import bisect
x,n=map(int,input().split())
P=list(map(int,input().split()))
Q=[-1,0]
for i in range(1,101):
    if i not in P:
        Q.append(i)
ans=10**9
A=[]
for i,q in enumerate(Q):
    A.append([i,abs(q-x)])
A.sort(key=lambda x: x[1])
print(Q[A[0][0]])

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n+1):
	for x in [1,-1]:
		y = n + x*i
		if y not in a:
			print(y)
			exit(0)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
li = []
if n != 0:
  li = list(map(int,input().split()))
answer = -10000
for i in range(1, 101):
  if (i in li):
    continue
  if abs(i-x) < abs(answer - x):
    answer = i
print(answer)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
li = []
if n != 0:
  li = list(map(int,input().split()))
answer = -10000
for i in range(0, 101):
  if (i in li):
    continue
  if abs(i-x) < abs(answer - x):
    answer = i
print(answer)

Submission status: Wrong Answer

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

ls = [0] * 101
for i in range(0, 101):
    ls[i] = i

ls_in = [0] * n
if n > 0:
    ls_in = list(map(int, input().split(' ')))
    for i in ls_in:
        ls.remove(i)
    ls.reverse()
    for i in ls:
        min_num = min(abs(x-i), min_num)
        if abs(x-i) == min_num:
            ans = i 
    print(ans)
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()))
    cnt = 0
    if x in p:
        print(x)
    else:
        while True:
            cnt += 1
            if x - cnt not in p:
                print(x - cnt)
                break
            if x + cnt not in p:
                print(x + cnt)
                break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# 考えたポイント
# 答えはあることを理解する
# 絶対値のうち最小
# 0, 101の扱い
# countを使う
for i in range(1,X+1):
    for s in [-1,1]:
        ans = X + (i * s)
        if P.count(ans) == 0:
            print(ans)
            exit(0)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans = 1000
ans_abs = 10000
for i in reversed(range(1, 101)):
    inP = False
    for p in P:
        if p == i:
            inP = True
            break
    if not inP:
        i_abs = abs(i - X)
        if ans_abs >= i_abs:
            ans = i
            ans_abs = i_abs

print(ans)

Submission status: Wrong Answer

Solution code:
x,n = list(map(int,input().split()))
ans = 0
if n != 0:
  p_list = list(map(int,input().split()))
  for i in range(0,101):
    if i not in p_list:
      if abs(x - i) < abs(x - ans):
        ans = i
      elif abs(x - i) == abs(x - ans) and i < ans:
        ans = i
else:
  ans = x
print(ans)

Submission status: Wrong Answer

Solution code:
x,n = list(map(int,input().split()))
ans = 0
if n != 0:
  p_list = list(map(int,input().split()))
  for i in range(0,101):
    if i not in p_list:
      if abs(i - x) < abs(ans - x):
        ans = i
      elif abs(i - x) == abs(ans - x) and i < ans:
        ans = i
else:
  ans = x
print(ans)

Submission status: Wrong Answer

Solution code:
x,n = list(map(int,input().split()))
ans = 0
if n != 0:
  p_list = list(map(int,input().split()))
  for i in range(-100,101):
    if i not in p_list:
      if abs(i - x) < abs(ans - x):
        ans = i
      elif abs(i - x) == abs(ans - x) and i < ans:
        ans = i
else:
  ans = x
print(ans)

Submission status: Wrong Answer

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

x1 = x
x2 = x

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    if x not in p:
        print(x)
    while True:
        x1 -= 1
        x2 += 1
        
        if x1 not in p:
            print(x1)
            exit()
            
        if x2 not in p:
            print(x2)
            exit()

Submission status: Wrong Answer

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

x1 = x
x2 = x

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    while True:
        x1 -= 1
        x2 += 1
        
        if x1 not in p:
            print(x1)
            exit()
            
        if x2 not in p:
            print(x2)
            exit()

Submission status: Wrong Answer

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

import numpy as np

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

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

m = np.array(list(range(102)))
m = (m-x)**2
for i in (np.argsort(m)):
    if p.count(i) == 0:
        print(i)
        break

Submission status: Wrong Answer

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

import numpy as np

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

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

m = np.array(list(range(102)))
m = (m-x)**2
for i in (np.argsort(m)+1):
    if p.count(i) == 0:
        print(i)
        break

Submission status: Wrong Answer

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

import numpy as np

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

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

m = np.array(list(range(-102,202)))
m = (m-x)**2
for i in (np.argsort(m)-102):
    if p.count(i) == 0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = sorted(list(map(int, input().split())))
    ok = [i for i in range(-101, p[-1]+1) if i not in p]
    ix = np.argmin(list(map(lambda a: abs(X-a), ok)))
    print(ok[ix])