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: Runtime Error

Solution code:
A1 = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
 
X = A1[0]
N = A1[1]
diff = 100
ans=[]
ans0 = 100
 
for i in range(N):
  diff0 = abs(p[i]-X)
  if diff0 < diff:
    diff = diff0
    ans.append(p[i])
if int(len(ans)) > 2:
  for i in range(int(len(ans))):
    if ans[i] < ans0:
      ans0 = ans[i]
else:
  ans0 = ans[0]
print(ans0)

Submission status: Runtime Error

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

num_list = list(range(1,101))
y = (num_list + p)

counter = Counter(y)
result =  [elem for elem in y if counter[elem] < 2]


ans = 10 *100000000000

for i in result:
    temp = abs(i - x)
    if ans >= temp:
        ans = temp
        res = i
print(res)

Submission status: Runtime Error

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
d = []
c=0
if n == 0:
    print(x)
else:
    for e in p:
        d.append( abs(e-x))
    s = d[0]
    for i in range(len(d)):
        if d[i] < s:
            s = i
            z = p[i]
    for j in range(1,100):
        for g in p:
            if z+j != g:
                c +=1
                w1 = z+j
        if c == n:
            break
        c = 0
    c=0
    for j in range(1,100):
        for g in p:
            if z-j != g:
                c +=1
                w2 = z-j
        if c == n:
            break
        c = 0

    if abs(w1-x) < abs(w2-x):
        print(w1)
    else:
        print(w2)

Submission status: Runtime Error

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

x,n = I2()
if n != 0:
    p = Intl()
else:
    p = []
p.sort()
if not x in p:
    print(x)
else:
    b,e = 0,n-1
    for i in range(n):
        if p[i] == x:
            b = max(b,i-1)
            e = min(e,i+1)
            break
    r = []
    s = []
    for i in range(p[b],p[e]+2):
        if i not in p:
            r.append(i)
            s.append(abs(x-i))
    print(r[s.index(min(s))])

Submission status: Runtime Error

Solution code:
def find_num(lst, value):
    return [i for i, x in enumerate(lst) if x == value]

def resolve():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
    else:
        p = list(map(int,input().split()))
        p.sort()
        idx = find_num(p,X)
        if idx == []:
            print(X)
        else:
            for i in range(1,100):
                if p[idx[0] - i ] != X - i or idx[0] - i == -1:
                    print(X-i)
                    break
                if p[idx[0] + i ] != X + i or idx[0] + i == N:
                    print(X+i)
                    break
resolve()

Submission status: Runtime Error

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

    min = 100000

    for i in range(1, 101):

        if i in p:
            continue

        if min > abs(x - i):
            result = i
            min = x - i

    print(result)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
a=list(map(int,input().split()))
number=[0]*101

for num in range(len(a)):
    number[a[num]]=a[num]
    
counter=0
plus=0
ans=0

while counter==0:
    if number[x-plus]==0:
        counter+=1
        ans=x-plus
    elif number[x+plus]==0:
        counter+=1
        ans=x+plus
    else:
        plus+=1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

    for i in range(1, 101):
        if i not in p:
            if abs(i - x) < absol:
                absol = abs(i - x)
                ans = i
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
Ps=list(map(int,input().split()))
numlist=[]
for i in range(101):
    numlist.append(i)
for p in Ps:
    numlist.remove(p)
import bisect
if numlist==[0]:
    if x<=51:
        print(0)
    else:
        print(101)
    quit()
a=bisect.bisect_left(numlist,x)
b=a-1
if abs(numlist[a]-x)>=abs(numlist[b]-x):
    print(numlist[b])
else:
    print(numlist[a])

Submission status: Runtime Error

Solution code:
lst = []
l = []
str = input()
l = str.split(' ')
n = int(l[0])
no = int(l[1])
if no==0:
  print(n)
  break
  
for i in range(0,no):
  inp = int(input())
  lst.append(inp)
  
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: Runtime Error

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
  print(x+ans[0])

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
nums = list(map(int, input().split()))
nums.sort()
low = nums[0]
high = nums[-1]
minDiff = 100000000
minNum = -1
for i in range(low+1, high):
  if i in nums:
    continue
  else:
    Dif = abs(X-i)
    if (Dif < minDiff):
      minDiff = Dif
      minNum=i

if (minNum == -1):
  print(X)
else:
  print(minNum)

Submission status: Runtime Error

