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

if n==0:
    print(x)
p = list(range(n))
p = list(map(int, input().split()))
p_2 = list(range(n))
for i in range(n):
    p_2[i] = x-p[i]

for i in range(100):
    h = p_2.count(i)
    h_2 = p_2.count(-i)
    if h==0 and h_2!=0:
        print(x-i)
        break
     elif h!=0 and h_2==0:
        print(x+i)
        break
    elif h==0 and h_2==0:
        print(x-i)
        break

Submission status: Runtime Error

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

mini = min(dic.values())
for j in lis:
    if mini == dic[j]:
        print(j)
        break

Submission status: Runtime Error

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

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

arr.sort()
i = arr.index(x)

if not i and i != 0:
  print(x)
  exit(0)

j = 1
for _ in range(n):
  row = i - j
  high = i + j
  if row >= 0 and arr[row] != x - j:
    print(x - j)
    exit(0)
  elif high <= n-1 and arr[high] != x + j:
    print(x + j)
    exit(0)
  j += 1

print(x-1)

Submission status: Runtime Error

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

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

arr.sort()
print(arr)
i = arr.index(x)

if not i and i != 0:
  print(x)
  exit(0)

j = 1
for _ in range(n):
  row = i - j
  high = i + j
  if row >= 0 and arr[row] != x - j:
    print(x - j)
    exit(0)
  elif high <= n-1 and arr[high] != x + j:
    print(x + j)
    exit(0)
  j += 1

print(x-1)

Submission status: Runtime Error

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

arr.sort()
i = arr.index(x)

if not i:
  print(x)
  exit(0)

j = 1
for _ in range(n):
  row = i - j
  high = i + j
  if arr[row] != x - j:
    print(x - j)
    break
  elif arr[high] != x + j:
    print(x + j)
    break
  
  j += 1

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
li=list(map(int,input().split()))
i=0
while i<N+100:
  if X-i in li:
    if x+i in li:
      i=i+1
    else:
      print(X+i)
      break
  else:
    print(X-i)
    break

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
li=list(map(int,input().split()))
i=0
while i<N+100:
  if X-i in li:
    if x+i in li:
      i+=1
    else:
      print(X+i)
      break
  else:
    print(X-i)
    break

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
li=list(map(int,input().split()))
i=0
while i<10*N+100:
  if X-i in li:
    if x+i in li:
      i+=1
    else:
      print(X+i)
      break
  else:
    print(X-i)
    break

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
li=list(map(int,input().split()))
i=0
while i<10*N:
  if X-i in li:
    if x+i in li:
      i+=1
    else:
      print(X+i)
      break
  else:
    print(X-i)
    break

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
li=list(map(int,input().split()))
i=0
while i<10*N:
  if X-i in li:
    if x+i in li:
      I+=1
    else:
      print(X+i)
      break
  else:
    print(X-i)
    break

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
li=list(map(int,input().split()))
i=0
while i<10*N:
  if X-i in list:
    if x+i in list:
      I+=1
    else:
      print(X+i)
      break
  else:
    print(X-i)
    break

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import copy
import sys
x,n = map(int, input().split())
nums = list(map(int, input().split()))
nums.sort()
if len(nums) == 0:
    print(x)
    sys.exit()
index = nums.index(x)
ind = copy.deepcopy(index)
ans = 0
while True:
    if ind < 0:
        break
    if nums[ind] != x and  nums[ind+1] - nums[ind] > 2:
        ans = nums[ind+1] - 1
        break
    ind -= 1
ind = copy.deepcopy(index)
while True:
    if ind > n-1:
        break
    if nums[ind] != x and  nums[ind] - nums[ind-1] > 2:
        if abs(ans - x) > abs(nums[ind-1] + 1 - x):
            ans = nums[ind-1] + 1
            break
    ind += 1
if index == 0:
    ans = x-1
if index == n - 1:
    if ans != x - 1:
        ans = x + 1
print(ans)

Submission status: Runtime Error

Solution code:
import copy
import sys
x,n = map(int, input().split())
nums = list(map(int, input().split()))
nums.sort()
if len(nums) == 0:
    print(x)
    sys.exit()
index = nums.index(x)
ind = copy.deepcopy(index)
ans = 0
while True:
    if ind < 0:
        break
    if nums[ind] != x and  nums[ind+1] - nums[ind] > 2:
        ans = nums[ind+1] - 1
        break
    ind -= 1
