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:
    print(x)
    exit()
elif n==100:
    if abs(-1-x)<=abs(101-x):
        print(-1)
    else:
        print(101)
    exit()
List=list(map(int,input().split()))
num=list(range(0,102))
min_num=1000000000
for i in range(len(List)):
    if num.count(List[i])>=1:
        num.remove(List[i])
for i in range(len(num)):
    if (abs(num[i]-x)<abs(min_num-x)) or (abs(num[i]-x)==abs(min_num-x) and num[i]<min_num):
        min_num=num[i]
print(min_num)

Submission status: Wrong Answer

Solution code:
x , n= map(int,input().split())
p = list(map(int,input().split()))
ans = []
if n == 0:
    print(x)
else:
    for i in range(-1,101):
        if i in p:
            pass
        else:
            ans.append(i)
    sa = []
    for i in range(len(ans)):
        sa.append(abs(ans[i]-x))
    MIN=min(sa)
    for i in range(len(ans)):
        if MIN == abs(ans[i]-x):
            print(ans[i])
            break

Submission status: Wrong Answer

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

if n==0:
    print(x)
    sys.exit()
    
li = sorted(list(map(int, input().split())))
li2 = [i for i in range(1,101)]

if n == 100 and x <= 50:
    print(0)
elif n == 100 and 50 < x:
    print(101)
else:
    li3 = list(set(li2)-set(li))
    li4 = [i-x for i in li3]
    li5 = [abs(i) for i in li4]    
    print(li3[li5.index(min(li5))])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
x,n = map(int, input().split())
if n > 0:
    p = list(map(int , input().split()))
else:
    p  = []
a = list(set(list(range(1,1001))) - set(p))
values = []
for i in a:
    values = values +  [[abs(x-i), i]]
values.sort(key=lambda x: x[0])
mins = values[0][0]
b = []
for i in values:
    if i[0] > mins:
        break
    b += [i[1]]
b.sort()
print(b[0])

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p_d  = [x-int(i) for i in input().split()]
p_sorted = sorted(p_d,key= lambda x: (-x-0.1, x)[x > 0])
l = [x-k for k in range(1,101)]
l_sorted = sorted(l,key= lambda x: (-x-0.1, x)[x > 0])
for i in range(n):
    ans = l_sorted[i]
    if p_sorted[i] != ans:
        print(x-ans)
        break
if n == 0:
    print(x)

Submission status: Wrong Answer

Solution code:
X, N = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
if len(l) == 0:
    print(X)
elif X not in l:
    print(X)
else:
    for i in range(1, N):
        if X - i not in l:
            print(X - i)
            break
        elif X + i not in l:
            print(X + i)
            break

Submission status: Wrong Answer

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

import sys
X = int(X)
N = int(N)

if N ==0:
    print(X)
    sys.exit
    
n = input().split()
n = [int(s) for s in n]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

d = [0 for _ in range(-100, 101)]
for i in range(-100, 101):
    d[i] = i+1 

for i in p:
    d.remove(i)

d2 = [0 for _ in range(len(d))]
for i in range(len(d)):
    d2[i] = abs(d[i]-x)

m = 1000
for i in reversed(range(len(d2))):
    if d2[i] <= m:
        m = d2[i]
        tmpi = i 

print(d[tmpi])

Submission status: Wrong Answer

Solution code:
import math

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

if n == 0:
    print(x)

else:
    p = list(map(int, input().split()))
    ans = []

    lx = x
    mx = x

    while lx <= 100:
        lx += 1
        if lx not in p:
            ans.append(lx)
            break

    while mx >= 0:
        mx -= 1
        if mx not in p:
            ans.append(mx)
            break

    if len(ans) == 0:
        print(x)
    elif abs(x-ans[0]) < abs(x-ans[1]):
        print(ans[0])
    elif abs(x-ans[0]) == abs(x-ans[1]):
        print(min(ans))
    else:
        print(ans[1])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
mn = 10 ** 18
for i in range(-101, 101):
    if i not in p:
        if abs(x-i) < mn:
            mn = abs(x-i)
            ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
# C - Forbidden List

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

if x==100:
    print(x)
