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:
X,N=map(int,input().split())
p=list(map(int,input().split()))
  
def abs_search(o,*l):
    if X  not in p:
        print(X)
        return
    
    for pl_num in range(X+1,102):
        if pl_num not in p:
            break
            
    for mi_num in range(X-1,-1,-1):
        if mi_num not in p:
            break
            
    abs_pl=abs(pl_num-X)
    abs_mi=abs(mi_num-X)
    
    if abs_pl<abs_mi:
        print(pl_num)
    else:
        print(mi_num)
        
abs_search(*p)

Submission status: Runtime Error

Solution code:
arr1 = list(map(int,list(input().split())))
arr2 = list(map(int,list(input().split())))
X=arr1[0]
N=arr1[1]


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

#####################3
arr2.sort()
if X < min(arr2):
	print(X-1)
	exit()
if max(arr2)<X:
	print(X+1)
	exit()


if arr2.index(X)==0 :
	arr2.append(X)


me = arr2.index(X)

len1 = int(len(arr2)/2)
for i in range( len(arr2 )):
	flg=0
	small1=0
	big1=0
	if me - i<0:
		print(min(arr2) - 1)
		exit()

	if me + i==len(arr2):
		print(max(arr2) + 1)
		exit()


	if (X - arr2[me - i] > i):
		small1 = arr2[me - i +1] - 1
		flg=1
	if (arr2[me + i] - X > i ):
		big1 = arr2[me + i -1] + 1
		flg=1
	
	if flg==1:
		if big1 - X < X - small1:
			print(big1)
			exit()
		else:
			print(small1)
			exit()

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n == 0:
	print(x)
	exit()
p = list(map(int, input().split()))
mind = abs(x - p[0])
pos = []
s = set(p)
p = []
for x1 in range(-100, 200):
	if x1 in s:
		continue
	else:
		p.append(x1)
for q in p:
	if abs(x - q) < mind:
		mind = abs(x - q)
		pos = [q]
	elif abs(x - q) == mind:
		pos.append(q)
pos.sort()
print(pos[0])

Submission status: Runtime Error

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

if Y == 0:
    print(X)
if Y != 0:
    for i in range(1, 100):
        if x-i >= 1:
            if abs(X-i) not in p:
                print(X-i)
                break
        if x + i =< 100:
            if abs(X+i) not in p:
                print(X+i)
                break

Submission status: Runtime Error

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

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

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

allList=[]

for i in range(1,101):
    allList.append(i)
    
diff = set(allList) ^ set(p)

diff = list(diff)
diff.append(x)
diff = sorted(diff)

# print(diff)

ind = diff.index(x)
# print(ind)

# if x == 100:
    

a = diff[ind-1]
if x != 100:
    b = diff[ind+1]
else:
    print(a)
    exit()

ax = abs(a-x)
bx = abs(b-x)

# print(ax,bx)

if ax==bx:
    if a < b:
        print(a)
    else:
        print(b)

if ax > bx:
    print(b)
    exit()

Submission status: Runtime Error

Solution code:
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if len(num_list)!=0:
    index=num_list.index(6)
    index_left=index-1
    index_right=index+1
    value_left=x-1
    value_right=x+1
    
    for i in range(n):
        if num_list[index_left]!=value_left:
            ans=value_left
            break
        elif num_list[index_right]!=value_right:
            ans=value_right
            break
        index_left=index_left-1
        index_right=index_right+1
        value_left=value_left-1
        value_right=value_right+1

print(ans)

Submission status: Runtime Error

Solution code:
i=(input().split())
j=(input().split())
X=int(i[0])
N=int(i[1])

d=[]
e=[]
jj=[]

if N==0:
    print(X)
else:
    for a in range(len(j)):
        jj.append(int(j[a]))
            
    for b in range(max(jj)):
        if b+1 not in jj:
            d.append(abs(X-(b+1)))

    w=X+min(d)
    v=X-min(d)

    if v in jj:
        print(w)
    else:
        print(v)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

p.sort()

p0 = []
j = 0
for i in range(1,100):
    if p[j]!=i:
        p0.append(i)
    elif p[j] == i:
        j+=1
    if j == N:
        for i0 in range(i+1,100):
            p0.append(i0)
        break

p1 = [0 for i in range(len(p0))]
for i in range(len(p0)):
    p1[i] = p0[i]-X
    p1[i] = np.abs(p1[i])
    