ind = copy.deepcopy(index)
while True:
    if ind > n-1:
        break
    if nums[ind] != x and  nums[ind] - nums[ind-1] > 2:
        if abs(ans - x) > abs(nums[ind-1] + 1 - x):
            ans = nums[ind-1] + 1
            break
    ind += 1
if index == 0:
    ans = x - 1
if index == n-1:
    if ans != x - 1
    ans = x + 1
print(ans)

Submission status: Runtime Error

Solution code:
import copy
import sys
x,n = map(int, input().split())
nums = list(map(int, input().split()))
nums.sort()
if len(nums) == 0:
    print(x)
    sys.exit()
index = nums.index(x)
ind = copy.deepcopy(index)
ans = 0
while True:
    if ind < 0:
        break
    if nums[ind] != x and  nums[ind+1] - nums[ind] > 2:
        ans = nums[ind+1] - 1
        break
    ind -= 1
ind = copy.deepcopy(index)
while True:
    if ind > n-1:
        break
    if nums[ind] != x and  nums[ind] - nums[ind-1] > 2:
        if abs(ans - x) > abs(nums[ind-1] + 1 - x):
            ans = nums[ind-1] + 1
            break
    ind += 1
print(ans)

Submission status: Runtime Error

Solution code:
import math
X, N = list(map(lambda n : int(n), input().split(" ")))
P = list(map(lambda p : int(p), input().split(" ")))
Q = list(map(lambda p : [p, abs(X-p)], P))
Q.sort(key=lambda q: (q[1], q[0]))

cand = []
for i in range(N):
  if i == 0 and Q[0][1] != 0:
    cand.append(X)
    break
  else:
    if Q[i][1] != math.ceil(i/2):
      cand.append(X + math.ceil(i/2))
      cand.append(X - math.ceil(i/2))
      break
if len(cand) == 0:
  if N % 2 == 0:
    cand.append(X + int(N/2))
    cand.append(X - int(N/2))
  else:
    cand.append(X + int((N+1)/2))
    cand.append(X - int((N+1)/2))

print(min(list(filter(lambda c: c not in P, cand))))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
x,n = map(int,input().split())
if n == 0:
    print(x)
    sys.exit(0)
p = list(map(int,input().split()))
p.sort()
a = []
j = 0
for i in range(n):
    while (j < p[i]):
        a.append(j)
        j += 1 
    j += 1
for i in range(j,101):
    a.append(j)
    j += 1 
    
#print(a)
def solve(a,x):
    if x < a[0]:
        print(a[0])
        return
    if x > a[-1]:
        if x - a[-1] <= 101 - x:
            print(a[-1])
        else:
            print(101)
        return
    if (binary_search(a,x)):
        mid = binary_search(a,x) - 2
        minimum = abs(a[mid] - x)
        index = mid
        for i in range(1,5):
            #print(a[mid + i])
            if abs(a[mid + i] - x) < minimum:
                index = mid + i 
                minimum = abs(a[mid + i] - x)
        print(a[index])
        return
    

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

solve(a,x)

Submission status: Runtime Error

Solution code:
import bisect

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

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

Submission status: Runtime Error

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


if N == 0:
    print(X)

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

Submission status: Runtime Error

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


if N == 0:
    print(X)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

min_diff = 101
min_val = 101

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

Submission status: Runtime Error

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

# x, n = 10, 5
# p = 4, 7, 10, 6, 5

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

Submission status: Runtime Error

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

index = 0
value = abs(A[0] - X)
up_list = [0]*(N+1)
down_list = [0]*(N+1)

for i in range(N):
  if abs(A[i] - X ) < N+1:
    if A[i] - X >= 0:
      up_list[A[i]-X] = 1
    if A[i] - X <= 0:
      down_list[abs(A[i]- X)] = 1

j = 0
while True:
  if down_list[j] == 0:
    print(X-j)
    break
  if up_list[j] ==0:
    print(X+j)
    break
  if j>N+1:
    print('fail')
    break
  j+=1

Submission status: Runtime Error

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

index = 0
value = abs(A[0] - X)
up_list = [0]*(N+1)
down_list = [0]*(N+1)

for i in range(N):
  if abs(A[i] - X ) < N+1:
    if A[i] - X >= 0:
      up_list[A[i]-X] = 1
    if A[i] - X <= 0:
      down_list[abs(A[i]- X)] = 1