else:
    p = list(map(int, input().split()))
    for i in range(100):
        a = x-(i+1)
        if a not in p:
            print(a)
            break
        b = x+(i+1)
        if b not in p:
            print(b)
            break

Submission status: Wrong Answer

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

num = [0]
for i in range(100):
  num.append(i + 1)
# num = [0, 1, ... , 100]

if n == 0:
  ans = x
else:
  p = list(map(int, input().split()))
  if p.count(x) == 0:
    ans = x
  else:
    for i in range(n):
      num.remove(p[i])
    for i in range(len(num)):
      num[i] -= x
    
    max_m = -100
    for i in range(len(num)):
      if num[i] < 0 and max_m < num[i]:
        max_m = num[i]
    
    min_p = 100
    for i in range(len(num)):
      if num[i] > 0 and min_p > num[i]:
        min_p = num[i]
    
    if abs(min_p) < abs(max_m):
      ans = min_p
    else:
      ans = max_m
    ans += x
print(ans)

Submission status: Wrong Answer

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

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    for i in range(max(p)+2):
        if i not in p:
            li1.append(i)

    for j in li1:
        li2.append(abs(x - j))

    print(li1[li2.index(min(li2))])
    
print(li1)

Submission status: Wrong Answer

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

i=0
p=X+1
q=X-1
while True:
    if Y==0:
        print(int(X))
        break
    if q not in  P:
        print(int(q))
        break
    if p not in P:
        print(int(p))
        break
    i+=1
    p+=1
    q-=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()))
  ans = []

  for i in range(n-2):
    if x-i not in p:
      ans.append(-i)
      break
    elif x+i not in p:
      ans.append(i)
      break
  if ans == []:
    ans.append(-n+2)

  print(x+ans[0])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(101):
  if i in A:
    pass
  else:
    B.append(i)

C=[abs(X-j) for j in B]
s=min(C)

y=C.index(s)

z=B[y]

print(z)

Submission status: Wrong Answer

Solution code:
# X:整数　N:長さ
# p1 ... pN
# 含まれない整数のうちXに近いものを答える
X, N = map(int, input().split())
p = list(map(int, input().split()))
for i in range(X, -50, -1):
    l = i
    if i not in p:
        break
for j in range(X, 201):
    r = j
    if j not in p:
        break
print(l if abs(l-X) < abs(r-X) else r)

Submission status: Wrong Answer

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

p.sort()
d = 10 ** 9
for i in range(-100,100):
    if d > abs(i-x) and i not in p:
        d = abs(i-x)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
X, N = np.array(list(map(int, input().split())))
if N == 0:
    print(X)
    sys.exit()
p = np.array(list(map(int, input().split())))
p = np.sort(p)
a = np.ones(203, dtype = np.int)
a[p+102] = 0
m = X
n = 0
for i in range(203):
    if a[i] == 1:
        if m>abs(i-X-102):
            if i-X-102 != 0:
                m = abs(i-X-102)
                n = i-102
print(int(n))

Submission status: Wrong Answer

Solution code:
def solution(X, N, P):
    if N <= 0 or X not in P:
        return X

    P.sort()
    diff = [abs(p - X) for p in P]
    X_idx = diff.index(0)
    left = sorted(diff[:X_idx])
    right = sorted(diff[X_idx+1:])

    nearest_l = None
    for i, l in enumerate(left, 1):
        if i != l:
            nearest_l = X - i
            break
    
    nearest_r = None
    for i, r in enumerate(right, 1):
        if i != r:
            nearest_r = X + i
            break
    
    if nearest_l and nearest_r:
        return min(nearest_l, nearest_r)
    else:
        return nearest_l or nearest_r

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

Submission status: Wrong Answer

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


def main():
    x, n = [int(i) for i in input().split()]
    p = set([int(i) for i in input().split()])

    ans = x
    for i in range(1, 101):
        if i in p:
            continue

        if i <= x:
            ans = i
        elif x - ans > i - x:
            ans = i
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x, n = input().split()
x = int(x)
n = int(n)
m = list(map(int,input().split()))
sa = 999
ans = 0

if x in m == False:
    print(x)
    exit()
elif len(m) == 0:
    print(x)
    exit()