ii = np.argmin(p1)

print(p0[ii])

Submission status: Runtime Error

Solution code:
import numpy as np
x, n = map(int, input().split())
num_list = list(map(int,input().split()))
num_list = sorted(num_list)
num_100 = list(range(1, 101))

for num in num_list:
    numbers = num_100.remove(num)

numbers1 = np.array(numbers)
numbers2 = numbers - x
numbers3 = np.abs(numbers)
min_index = numbers.argmin()
print(numbers1[min_index])

Submission status: Runtime Error

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

def main():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
        exit()
    p = set(map(int,input().split()))
    lst = set(range(1,101)) - p
    tmp = 130
    if min(lst) >= X:
        print(min(lst))
        exit()
    if max (lst) <= X:
        print(max(lst))
        exit()
    prev = min(lst)
    for s in lst:
        if abs(s - X) >= tmp:
            print(prev)
            exit()
        prev = s
        tmp = abs(s - X)
    print(max(lst))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
x,N = list(map(int,input().split(" ")))
try:
  p = list(map(int,input().split(" ")))
  sa = 1
  ans = -100
except EOFError:
  ans = x
    
while True:
  if ans != -100:
    break
  for i in range(N):
    if x-sa == p[i]:
      break
    if i == N-1:
      if x-sa != p[i]:
        ans = x-sa
  if ans != -100:
    break
  for i in range(N):
    if x+sa == p[i]:
      break
    if i == N-1:
      if x+sa != p[i]:
        ans = x+sa
  if ans != -100:
    break
  sa += 1
print(ans)

Submission status: Runtime Error

Solution code:
X,N = map(int, input().split())
p = list(map(int, input().split()))
p = sorted(p)
lista = list(range(101))
for i in p:
    if i in lista:
        lista.remove(i)
def binary_search_find_closest(data, target):
    if len(data) == 0:
        return None
    if len(data) == 1:
        return data[0]
    min_diff = float('inf')
    imin = 0
    imax = len(data) - 1
    closest_num = None
    while imin <= imax:
        imid = imin + (imax - imin) // 2
        #　中心の左右の値と目標との差を計算する。
        if imid + 1 < len(data):
            min_diff_right = abs(data[imid+1] - target)
        if imid > 0:
            min_diff_left = abs(data[imid-1] - target)
        # 最初の差と最も最小に近い値を更新する。
        if min_diff_left < min_diff:
            min_diff = min_diff_left
            closest_num = data[imid-1]
        if min_diff_right < min_diff:
            min_diff = min_diff_right
            closest_num = data[imid+1]
        # 2分探索する。
        if data[imid] < target:
            imin = imid + 1
        elif data[imid] > target:
            imax = imid -1
        else:
            return data[imid]
    return closest_num
binary_search_find_closest(lista,X)

Submission status: Runtime Error

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

tmp = [i for i in range(1, 101)]
for i in p:
  tmp.remove(i)
for i in range(len(tmp)):
  tmp[i] = abs(tmp[i] - X)

ans = 0
for i in p:
  if X-min(tmp)==i:
    ans = 1

if ans==0:
  print(X-min(tmp))