Solution code:
X,N = list(map(int,input().split()))
if N == 0:
  print(X)
  exit()
P = sorted(list(map(int,input().split())))
ans1 = P[0] - 1
ans2 = P[-1] + 1
isx = 0
for i in range(1,N+1):
  if (P[i]-X) > 0:
    if not isx:
      ans1 = X
      break
    else:
      break
  if P[i-1] != (P[i]-1):
    ans1 = P[i] -1
  if P[i] == X:
    isx = 1
    break

for i in range(1,N+1):
  if (P[-i]-X) < 0:
    if not isx:
      ans1 = X
      break
    else:
      break
  if P[-i+1] != (P[-i]+1):
    ans2 = P[-i] + 1
  if P[-i] == X:
    isx = 1
    break

if not isx:
  print(X)
  exit()

aa1 = abs(X-ans1)
aa2 = abs(X-ans2)
if aa1 == aa2:
  print(ans1)
elif aa1 > aa2:
  print(ans2)
else:
  print(ans1)

Submission status: Runtime Error

Solution code:
x,N=map(int,input().split())
p=list(map(int,input().split()))
p_set=set(p)
flag=0
if x not in p_set:
    ans=x
else:
    count=0
    while flag==0:
        count+=1
        if x+count not in p_set:
            ans=x+count
            flag=1
        if x-count not in p_set:
            ans=min(ans,x-count)
            flag=1
print(ans)

Submission status: Runtime Error

Solution code:

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

d=150
pa = 0
px =range(1,101,1)
py = list(set(px) - set(p))

for i in py:

    if d> abs(i-x):
        pa = i
        d = abs(i-x)
    elif d == abs(i-x):
        if i < pa:
            pa =i

if n == 100
    if x<=50:
        print(0)
    else:
        print(101)

print(pa)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
t = [0]*101

for i in p:
    t[i] = 1

for j in range(50):
    if t[x-j] == 0:
        print(x-t[n-j])
        break
    elif t[x+j] == 0:
        print(x+t[n+j]+1)
        break

Submission status: Runtime Error

Solution code:
kazulist = []
for i in range(100):
    kazulist.append(i+1)

a = list(input().split(" "))
target = int(a[0])
syokyo = int(a[1])

b = list(input().split(" "))
for i in b:
    kazulist.pop(int(i))

saisyosa = 100
kotae = 0
for i in kazulist:
    sa = target - int(i)
    if sa < 0:
        sa *= -1
    if sa < saisyosa:
        saisyosa = 0
        kotae = i

print(i)

Submission status: Runtime Error

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

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

d = [0 for _ in range(100)]
for i in range(100):
    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: Runtime Error

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

if x not in l:
    print(x)
    exit()

tmp = []
for i in range(x-50,x+50):
    tmp.append(i)

ans = []
for j in tmp:
    if j not in l:
        ans.append(j)

tmp1 = 1
for k in ans:
    tmp2 = abs(x-k)
    if tmp2 != 0:
        if tmp1 >= tmp2:
            tmp1 = tmp2

ans2 = []
for m in ans:
    a = abs(m-x)
    if a == tmp1:
        ans2.append(m)

print(min(ans2))

Submission status: Runtime Error

Solution code:
from math import ceil

X, N = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l2 = [abs(int(x)-X) for x in l]
l2.sort()
for i in range(N):
    if ceil(i/2) != l2[i]:
        t = ceil(i/2)
        break
if X - t in l:
    print(X + t)
else:
    print(X - t)

Submission status: Runtime Error

Solution code:
z = list(map(int, input().split()))
x = z[0]
if z[1] == 0:
  print(z[0])
else:
  p = list(map(int, input().split()))
  count = 0
  l = []
  for i in range(1, 101):
    l.append(i)
  for i in p:
    l.remove(i)
  t = 200
  for i in l:
    e = abs(x-i)
    if e >= t:
      break
    t = e
    ans = i
  print(ans)

Submission status: Runtime Error

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

num_list = list(range(1,101))
y = (num_list + p)

counter = Counter(y)
result =  [elem for elem in y if counter[elem] < 2]
#print(result)

ans = 10 *100000000000

for i in result:
    temp = abs(i - x)
    if ans > temp:
        ans = temp
        res = i
print(res)

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 0
    a = x
    b = x
    while ans == 0:
      if X-i != P[a]:
        ans = X-i
      elif X+i != P[b]:
        ans = X+i
        a -= 1
      else:
        a -= 1
        b += 1
        i += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline

def main():
    x, n = map(int, input().rstrip().split())
    if n == 0:
        print(x)
        sys.exit()
    else:
        p = list(map(int, input().rstrip().split()))
        if x > max(p):
            print(x)
            sys.exit()
        else:
            p_x = set(range(min(p),max(p)+1))
            p_temp = set(p)
            p_diff = p_x - p_temp
            p_temp = list(p_diff)
            p_dir = []

        for i in range(len(p_temp)):
            p_dir.append(abs(p_temp[i] - x))
        print(p_temp[p_dir.index(min(p_dir))])
  
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
tmp = []
for i in range(1,101):
    tmp.append(i)

if n == 0:
    print(x)
else:
    for i in p:
        tmp.remove(i)
    
    ans = []
    for i in tmp:
        a = abs(x-i)
        ans.append(a)

    b = min(ans)

    c = x+b
    d = x-b

    if c and d in tmp:
        print(d)
    elif c in tmp:
        print(c)
    elif d in tmp:
        print(d)

Submission status: Runtime Error

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

ls = sorted(ls)
d = 10**3
ans = 0
for i in range(ls[0]-1,ls[-1]+2):
  if i in ls:
    continue
  if d>abs(i-x):
    d = abs(i-x)
    ans = i
print(ans)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
lis=[i+1 for i in range(100)]
flag=True
flag2=True
if n==0:
  flag=False
  print(x)


if flag:
  p=list(map(int,input().split()))
  for i in p:
    lis.remove(i)
  if x>lis[-1]:
    print(lis[-1])
    flag2=False
  if flag2:
    for i in range(len(lis)):
      if lis[i]>x:
        id=i
        break
    if id>=1:
      if abs(x-lis[id])<abs(x-lis[id-1]):
        print(lis[id])
      else:
        print(lis[id-1])
    else:
      print(lis[0])

Submission status: Runtime Error

Solution code:
X, num = [int(i) for i in input().split(" ")]
l = [int(i) for i in input().split(" ")]
 
if num == 0:
  print(X)
else:
  for i in range(num):
    if X-i not in l:
      print(X-i)
      exit()
    elif X+i not in l:
      print(X+i)
      exit()
  print(X-num)

Submission status: Runtime Error

Solution code:
import sys
X,n=[int(x) for x in input().rstrip().split()]
p=[int(x) for x in input().rstrip().split()]

nai=[]
if n==0:
  print(X)
  sys.exit()
else:
  if X not in p:
    print(X)
    sys.exit()
  else:
    for i in range(-100,101):
      if i not in p:
        nai.append(i)
    nai.append(X)
    nai.sort()

    for i in range(len(nai)):
      if nai[i]==X:
        if abs(nai[i-1]-X)<=abs(nai[i+1]-X):
          print(nai[i-1])
        else:
          print(nai[i+1])
          sys.exit()

Submission status: Runtime Error

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 A[X - count] == 0:
        print(X - count)
        exit()

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

Submission status: Runtime Error

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

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

num=[i for i in range(1,101)]
for i in p:
    num[i-1]=0

num.append(-1)
num.sort()
while True:
    if num[1]!=0:
        break
    num.pop(1)
# print(num)

min=1000
for i in num:
    if min>abs(x-i):
        min=abs(x-i)
        ans=i
print(ans)

Submission status: Runtime Error

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

p = [int(input()) for i in range(n)]
s = 1000000000