for k in range(1,x+1):
    if m.count((x - k)) == 0 and x - (x - k) < sa:
        sa =  x - (x - k)
        ans = x - k

for l in range(1,300):
    if m.count((x + l)) == 0 and (x+l) - x < sa:
        sa = (x+l) - x
        ans = x + l

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

p = set(map(int, readline().split()))

ans = x
tmp = 10 ** 9
for i in reversed(range(-1, 101)):
    if i not in p:
        if tmp >= abs(x - i):
            tmp = abs(x - i)
            ans = i
print(ans)

Submission status: Wrong Answer

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

    ans=0
    min_ans=101
    t=0

    for i in range(101):
        #for e in range(n):
        ans=abs(x-i)
        if p.count(i)==0:#i!=p:#[e]:
            if ans<min_ans:
                min_ans=ans
                t=i

    print(t)

Submission status: Wrong Answer

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

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

s = 1000000000

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

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

Submission status: Wrong Answer

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

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

l = [0] * 100

for p in P:
    l[p-1] = 1
    
i = 1
while 1:
    if X-i-1 < 0:
        print(0)
        exit()
    elif l[X-i-1] == 0:
        print(X-i)
        exit()
    elif X+i-1 >= 100:
        print(101)
        exit()
    elif l[X+i-1] == 0:
        print(X+i)
        exit()
    i+=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()))

dl=[[0,0] for _ in range(n)]

for i in range(n):
    dl[i][0]=abs(x-p[i])
    dl[i][1]=x-p[i]
dl.sort()


j=0
for i in range(n):
    if i%2!=0:
        if dl[i][0]!=j:
            print(x-j)
            exit()
    else:
        if dl[i][0]!=j:
            print(x+j)
            exit()
        j+=1

Submission status: Wrong Answer

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

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

if N == 0:
    print(X)
else:
    for i in range(1, 110):
        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:
#!/usr/bin/env python3
import os
from sys import stdin


def solve(tc):
    x, n = map(int, stdin.readline().split())
    seq = list(map(int, stdin.readline().split()))

    diff = [0 for i in range(100)]
    for num in seq:
        diff[abs(x-num)] += 1

    if diff[0]==0:
        ans = x
    else:
        for i in range(1,100):
            if diff[i] < 2:
                ans = x+i
                break

    print(ans)


tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1

Submission status: Wrong Answer

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

p.sort()
index = 0
for i in range(n):
    if p[i] == x:
        index = i

prev = x
right = x
left = x

for i in p[index:]:
    if i != prev + 1:
        right = prev + 1
    prev = i

for i in reversed(p[: index + 1]):
    if i != prev - 1:
        left = prev - 1
    prev = i

if n != 0:
    if index == n - 1:
        right = p[index] + 1
    elif index == 0:
        left = p[index] - 1

print(min(left, right))

Submission status: Wrong Answer

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

nun_list = list(map(int, input().split()))
answer = nun_list[0]
for i in nun_list:
    if abs(x - answer) >= abs(x - i):
        if abs(x - answer) == abs(x - i):
            if answer > i:
                answer = i
        else:
            answer = i
for i in range(0,1000):
    if not nun_list.__contains__(answer -i):
        print(answer - i)
        sys.exit() 
    if not nun_list.__contains__(answer + i):
        print(answer + i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
def main():
  X, N = map(int, input().split())
  if N == 0:
    return X
  
  P = list(map(int, input().split()))
  
  delta = []
  for n in range(1, 101):
    if n in P:
      delta.append(float('inf'))
    else:
      delta.append(abs(X - n))
      
  minD = min(delta)
  for i, d in enumerate(delta):
    if d == minD:
      return i + 1


print(main())

Submission status: Wrong Answer

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


def f(X, N, listp):

    if N == 0:
        return X
    if X not in listp:
        return X

    up_list = []
    down_list = []
    for p in listp:
        if p > X:
            up_list.append(p)
        if p < X:
            down_list.append(p)

    up_list = sorted(up_list)
    down_list = sorted(down_list, reverse=True)


    up_res = 10000
    for i, p in enumerate(up_list):
        if p != X+i+1:
            up_res = X+i+1
            break
    if up_res == 10000:
        up_res = X+1

    down_res = -10000
    for i, p in enumerate(down_list):
        if p != X-i-1:
            down_res = X-i-1
            break
    if down_res == -10000:
        down_res = X-1
    

    if abs(X - up_res) < abs(X - down_res):
        return up_res
    else:
        return down_res


print(f(X, N, listp))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import sys
X,N=list(map(int,input().split()))
if N==0:
    print(X)
    sys.exit()
P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if x>=len(P):
    print(X)
    sys.exit()
if P[x]!=X:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)

    if x1<len(P) and P[x1]!=A:
        print(A)
        break
        
    if x2<len(P) and P[x2]!=B:
        print(B)
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
x =a[0]
n =a[1]
if n==0:
  print(x)