else:
  print(X+min(tmp))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(X: int, N: int, p: "List[int]"):
    ii = [i for i in range(-101,101)]
    iii = sorted(list(set(ii) - set(p)))
    idx = np.searchsorted(iii, X, side='left')
    #print(iii)
    if idx>0:
        if iii[idx]-X >= X-iii[idx-1]:
            print(iii[idx-1])
        else:
            print(iii[idx])
    else:
        print(iii[idx])
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    d = []
    c=0
    for e in p:
        d.append(abs(e-x))
    d1 = d[0]
    for i in range(len(d)):
        if d[i] < d1:
            d1 = d[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 j2 in range(1,100):
        for g2 in p:
            if z-j2 != g2:
                c +=1
                w2 = z-j2
        if c == n:
            break
        c = 0

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

Submission status: Runtime Error

Solution code:
X,N = input().split()
 
import sys
X = int(X)
N = int(N)
 
if N ==0:
  print(X)
  break
else:
  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: Runtime Error

Solution code:
X, N = map(int,input().split())
LP = [list(map(int, input().split())) for i in range(N)]

if N == 0:
    print(X)

else:
    for i in range(100):
        ans = X - i
        if ans not in LP:
            print(ans)
            break
        else:
            dans = X + i
            if dans not in LP:
                print(dans)
                break

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
q=list()
for i in range(100):
    q.append(i)

for j in range(n):
    q.remove(p[j])
min=1000
for k in range(0,100-n):
    a=x-q[k]
    if min>=abs(a):
        min=abs(a)

print(abs(min-x)+1)

Submission status: Runtime Error

Solution code:
z = list(map(int, input().split()))
x = z[0]
if z[1] == 0:
  print(x)
elif z[1] == 1:
  p = list(map(int, input().split()))
  print(p[0]-1)
else:
  p = list(map(int, input().split()))
  l = []
  for i in range(-101, 102):
    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:
X,N=map(int,input().split())
P=list(map(int,input().split()))

if N==0:
    print(X)
else:
    if X<min(P):
        ans=X
        print(ans)
    
    elif X in range(min(P),max(P)+1):
        #大した大きい数じゃないので全探索すればいい
        ans_len=200 #ひとまずの仮定
        for i in range(min(P),max(P)+1):
            if i in P:
                continue
            else:
                l=abs(X-i)
                if l < ans_len:
                    ans_len=l
                    ans=i
        print(ans)
                
    else:
        ans=X
        print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

def ForbiddenList():

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

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

    result = list(range(min(NumB)-1, max(NumB)+1, 1))

    for data in NumB:
        result.remove(data)

    idx = np.abs(np.asarray(result) - NumA[0]).argmin()

    print(result[idx])

if __name__ == '__main__':
    ForbiddenList()

Submission status: Runtime Error

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

p_list = sorted(p_list)
all_range = list(range(1, 101))
A = [i for i in all_range if i not in p_list]
B = [abs(i - X) for i in A]

low = X - min(B)
high = X + min(B)

if N == 0:
  print(X)
elif high in p_list:
  print(low)
else:
  print(high)

Submission status: Runtime Error

Solution code:
import sys

X,N = input().split()
if N == "0":
  print(X)
  sys.exit()

else:
  p = [int(e) for e in input().split()]
  p.sort()
  # print(p)
  # [4, 7, 10, 6, 5]
  X = int(X)

  f = int(p[0])
  e = int(p[-1])
  ans = 999
  for num in range(f,e):
    if num in p:
      continue
    else:
      tmp = abs(X-num)
      if tmp < ans:
        ans = tmp
        a = num

  print(a)

Submission status: Runtime Error

Solution code:
x, n = map(int,input().split())
p = [int(s) for s in input().split()]
k= 100

for r in range (1,101):
    if (r not in p):
        if (abs(x - int(r)) < k):
            A = int(r)
            k = abs(x - int(r))
if (A > x):
    if (2*x-A not in p):
        A = 2*x-A

print (A)

Submission status: Runtime Error

Solution code:
i=(input().split())
j=(input().split())
X=int(i[0])
N=int(i[1])

d=[]
e=[]
jj=[]

if N!=0:
    for s in range(len(j)):
        jj.append(int(j[s]))
            
    for a in range(max(jj)):
        if a+1 not in jj:
            d.append(abs(X-(a+1)))

    w=X+min(d)
    v=X-min(d)

    if v in jj:
        print(w)
    else:
        print(v)
else:
    print(X)

Submission status: Runtime Error

Solution code:
import bisect
a,b=map(int,input().split())
c=list(map(int,input().split()))

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

m=sorted(list(set(n)^set(c)))
bisect.insort_right(m,a)

m=sorted(list(set(m)))

if b==0:
    print(a)
elif a==100:
    print(m[m.index(a)-1])

elif abs(a-m[m.index(a)-1])<abs(a-m[m.index(a)+1]):
    print(m[m.index(a)-1])

elif abs(a-m[m.index(a)-1])==abs(a-m[m.index(a)+1]):
    print(m[m.index(a)-1])

else:
    print(m[m.index(a)+1])

Submission status: Runtime Error

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

if not nums or x not in nums:
    print(x)

nums.sort()

x_index = nums.index(x)
left_pointer, right_pointer = x_index - 1, x_index + 1
expected_small, expected_big = x - 1, x + 1

while True:
    if 0 <= left_pointer < len(nums) and expected_small != nums[left_pointer]:
        print(expected_small)
        exit()
    else:
        expected_small -= 1
        left_pointer -= 1

    if 0 <= right_pointer < len(nums) and expected_big != nums[right_pointer]:
        print(expected_big)
        exit()
    else:
        expected_big += 1
        right_pointer += 1

Submission status: Runtime Error

Solution code:
def ints(): return map(int, input().split())

import bisect

def solve():
    target, count = ints()
    if count < 1:
        return target
    excludes = sorted(ints())

    collection = set(range(0, 101))
    remain = list(collection - set(excludes))

    idx = bisect.bisect_left(remain, target)

    n = 0
    for x in (idx -1, idx, idx +1):
        if x < 0 or x > len(remain):
            continue
        if abs(abs(remain[x]) - abs(target)) < abs(abs(n) - abs(target)):
            n = remain[x]
    return n


print(solve())

Submission status: Runtime Error

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

    for i in range(1,max(p)+1):
        if x == i:
            continue
        if (i in p) == True:
            continue
    
        y1 = abs(i-x)
        if y2 > y1:
            y2 = y1
            t = i
    print(t)

Submission status: Runtime Error

Solution code:
input_list1 = input().split()
input_list1_int = [int(x) for x in input_list1]

try:
    input_list2 = input().split()
    input_list2_int = [int(x) for x in input_list2]

    num_min = min(input_list2_int)
    num_max = max(input_list2_int)

    number_list = list(range(num_min,num_max+1))
    pre_abs = 10000000

    for i in input_list2_int:
        number_list.remove(i)

    if input_list1_int[0] in number_list:
        answer = input_list1_int[0]

    else:
        for j in number_list:
            temp1 = abs(j - input_list1_int[0])
            if temp1 < pre_abs:
                pre_abs = temp1
                answer = j
        
            else:
                answer = j
                break
    print(answer)

except EOFError:
    print(input_list1_int[0])

Submission status: Runtime Error

Solution code:
import numpy as np
x, n = map(int, input().split())
num_list = list(map(int,input().split()))
num_100 = list(range(1, 101))

for num in num_list:
    numbers = num_100.remove(num)

numbers1 = np.array(numbers)
numbers2 = numbers - x
numbers3 = np.abs(numbers)
min_index = numbers.argmin()
print(numbers1[min_index])

Submission status: Runtime Error

Solution code:
import sys

x, n = map(int, input().split())
pn = list(map(int, sys.stdin.readline().rstrip().split()))

qn = set([i for i in range(1,101)]) - set(pn)

qn = list(qn)


if x-qn[0]<0:
    print(qn[0])
    exit(0)
if x-qn[-1]>=0:
    print(qn[-1])
    exit(0)

for i in range(100-n):
    if qn[i]==x:
        print(x)
        exit(0)
    elif x-qn[i+1]<0:
        if x-qn[i] <= qn[i+1]-x:
            print(qn[i])
            exit(0)
        elif x-qn[i] > qn[i+1]-x:
            print(qn[i+1])
            exit(0)

Submission status: Runtime Error

Solution code:
X,N = input().split()
 
import sys
X = int(X)
N = int(N)
 
if N ==0:
    print(X)
    break
else:
	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: Runtime Error

Solution code:
def challenge(X, numlist, vec):
  for i in range(len(numlist)):
    try:
      numlist.index(X)
    except:
      return(X)
    if vec:
      X -= 1
    else:
      X += 1

list1 = input().split()
X = int(list1[0])
N = int(list1[1])
  
if N == 0:
  print(X)
else:
  list2 = input().split()
  numlist = []
  for i in list2:
    numlist.append(int(i))

  num1 = challenge(X, numlist,True)
  num2 = challenge(X, numlist,False)
  wk1 = abs(X - num1)
  wk2 = abs(X - num2)
  if wk1 > wk2:
    print(num2)
  else:
    print(num1)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n > 0:
    P = list(map(int, input().split()))
    Q = sorted(
        [[i, abs(i - x)] for i in range(1, 101) if i not in P],
        key=lambda x:x[0])
    Q.sort(key=lambda x:x[1])
    print(Q[0][0])
else:
    print(x)

Submission status: Runtime Error

Solution code:
import numpy as np

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

if N == 0:
    print(X)
else:
    A = [i for i in range(1,101)]

    for i in P:
        A.remove(i)

    a = (np.array(A) - X)**2
    j = np.argmin(a)
    if (A[j] - X)**2 >= X**2:
        print(0)
    else:
        print(A[j])

Submission status: Runtime Error

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

try:
    p = [int(_) for _ in input().split()]
    p.sort()

    if X in p:
        index = p.index(X)
        for i in range(1, N):
            if p[index - i] != X - i:
                print(X - i)
                break
            elif p[index + i] != X + i:
                print(X + i)
                break
    else:
        print(X)


except EOFError:
    print(X)
    pass

Submission status: Runtime Error

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

def f(p):
  global X
  return p - X

p2 = list(map(f,p))

p3 = list(map(abs,p2))

OK = 2
j = 0


if min(p3) ==0:
  while(OK==2):
    j+=1
    OK = p3.count(min(p3)+j)
  if OK == 1:
    print(X-p2[p3.index(min(p3)+j)])
  else:
    print(X-j)
else:
  print(X)

Submission status: Runtime Error

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

# x, n = 10, 5
# p =  [4, 7, 10, 6, 5]
# ->9が解

# pに含まれない整数リストを、最小値-1最大値+1も含めて求める
pl = min(p)-1
pr = max(p)+1
npl = list(range(pl, pr))
np = list(set(npl) - set(p))
np.sort()

# np内で最もxに近い数値を算出する
mx = x
res = x
for k in np:
  t = abs(k - x)
  if t < mx:
    mx = t
    res = k

print(k)

Submission status: Runtime Error

Solution code:
n, ls = [int(x) for x in input().strip().split(' ')]
x = [int(x) for x in input().strip().split(' ')]
x.sort()
a = []
for y in range(1,x[-1]):
    if y not in x:
        a.append(y)
# print(a)
b = {}
for y in range(len(a)):
    b.update({a[y]: abs(n-a[y])})
print(min(b.keys(), key=(lambda k: b[k])))

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
for i in range(n):
    p = list(map(int,input().split()))
flaga = 0
flagb = 0
for i in range(n):
    for j in range(n-1):
        if x-i == p[j]:
            flaga = 1
        if x+i == p[j]:
            flagb = 1
    if(flaga == 0):
        print(x-i)
    elif(flagb == 0):
        print(x+i)
    elif(flaga == 0 and flagb == 0):
        print(x-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:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],p[p.index(max(p))]+1):
        if i  not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], p[p.index(min(p))]+1, -1):
        if i not in p:
            ans.append(i)
            break
 
    print(min(ans))