j = 0
while True:
  if up_list[j] ==0:
    print(X+j)
    break
  if down_list[j] == 0:
    print(X-j)
    break
  if j>N+1:
    print('fail')
    break
  j+=1

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
p = [int(i) for i in input().split()]
if N==0:
    print(X)
else:
    pN=[]
    for j in range(N):
        pj = p[j]-X
        pN.append(pj)
    pN.sort()
    p0 = pN[0]-1
    p1 = pN[N-1]+1
    list_p = list(range(p0,p1+1,1))
    result = list(set(list_p)-set(pN))
    k0 = abs(result[0])
    for k in result:
        k1 = abs(k)
        if k1<k0:
            k0 = k1
for l in result:
    if l == (-1)*k0:
        print(X-k0)
        break
else:
    print(X+k0)

Submission status: Runtime Error

Solution code:
def Qc():
    x, n = map(int, input().split())
    if 0 < n:
        p = map(int, input().split())

        targets = list(range(1, 101))
        outer = set(targets) - set(p)
        res = [abs(x - v) for v in outer]
        i = res.index(min(res))
        res = list(outer)[i]
    else:
        # 整数列がなにもない場合は自分自身が含まれていない最近値になる
        res = x
    print(res)


if __name__ == "__main__":
    Qc()

Submission status: Runtime Error

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

        targets = list(range(1, 101))
        outer = set(targets) - set(p)
        res = [abs(x - v) for v in outer]
        i = res.index(min(res))
        res = list(outer)[i]
    else:
        # 整数列がなにもない場合は自分自身が含まれていない最近値になる
        res = x
    print(res)


if __name__ == "__main__":
    Qc()

Submission status: Runtime Error

Solution code:
a = input()

t, c = int(a.split(" ")[0]), int(a.split(" ")[1])

if not c:
    print(t)

b = input()
lst = [int(x) for x in b.split(" ")]

for i in range(c):
    if t - i not in lst:
        print(t - i)
        break
    if t + i not in lst:
        print(t + i)
        break

Submission status: Runtime Error

Solution code:
a = input()
b = input()
t = int(a.split(" ")[0])
lst = [int(x) for x in b.split(" ")]
x = len(lst)
if not x:
    print(t)
for i in range(x):
    if t - i not in lst:
        print(t - i)
        break
    if t + i not in lst:
        print(t + i)
        break

Submission status: Runtime Error

Solution code:
a = input()
b = input()
t = int(a.split(" ")[0])
lst = [int(x) for x in b.split(" ")]
x = len(lst)
if not x:
  print(t)
for i in range(x):
  if t - x not in lst:
    print(t - x)
    break
  if t + x not in lst:
    print(t + x)
    break

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
p = input("").split(" ")
try:
    p = [int(i) for i in p]
    l = []
    for i in range(-100, 101):
        l.append(i)

    for i in range(N):
        if p[i] in l:
            l.remove(p[i])

    for i in range(0, 201 - N):
        n = (X - l[i]) ** 2
        if n <= (X - l[i + 1]) ** 2:
            print(l[i])
            break
        else:
            pass
except(ValueError):
    print(X)

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
p = input("").split(" ")
try:
    p = [int(i) for i in p]
    l = []
    for i in range(-100, 101):
        l.append(i)

    for i in range(N):
        if p[i] in l:
            l.remove(p[i])

    for i in range(201 - N):
        n = (X - l[i + 100]) ** 2
        if n >= (X - l[i + 99]) ** 2:
            print(l[i + 99])
            break
        else:
            pass
except(ValueError):
    print(X)

Submission status: Runtime Error

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

ans = -1

for i in range(0,102):
    if i not in p:
        if abs(i-X) < abs(ans-X):
            ans = i
print(ans)

Submission status: Runtime Error

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

s=set()
for i in range(1,101):
    s.add(i)

s=list(s-p)

a=[abs(x-i) for i in s]
print(s[a.index(min(a))])

Submission status: Runtime Error

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

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

p.append(x)

d =100

if n == 0:
    print(x)
else:
    for i in range(1,101):
        if i not in p:
            d_temp = abs(x-i)
            if d_temp < d:
                d = d_temp
                num = i
    print(num)

Submission status: Runtime Error

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

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

p.append(x)

d =100

for i in range(1,101):
    if i not in p:
        d_temp = abs(x-i)
        if d_temp < d:
            d = d_temp
            n_i = i

            
if n == 0:
    print(x)
else:
    print(n_i)