for i in range(1,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: Runtime Error

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

x, n = [int(x) for x in input().split()]
if n == 0:
    q = [x for x in range(1, 101)]
else:
    p = [int(x) for x in input().split()]
    q = [x for x in range(1, 101) if x not in p]

diffs = [abs(x-qk) for qk in q]
mindiff = min(diffs)
idx = diffs.index(mindiff)
print(q[idx])

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  p=list(map(int,input().split()))
  c=[0]*100
  for i in p:
    c[i]=1
  if max(p)<x:
    print(x)
  elif min(p)>x:
    print(x)
  else:
    i=0
    while True:
      if p.count(x-i)==0:
        print(x-i)
        break
      elif p.count(x+i)==0:
        print(x+i)
        break
      else:
        i+=1

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
if n != 0:
  p = sorted(map(int,input().split()))
aa = []
for i in range(1,101):
  if not i in p:
    aa.append(i)
bb = []
for A in aa:
  eee = abs(x-A)
  bb.append(eee)

ans = bb.index(min(bb))
print(aa[ans])

Submission status: Runtime Error

Solution code:

def main():
    x,y = list(map(int, input().split()))

    if y == 0:
        print(x)
        exit()
    nums = list(map(int, input().split()))
    ans = []
    # 右へ進む
    for i in range(x, 101):
        if i not in nums:
           ans.append(i)
           break
    for i in range(x, 0, -1):
        if i not in nums:
           ans.append(i)
           break
    if len(ans) == 1:
        print(ans[0])
        exit()
    if abs(ans[0] - x) == abs(ans[1] - x):
        print(min(ans))
    elif abs(ans[0] - x) > abs(ans[1] - x):
        print(ans[1])
    elif abs(ans[0] - x) < abs(ans[1] - x):
        print(ans[0])

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import bisect
X,N=map(int,input().split())
if N==0:
    print(X)
    exit()
P=sorted(list(map(int, input().split())))
key=bisect.bisect_left(P,X)
small=P[-1]
key2=bisect.bisect_right(P,X)
for i in range(N):
    if P[key]-i not in P:
        small=P[key]-i
        break
for i in range(N):
    if P[key2-1]+i not in P:
        large=P[key2-1]+i
        break
print(small if abs(X-small)<=abs(X-large) else large)

Submission status: Runtime Error

Solution code:
X, N = list(map(int,input().split()))
if N !=0:
  P = list(map(int,input().split()))
  ab = 100
  for i in range(101):
    if i not in P:
      if abs(X-i)<ab:
        ab = abs(X-i)
        ans = i
      elif abs(X-i)==ab:
        ans = min(ans,i)
  print(ans)
else:
  print(X)

Submission status: Runtime Error

Solution code:
lst = []
l = []
str = input()
l = str.split(' ')
n = int(l[0])
no = int(l[1])
  
  
for i in range(0,no):
  inp = int(input())
  lst.append(inp)
  
for i in range(1,100):
  if n-i not in lst:
    print(n-i)
    break
  if n+i not in lst:
    print(n+i)
    break

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
p=sorted(map(int,input().split()))
p = [i for i in range(min(p),max(p)+1) if i not in p]
if X in p:
  print(X)
else:
  p = list(set(p))
  p.append(X)
  p.sort()
  index_num = p.index(X)
  if 0 < index_num < len(p)-2:
    num1=index_num+1
    num2=index_num-1
    num1_abs=abs(p[index_num]-p[num1])
    num2_abs=abs(p[inedx_num]-p[num2])
    if num1_abs < num2_abs:
      print(p[num1])
    else:
      print(p[num2])
  elif index_num==0:
    num1=index_num+1
    print(p[num1])
  elif index_num == len(p)-1:
    num2=index_num-1
    print(p[num2])

Submission status: Runtime Error

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

P = list(map(int, input().split()))
minmin = []
minn = 101
for i in range(1, 101):
    abs1 = abs(i - X)
    if not i in P and minn > abs1:
        minn = abs1
        minmin.append(i)

print(max(minmin))

Submission status: Runtime Error

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

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

p.sort()
tmp = [i for i in range(1, 101)]
for i in p:
        tmp.remove(i)

ans_num = float("Inf")
ans_i = 0
for i in range(len(tmp)):
        if abs(X - tmp[i]) < ans_num:
                ans_num = abs(X - tmp[i])
                ans_i = i


print(tmp[ans_i])

Submission status: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    X, N = LI()
    if N == 0:
        print(X)
        return

    p = LI()

    p_max = max(p)
    p_min = min(p)

    if X < p_min or p_max < X:
        print(X)
    else:
        d = [abs(i-X) for i in range(p_min, p_max+1) if i not in p]
        d_min = min(d)
        for i in range(p_min, p_max+1):
            if i not in p:
                if abs(i-X)==d_min:
                    print(i)
                    break

if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
z = list(map(int, input().split()))
x = z[0]
if z[1] == 0:
  print(z[0])
else:
  p = list(map(int, input().split()))
  count = 0
  l = []
  for i in range(1, 101):
    l.append(i)
  for i in p:
    l.remove(i)
  print(l)
  t = 200
  for i in l:
    e = abs(x-i)
    if e >= t:
      break
    t = e
    ans = i
  print(ans)

Submission status: Runtime Error

Solution code:
x,n = map(int, input().split())
l = list(map(int, input().split()))
l_dis = [num - x for num in l]

def s_func(x):
    if x < 0:
        return abs(x) - 0.5
    else:
        return abs(x)
    
l_dis = sorted(l_dis, key=s_func)
if not l_dis:
    print(x)
elif l_dis[0] != 0:
    print(x)
else:
    i = 1
    j = 1
    b = -1
    while True:
        if l_dis[i] != j*b:
            print(x + j*b)
            break
        i += 1
        b *= -1
        if l_dis[i] != j*b:
            print(x + j*b)
            break
        i += 1
        b *= -1
        j += 1

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
lis=[i+1 for i in range(100)]
flag=True
flag2=True
if n==0:
  flag=False
  print(x)


if flag:
  p=list(map(int,input().split()))
  for i in p:
    lis.remove(i)
  if x>lis[-1]:
    print(lis[-1])
    flag2=False
  if flag2:
    for i in range(len(lis)):
      if lis[i]>x:
        id=i
        break
    if id>=1:
      if abs(x-lis[id])<abs(x-lis[id-1]):
        print(lis[id])
      else:
        print(lis[id-1])
    else:
      print(lis[0])x,n=map(int,input().split())
lis=[i+1 for i in range(100)]
flag=True
flag2=True
if n==0:
  flag=False
  print(x)


if flag:
  p=list(map(int,input().split()))
  for i in p:
    lis.remove(i)
  if x>lis[-1]:
    print(lis[-1])
    flag2=False
  if flag2:
    for i in range(len(lis)):
      if lis[i]>x:
        id=i
        break
    if id>=1:
      if abs(x-lis[id])<abs(x-lis[id-1]):
        print(lis[id])
      else:
        print(lis[id-1])
    else:
      print(lis[0])

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
P = list(map(int,input().split()))
value = float('inf')
if(N==0):
    print(X)
    exit()
ans_value= 100
for i in range(-1,102):
    if (i not in P):
        if(abs(X-i)<value):
            value=abs(X-i)
            ans_value=i
print(ans_value)

X,N=map(int,input().split())
P = list(map(int,input().split()))
value = float('inf')
if(N==0):
    print(X)
    exit()
ans_value= 100
for i in range(-1,102):
    if (i not in P):
        if(abs(X-i)<value):
            value=abs(X-i)
            ans_value=i
print(ans_value)

Submission status: Runtime Error

Solution code:
X, num = [int(i) for i in input().split(" ")]
l = [int(i) for i in input().split(" ")]

if num == 0:
  print(X)
else:
  for i in range(num):
    if X-i not in l:
      print(X-i):
      exit()
    elif X+i not in l:
      print(X+i)
      exit()
  print(X-num)

Submission status: Runtime Error

Solution code:
10 5
4 7 10 6 5

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
x, N = map(int, input().split())
p1, p2, p3, p4, p5 = map(int, input().split())
num_list = [p1, p2, p3, p4, p5]

min_abs = 100
min_num = 0

for num in range(1, 101):
    if num in num_list:
        continue
    else:
        b = abs(num-x)
        if b < min_abs:
            min_abs = b
            min_num = num
            
print(min_num)

Submission status: Runtime Error

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


l = [0]*X

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

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:
        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: Runtime Error

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,102):
        if (X-i) not in P:
            print(X-i)
            break
        elif (X+i) not in P:
            print(X+i)
            break
    else:
        print(X)
        break