Submission status: Runtime Error

Solution code:
X,N = input().split()
 
import sys
X = int(X)
N = int(N)
 
if N ==0:
    print(X)
else:
  
    
	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
X,N = input().split()
 
import sys
X = int(X)
N = int(N)
 
if N ==0:
    print(X)
    break
else:
	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: Runtime Error

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
l = list(range(1, 100))
ll = []
if n ==0:
    print(x)
else:
    for i in p:
        l.remove(i)
    for j in range(50):
        if x-j in l:
            ll.append(x-j)
        if len(ll) != 0:
            print(min(ll))
            break
        if x+j in l:
            ll.append(x+j)
        if len(ll) != 0:
            print(min(ll))
            break

Submission status: Runtime Error

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


def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))
    assert N == len(p)
    if N == 0:
        print(X)
        exit()
    abs_list = []
    abs_list2 = list(range(-100, 100))
    abs_list2.sort()
    abs_list2 = sorted(abs_list2, key=abs)
    for i in p:
        abs_list.append(i-X)
    abs_list.sort()
    abs_list = sorted(abs_list, key=abs)
    # print(abs_list)
    # print(abs_list2)
    for i in range(len(abs_list2)):
        if abs_list[i] != abs_list2[i]:
            print(X+abs_list2[i])
            exit()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