Submission status: Runtime Error

Solution code:
import io
import sys
_INPUT = """\
100 0

"""
sys.stdin = io.StringIO(_INPUT)

# ABC170
# C Forbidden List
X, N = map(int, input().split())
p = list(map(int, input().split()))
q = [-105 + i for i in range(211)]
c = 1000
for j in p:
    q.remove(j)
for k in q:
    d = abs(X - q[k])
    if d0 < c:
        A = q[k]
        c = d
print(A)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
p = map(int, input().split())
p_list = sorted(list(p), reverse=False)
dist_list = list(map(lambda y: abs(y-x), p_list))
all_list = [[]]
ans = 0
for i in range(n):
  all_list.append([p_list[i], dist_list[i]])
del all_list[0] # appendは空に追加してしまうので最初の空を削除
sort_list = sorted(all_list, key=lambda z:(z[1],z[0]))
ans = int(sort_list[0][0])
print(ans)

Submission status: Runtime Error

Solution code:
X,N = map(int, input().split())
num_list = list(map(int, input().split()))
if (len(num_list) == 0) or X not in num_list:
  print(X)
else:
  d = 1
  while True:
	if X - d not in num_list:
      print(X -d)
      break
    elif X + d not in num_list:
      print(X + d)
      break
    else:
      d += 1

Submission status: Runtime Error

Solution code:
import numpy as np

x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = np.array(list(map(int, input().split())))
    x_vec = np.ones(n)*x

    px_abs = sorted(abs(p-x))

    if px_abs[0] != 0:
        print(x)
    else:
        for i in range(1, int(n)):
            if 2*i-1>n:
                print(x-i)
            elif 2*i>n:
                print(x+i)
            else:
                if px_abs[2*i-1] != i or px_abs[2*i] != i:
                    if x-i not in p:
                        print(x-i)
                        break
                    else:
                        print(x+i)
                        break

Submission status: Runtime Error

Solution code:
import numpy as np

x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = np.array(list(map(int, input().split())))
    x_vec = np.ones(n)*x

    px_abs = sorted(abs(p-x))

    if px_abs[0] != 0:
        print(x)
    else:
        for i in range(1, int(n)):
            if px_abs[2*i-1] != i or px_abs[2*i] != i:
                if x-i not in p:
                    print(x-i)
                    break
                else:
                    print(x+i)
                    break

Submission status: Runtime Error

Solution code:
def solve():
    x, n = map(int, input().split())
    if not n:
        print(x)
        return

    ps = list(map(int, input().split()))
    flgs = [1] * 101

    for p in ps:
        flgs[p] = 0

    ansr = 101
    ansl = 101
    index = x
    while 1:
        if flgs[index] == 1:
            ansr = index
            break
        else:
            index += 1

    index = x
    while 1:
        if flgs[index] == 1:
            ansl = index
            break
        else:
            index -= 1

    if abs(ansr - x) >= abs(ansl - x):
        print(ansl)
    else:
        print(ansr)


solve()

Submission status: Runtime Error

Solution code:
# Crank
N,M=map(int, input().split())
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

if M==0:
    print(N)
else:
    check_set=set(map(int, input().split()))
    ans_set = set([i for i in range(1,101)])
    lst = list(ans_set-check_set)
    print(getNearestValue(lst, N))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

def main():

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

    listNotP = []

    if N == 0:
        ans = 0

    for i in range(0, 101):
        if i not in p:
            listNotP.append(i)

    listNotP.sort()

    for i in range(len(listNotP) - 1):
        if abs(listNotP[i] - X) < abs(listNotP[i + 1] - X):
            ans = listNotP[i]
            break

        elif abs(listNotP[i] - X) == abs(listNotP[i + 1] - X):
            ans = listNotP[i]
            break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

def main():

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

    listNotP = []

    if N == 0:
        ans = 0

    for i in range(1, 101):
        if i not in p:
            listNotP.append(i)

    listNotP.sort()

    for i in range(len(listNotP) - 1):
        if abs(listNotP[i] - X) < abs(listNotP[i + 1] - X):
            ans = listNotP[i]
            break

        elif abs(listNotP[i] - X) == abs(listNotP[i + 1] - X):
            ans = listNotP[i]
            break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
d = {i: 1 for i in p}
idx = X
while True:
    if d.get(idx) is None:
        ans_plus = idx
        break
    else:
        idx += 1