Submission status: Runtime Error

Solution code:
import numpy as np

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


possible=[]

for i in range(1,101):
    if i not in Pn:
        possible.append(i)

idx = np.abs(np.asarray(possible) - X).argmin()

print(possible[idx])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math
from collections import deque
from collections import defaultdict
from math import gcd




def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    P = np.array(P)
    
    P = np.sort(P)
    ind = bisect.bisect_right(P, X)

    if len(P) == 0 or P[ind-1] != X:
        return X
    
    Left = P[:ind-1] - X
    Right = P[ind:] - X

    Left = abs(Left[::-1])
    diff = 1
    Left_over = False
    Right_over = False
    while True:
        if not Left_over and Left[0] != diff:
            return X - diff
        elif not Right_over and Right[0] != diff:
            return X + diff
        diff += 1
        if len(Left) >= 2:
            Left = Left[1:]
        else:
            Left_over = True
        if len(Right) >= 2:
            Right = Right[1:]
        else:
            Right_over = True

        if Left_over and Right_over:
            return P[0]-1


print(main())

Submission status: Runtime Error

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

n_P = []

for i in range(1, 100):
    if i not in P:
        n_P.append(i)

n_P.sort()
INF = 10 ** 9
diff = INF
ans = INF

for p in n_P:
    if abs(X-p) < diff:
        diff = abs(X-p)
        ans = p