X,N = input().split()
if N == "0":
  print(X)
  sys.exit()

p = [int(e) for e in input().split()]
p.sort()
# print(p)
# [4, 7, 10, 6, 5]
X = int(X)

f = int(p[0])
e = int(p[-1])
ans = 999
for num in range(f,e):
  if num in p:
    continue
  else:
    tmp = abs(X-num)
    if tmp < ans:
      ans = tmp
      a = num

print(a)

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)
    #     return
    # else:
    d = [abs(i-X) for i in range(1, 101) if i not in p]
    d_min = min(d)
    for i in range(1, 101):
        if i not in p:
            if abs(i-X)==d_min:
                print(i)
                return

if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
X, N = map(int,input().split())
LP = [list(map(int, input().split())) for i in range(N)]

if N == 0:
    print(X)

else:
    for i in range(1,100):
        ans = X - i
        if ans not in LP:
            print(ans)
            break
        else:
            dans = X + i
            if dans not in LP:
                print(dans)
                break

Submission status: Runtime Error

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

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

P1=sorted(P_ori)
N=list(range(1,101))
PZ=[]
for i in range(len(N)):
    if P1.count(N[i])==0:
        PZ.append(N[i])

PZ.append(X)
P2=sorted(PZ)
t=P2.index(X)

if t==0:
    print(-1)
    exit()