else:
  p = list(map(int,input().split()))
  p.sort()
  out_p = []
  for i in range(p[n-1]-p[0]+1):
    if not i+p[0] in p:
      out_p.append(i+p[0])
  if min(p)>x or max(p)<x:
    print(x)
  else:
    re_p =[]
    for j in range(len(out_p)):
      re_p.append(abs(out_p[j]-x))
    if re_p:
      print(out_p[re_p.index(min(re_p))])
    else:
      if abs(max(p)-x)>abs(min(p)-x):
        print(min(p)-1)
      else:
        print(max(p)+1)

Submission status: Wrong Answer

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

if n == 0:  
    p = input()
    print(x)
else:
    p = list(map(int, input().split()))
    max_p = max(p)
    ans = 0
    tmp = 1000

    for i in range(1, 200):
        diff = abs(x - i)
        if i not in p and tmp > diff:
            ans = i
            tmp = diff

    print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n != 0:
    li = list(map(int,input().split()))

if n == 0:
    print(x)
else:
    for i in range(1, 101):
        up = x + i
        down = x - i
        if down not in li:
            print(down)
            break
        if up not in li:
            if down == up:
                print(down)
                break
            else:
                print(up)
                break

Submission status: Wrong Answer

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

result = 100
ans = 0
if n == 0:
    print(x)
    exit()
else:
    p = list(map(int,input().split()))
    for i in range(1,max(p)+2):
        if p.count(i) == 0:
            if abs(x-i) < result:
                result = 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:
    pn = list(map(int, input().split()))
    is_ex_list = [False for i in range(max(pn) + 1)]
    for p in pn:
        is_ex_list[p] = True
    min_v = x
    min_f = 101
    for i in range(max(pn) + 1):
        if not is_ex_list[i] and abs(x - i) <= min_v:
            if min_v == abs(x - i) and min_f > i:
                min_f = i 
            else:
                min_f = i 
            min_v = abs(x - i)
    for i in range(-(max(pn)), 0):
        if abs(x - i) <= min_v:
            if min_v == abs(x - i) and min_f > i:
                min_f = i 
            else:
                min_f = i 
            min_v = abs(x - i)
    print(min_f)

Submission status: Wrong Answer

Solution code:
def resolve():
    X, N = map(int, input().split())
    if N != 0:
        P = list(map(int, input().split()))
        S = []
        for _ in range(0, 102):
            if _ in P:
                continue
            else:
                S.append(_)
        if X in S:
            print(X)
        else:
            for i in range(N):
                if X-i in S:
                    print(X-i)
                    exit()
                elif X+i in S:
                    print(X+i)
                    exit()
    else:
        print(X)
resolve()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
X, N = np.array(list(map(int, input().split())))
if N == 0:
    print(X)
    sys.exit()
p = np.array(list(map(int, input().split())))
p = np.sort(p)
a = np.ones(203, dtype = np.int)
a[p+102] = 0
m = X
n = 0
for i in range(203):
    if a[i] == 1:
        if m>abs(i-X-102):
            if i-X-102 != 0:
                m = abs(i-X-102)
                n = i-102
print(n)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
	print(X)
	exit()
p=list(map(int,input().split()))
if X not in p:
	print(X)
	exit()
tmp=101
for i in range(101):
	if i not in p:
		if tmp>abs(X-i):
			ans=i
			tmp=abs(X-i)
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()))
  numbers=list(range(101))
  ans=0

  for i in range(len(p)):
    numbers.remove(p[i])

    for j in range(100):
      for k in range(len(numbers)):
        if abs(X-numbers[k]) == 100-j:
          ans=numbers[k]
          break

  print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