if abs(X-ans) > abs(X-n_P[-1]+1):
    ans = n_P[-1] + 1
if abs(X-ans) > abs(X-n_P[0]-1):
    ans = n_P[0] - 1

print(ans)

Submission status: Runtime Error

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

p.sort()
tmp = [i for i in range(1, 101)]
for i in p:
        tmp.remove(i)

ans_num = float("Inf")
ans_i = 0
for i in range(len(tmp)):
        if abs(X - tmp[i]) < ans_num:
                ans_num = abs(X - tmp[i])
                ans_i = i
if N == 0:
        print(X)
else:
        print(tmp[ans_i])

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
X, N = map(int, input().split())
if N!=0:
    p=list(map(int,input().split()))
    checkNum=[0 for j in range(101)]
    for i in range(len(p)):
        checkNum[p[i]]=1
    i=0
    while(X-i>=0 or X+1<101):
        if checkNum[X-i]==0:
            print(X-i)
            break
        if checkNum[X+i]==0:
            print(X+i)
            break
        i+=1
else:
    print(X)

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 1
    a = x-1
    b = x+1
    while ans == 0:
      if X-i != P[a]:
        ans = X-i
      elif X+i != P[b]:
        ans = X+i
        a -= 1
      else:
        a -= 1
        b += 1
        i += 1
print(ans)

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
tmp = []
for i in range(1,101):
    tmp.append(i)

if n == 0:
    print(x)
else:
    for i in p:
        tmp.remove(i)
ans = []
for i in tmp:
    a = abs(x-i)
    ans.append(a)

b = min(ans)

c = x+b
d = x-b

if c and d in tmp:
    print(d)
elif c in tmp:
    print(c)
elif d in tmp:
    print(d)

Submission status: Runtime Error

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

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

for i in range(X+1):
    if not i in p:
        x = i

for i in range(X,101):
    if not i in p:
        y = i
        break

if (X-x) == (y-X):
    print(x)
elif (X-x) > (y-X):
    print(y)
else:
    print(x)

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
l = [int(x) for x in input().split()]
mp = [False]*101
for i in range(n):
    mp[l[i]] = True



queue = [x]
while(len(queue)>0):
    now = queue.pop(0)
    if(mp[now]==False):
        print(now)
        exit()
    if(now <= 0 or now >=101):
        print(now)
        exit()
    
    queue.append(now-1)
    queue.append(now+1)

Submission status: Runtime Error

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

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

cnt = [0] *101
ans1 = 0
ans2 = 0

for _p in p:
    cnt[_p] += 1

for i in range(x, 1000):
    if cnt[i] == 0:
        ans1 = i
        break

for i in range(x-1, -1000, -1):
    if cnt[i] == 0:
        ans2 = i
        break

if abs(ans1 - x) < abs(ans2 - x):
    print(ans1)
elif abs(ans1 - x) >= abs(ans2 - x):
    print(ans2)

Submission status: Runtime Error

Solution code:
X,N = (int(x) for x in input().split())
if N==0:
    print(X)
else:
    P = [int(x) for x in input().split()]
    Flag   = True
    Target = X
    Count  = 0 
    if Target not in P:
        Flag = False
        print(X)
    else:
        while Flag:
            Count += 1
            Target = [X-Count,X+Count]
            if Target[1] not in P:
                Flag = False
                Disp = Target[1]
            if Target[0] not in P:
                Flag = False
                Disp = Target[0]
    print(Disp)

Submission status: Runtime Error

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


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

p.sort()
gen = list(range(-1,101))

for i in p:
    gen.remove(i)

index = bisect.bisect(gen,X)

ans = 100000
ans2 = 100000
a = [gen[index-1],gen[index],gen[index+1]]

for i in range(3):
    if ans >= abs(a[i]-X):
        ans = abs(a[i]-X)
        ans2 = a[i]
    else:
        pass
print(ans2)

Submission status: Runtime Error

Solution code:
import numpy as np
X,N = map(int,input().split())
p = list(map(int,input().split()))
idx = 0
if X < min(p):idx =0
elif X>max(p):idx =N-1
else:idx = np.abs(np.asarray(p) - X).argmin()
print(p[idx])