idx = X
while True:
    if d.get(idx) is None:
        ans_minus = idx
        break
    else:
        idx -= 1

if abs(X - ans_plus) < abs(X - ans_minus):
    print(ans_plus)
elif abs(X - ans_plus) > abs(X - ans_minus):
    print(ans_minus)
else:
    print(ans_minus)

Submission status: Runtime Error

Solution code:
x, n = input().split()
p = list(input().split())
ans = x
for i in range(n):
    if p.count(x - i) and p.count(x + i):
        continue
    elif p.count(x - i):
        ans = x + i
        break
    elif p.count(x + i):
        ans = x - 1
        break
    else:
        x - i + 1
        break
print(ans)

Submission status: Runtime Error

Solution code:
x, n = input().split()
p = list(input().split())
ans = x
for i in range(n):
    if p.count(x - i) and p.count(x + i):
        continue
    elif p.count(x - i):
        ans = x + i
    elif p.count(x + i):
        ans = x - 1
    else:
        x - i + 1
print(ans)

Submission status: Runtime Error

Solution code:
x, n = input().split()
p = list(input().split())
ans = x
for i in range(n):
    if (p.count(x - i) and p.count(x + i)):
        continue
    elif (p.count(x - i)):
        ans = x + i
    elif (p.count(x + i)):
        ans = x - 1
    else:
        x - i + 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
 
def Ss():
  return sys.stdin.readline().rstrip().split(' ')
 
def Is():
  ss = Ss()
  return map(int, ss) if len(ss) > 1 else int(ss[0])
 
def Xs():
  return list(Is())
 
i, n = Is()
 
xs = Xs() if n > 0 else []
 
def go(l, r, blacklist):
  if l not in blacklist:
    return l
  if r not in blacklist:
    return r
  else:
    return go(l-1, r+1, blacklist)
 
print(go(i, i, xs))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
 
def Ss():
  return sys.stdin.readline().rstrip().split(' ')
 
def Is():
  ss = Ss()
  return map(int, ss) if len(ss) > 1 else int(ss[0])
 
def Xs():
  return list(Is())
 
i, n = Is()
 
xs = Xs() if n > 0 else []
 
def go(l, r, blacklist):
  if l not in blacklist:
    return l
  if r not in blacklist:
    return r
  else:
    return go(l-1, r+1, blacklist)
 
print(go(i, xs))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

def Ss():
  return sys.stdin.readline().rstrip().split(' ')

def Is():
  ss = Ss()
  return map(int, ss) if len(ss) > 1 else int(ss[0])

def Xs():
  return list(Is())

i, n = Is()

xs = Xs() if n > 0 else []

def go(i, blacklist):
  if i not in blacklist:
    return i
  else:
    return min(go(i-1, blacklist), go(i+1, blacklist))

print(go(i, xs))

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
I=list(map(int,input().split()))
S=[]
T=[]
ans=[]
for i in range(1,101):
    S.append(i)
    if i in I:
        S.remove(i)
for j in range(len(S)):
    if j==0:
        T.append(S[0])
    elif abs(x-S[j-1])>abs(x-S[j]):
        T.clear()
        T.append(S[j])
print(min(T))

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
I=list(map(int,input().split()))
S=[]
T=[]
ans=[]
for i in range(1,101):
    S.append(i)
    if i in I:
        S.remove(i)
for j in range(len(S)-1):
    if j==0:
        T.append(S[0])
    elif abs(x-S[j])>abs(x-S[j+1]):
        T.clear()
        T.append(S[j+1])
print(min(T))

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
I=list(map(int,input().split()))
S=[]
T=[]
ans=[]
for i in range(100):
    S.append(i)
    if i in I:
        S.remove(i)
for j in range(len(S)-1):
    if j==0:
        T.append(S[0])
    elif abs(x-S[j])>abs(x-S[j+1]):
        T.clear()
        T.append(S[j+1])
print(min(T))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in input().split()]

nums = []
min_l = 1000
for i in range(1, 101):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_l:
    min_l = l
    min_num = i
  elif l >= min_l:
    break
print(min_num)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in input().split()]

nums = []
min_num = 1000
for i in range(1, 101):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_num:
    min_num = l
    nums.append(i)
  elif l > min_num:
    break
print(nums[-1])

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in k.split()]

nums = []
min_num = 1000
for i in range(1, 101):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_num:
    min_num = l
    nums.append(i)
  elif l > min_num:
    break
print(nums[-1])