if n == 0:
    print(x)

else:
    p = list(map(int, input().split()))
    ans = []

    lx = x
    mx = x

    while lx <= 100:
        lx += 1
        if lx not in p:
            ans.append(lx)
            break

    while mx >= 0:
        mx -= 1
        if mx not in p:
            ans.append(mx)
            break

    if abs(x-ans[0]) < abs(x-ans[1]):
        print(ans[0])
    elif abs(x-ans[0]) == abs(x-ans[1]):
        print(min(ans))
    else:
        print(ans[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(1, 100):
    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:
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    if x in p:
        for i in range(-1000, 1001):
            print(i)
            if i == -1000:
                mini = i
            if i in p:
                pass
            else:
                if abs(x - mini) > abs(x - i):
                    mini = i
                elif abs(x - mini) == abs(x - i):
                    mini = min(mini, i)
        else:
            print(mini)
    else:
        print(x)
else:
    print(x)

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


for i in range(1,150):
  if x-i not in p:
    print(x-i)
    break
  if x+i not in p:
    print(x+i)
    break

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
try:
  p=list(map(int,input().split()))
except:
  print(x)
  exit()
ans=float('inf')
for i in range(1,101):
  if i not in p:
    ans=min(ans,abs(x-i))
    
    
if x-ans not in p and (x-ans)>0 and (x-ans)<=x:
  print(x-ans)
  
elif x-ans not in p and (x-ans)<=0:
  print(x+ans)

else:
  print(x+ans)

Submission status: Wrong Answer

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

if len(p) == 0:
    print(X)
    exit()

if not X in p:
    print(X)
    exit()

small = [i for i in range(-101, X)]
big = [i for i in range(X+1, 102)]
small.reverse()
print(small)
print(big)
print(max(len(big),len(small)))
for i in range(max(len(big),len(small))):
    if not small[i] in p:
        print(small[i])
        exit()
    elif not big[i] in p:
        print(big[i])
        exit()

Submission status: Wrong Answer

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

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

if X in P:
    for i in range(1,100):
        if X - i > 0:
            if not X - i in P:
                print(X - i)
                exit()

        if X + i <= 100:
            if not X + i in P:
                print(X + i)
                exit()
else:
    print(X)

Submission status: Wrong Answer

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

antip = set(range(1,101)) - set(p)
dist = 1000
ans = 1000
for v in antip:
    can = abs(v - X)
    if(can < dist):
        dist = can
        ans = v
    if(can == dist):
        ans = min(ans, v)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input1 = list(map(int, input().split()))
X = input1[0]
N = input1[1]
p = list(map(int, input().split()))

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

# print(X)
flag = True
diff = 1
# print((X - diff) in p)
while(flag):
    if ((X - diff) in p) == False:
        answer = X - diff
        flag = False
    elif ((X + diff) in p) == False:
        answer = X + diff
        flag = False
    else:
        diff += 1

print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = list(map(int,input().split()))
if N == 0:
  print(X)
else:
  p_arr = list(map(int,input().split()))
  for i in range(101):
    if not (X in p_arr):
      print(X)
    else:
      if i == 0:
        continue
    lower = (X-i in p_arr)
    upper = (X+i in p_arr)
    if not lower:
      print(X-i)
      break
    else:
      if not upper:
        print(X+i)
        break

Submission status: Wrong Answer

Solution code:
def f(x, P):
    y = x
    z = x
    while y > 0 or z <= 100:
        if y > 0:
            if y not in P:
                return y
        if z <= 100:
            if z not in P:
                return z
        y -= 1
        z += 1
    return -1


x, N = map(int, input().split())
if N:
    P = list(map(int, input().split()))
    print(f(x, P))
else:
    print(x)

Submission status: Wrong Answer

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


l = [0]*200

for i in range(N):
  l[abs(p[i] - X)] += 1

#print(p.index(9))
if N == 0:
  print(X)
else:
  for i in range(N):
    if i == 0:
      if l[0] == 1:
        continue
      else:
        print(X)
        break
    else:
      if l[i] == 0:
        if X-i != 0:
          print(X-i)
          break
        else:
          print(X+i)
          break
      elif l[i] == 1:
        try:
          p_index = p.index(X-i)
          print(X+i)
        except:
          print(X-i)
        break

Submission status: Wrong Answer

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

A = [0]*101
for i in P:
    A[i] = 1

if A[X] == 0:
    print(X)
    exit()

count = 1
while(1):
    if (X - count) < 101 and (X - count) >= 0:
        if A[X - count] == 0:
            print(X - count)
            exit()

    if count > 0:
        count = -count
    else:
        count = -count
        count += 1

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N > 0:
    P = list(map(int, input().split()))
    res = float('Inf')
    A = [0]*101
    for n in range(N):
        A[P[n]-1] += 1
    cnt = 1
    man = 0
    for a in A:
        if a == 0:
            total = abs(cnt - X)
            if res > total:
                res = total
                man = cnt
        cnt += 1
    print(man)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
try:
  p = list(map(int, input().split()))
  lists = list(range(101))
  del lists[0]
  sa = []
  for i in lists:
    if(i in p):
      sa.append(999)
    else:
      sa.append(abs(x-i))
    ind = sa.index(min(sa))
    ans = lists[ind]
except:
  ans = x
print(ans)

Submission status: Wrong Answer

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

# そもそもNが0ならXが正解
# Xを基準に大きい方向、小さい方向の両方向へ1づつ数値をずらしていき、
# p_listにヒットしない整数が合ったときに正解となる。
# 同時に大小ヒットした場合は小さいほうが正解

if(N == 0):
  goal = 0
else:
  p_list = list(map(int, input().split(' ')))
  max_p = max(p_list)
  min_p = min(p_list)
  #print(X,N)
  #print(p_list)
  #print(max_p, min_p)
  goal = 0
  challenge_plus = X
  challenge_minus = X

  for i in range(min_p, max_p + 1):
    tmp_break = False
    challenge_plus += 1
    challenge_minus -= 1
    #print("比較対象は{0}, {1}".format(challenge_plus, challenge_minus))
    if(challenge_plus in p_list):
      p_list.remove(challenge_plus)
    else:
      goal = challenge_plus
      tmp_break = True
      
    if(challenge_minus in p_list):
      p_list.remove(challenge_minus)
    else:
      goal = challenge_minus
      break
      
    if(tmp_break):
      break

  

print(goal)

Submission status: Wrong Answer

Solution code:
s = input().split()

x = int(s[0])
n = int(s[1])

s = {i for i in range(-1,101)}

p1 = input().split()

p = set()

for i in p1:
    p.add(int(i))

t = s - p

answer = 20000

for i in t:
    if (abs(x - abs(int(i))) < abs(x - abs(answer))) or (abs(x - abs(int(i))) == abs(x - abs(answer))) and i < answer:
        answer = int(i)

print(answer)

Submission status: Wrong Answer

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

for n in range(1, (N // 1) + 1):
    if not (X - n) in P:
        print(X - n)
        exit()
    if not (X + n) in P:
        print(X + n)
        exit()
print(min(P) - 1)

Submission status: Wrong Answer

Solution code:
import sys


def int1(x): return int(x) - 1
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def mi1(): return map(int1, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def lli(rows_number): return [li() for _ in range(rows_number)]


if __name__ == "__main__":
    x, n = mi()
    if n == 0:
        print(x)
        exit()
    p_l = li()
    a = list(range(0, 101))
    for p in p_l:
        a.remove(p)
    ans = 0
    min_dif = 10000
    for i in a:
        dif = abs(i-x)
        if dif < min_dif:
            min_dif = dif
            ans = i
    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    if p != []:
        for i in range(0, 100):
            if not x-i in p:
                if x-i >= 0:
                    print(x-i)
                break
            else:
                if not x+i in p:
                    if x+i <= 100:
                        print(x+i)
                    break
    else:
        print(x)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

	diff_1 = abs(X-p[-1])
	diff_2 = abs(X-p[0])
	diff = max(diff_1,diff_2)


	for x in range(diff):
		if X-x not in p:
			print(X-x)
			break
		if X+x not in p:
			print(X+x)
			break