dist1=abs(P2[t-1]-P2[t])
dist2=abs(P2[t]-P2[t+1])
if dist1<=dist2:
    print(P2[t-1])
else:
    print(P2[t+1])

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)
        return
    else:
        d = [abs(i-X) for i in range(1, 101) if i not in p]
        d_min = min(d)
        for i in range(1, 101):
            if i not in p:
                if abs(i-X)==d_min:
                    print(i)
                    return

if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
temp1 = input().split(" ")
temp1 = [int(i) for i in temp1]
x = temp1[0]
n = temp1[1]

if not n == 0:
    temp2 = input().split(" ")
    temp2 = [int(i) for i in temp2]
else:
    temp2 = []

counter = 1
while True:
    if n == 0:
        print(x)
        break

    mx = x - counter
    px = x + counter

    if not mx in pn:
        print(mx)
        break
    if not px in pn:
        print(px)
        break

    counter += 1

Submission status: Runtime Error

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

if x not in nums:
    print(x)

nums.sort()

x_index = nums.index(x)
left_pointer, right_pointer = x_index - 1, x_index + 1
expected_small, expected_big = x - 1, x + 1

while True:
    if 0 <= left_pointer < len(nums) and expected_small != nums[left_pointer]:
        print(expected_small)
        exit()
    else:
        expected_small -= 1
        left_pointer -= 1

    if 0 <= right_pointer < len(nums) and expected_big != nums[right_pointer]:
        print(expected_big)
        exit()
    else:
        expected_big += 1
        right_pointer += 1

Submission status: Runtime Error

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

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

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

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

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

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

if length > 0:
  o_nums = list(input().split())

  def convert(arg):
    return int(arg)

  o_nums = o_nums.maps(convert)
  diffs = list()
  nums = list()
  for exclude_num in range(min(o_nums), max(o_nums)):
    if exclude_num in o_nums:
      continue
    else:
      nums.append(exclude_num)

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

  def absm(arg):
    return abs(arg)

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

  if -(nums[smallest_diff_index]) in diffs:
    print(-(nums[smallest_diff_index]))
  else:
    print(nums[smallest_diff_index])

else:
  print(target)

Submission status: Runtime Error

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

    num = []
    for i in range(1,100):
        num.append(abs(x-i))

    for i in range(n):
        num[p[i]-1] = 1000

    min = 1000
    ansnum = 0
    for i in range(len(num)):
        if min > num[i]:
            min = num[i]
            ansnum = i

    print(ansnum+1)
else:
    print(x)

Submission status: Runtime Error

Solution code:
import bisect

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

p.sort()
p= p+[p[n-1]+2]
index = bisect.bisect_left(p,x)

if n==0:
    print(x)
else:
    for i in range(n):
        # print(index-i, index+i)
        if p[max(index-i,0)] != x-i:
            print(x-i)
            break
        elif p[min(index+i,n)] != x+i:
            print(x+i)
            break
    else:
        print(p[0]-1)

Submission status: Runtime Error

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

ans = x

for i in range(100):
    tmp1 = x - i
    tmp2 = x + i
    if not tmp1 in p:
        ans = tmp1
        break
    elif not tmp2 in p:
        ans = tmp2
        break

print(ans)

Submission status: Runtime Error

Solution code:
a,b = map(int, input().split())
arr = list(map(int, input().split()))
o = -1
m = -1
if b == 0:
    print(a)
for i in range(min(arr), max(arr)):
    if i not in arr and abs(i-a) < m:
        m = abs(i-a)
        o = i
print(o)

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
m = {}
for i in range(1, 101):
    if i in P:
        continue
    ab = abs(i - X)
    m[i] = ab
min_k_list = [kv[0] for kv in m.items() if kv[1] == min(m.values())]
print(min(min_k_list))