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:
import bisect as bi

if __name__ == '__main__':

	x,n = map(int,input().split())
	A = list(map(int,input().split()))
	B = [i for i in range(101)]
	
	#差分を求める
	C = list(set(B) - set(A))

	#二分探索自身の位置を調べる
	ind = bi.bisect_left(C,x)

	if ind == 0:
		print(C[0])
	elif ind == x - n:
		print(C[ind])
	elif x == C[ind]:
		print(0)
	else:
		tmp_l = abs(C[ind-1] - x)
		tmp_r = abs(C[ind] - x)
		if tmp_l > tmp_r:
			print(C[ind])
		else:
			print(C[ind-1])

Submission status: Runtime Error

Solution code:
import bisect as bi

if __name__ == '__main__':

	x,n = map(int,input().split())
	A = list(map(int,input().split()))
	B = [i for i in range(101)]
	
	#差分を求める
	C = list(set(B) - set(A))
	
	#二分探索自身の位置を調べる
	ind = bi.bisect_left(C,x)

	if ind == 0:
		print(C[0])
	elif ind == x - n:
		print(C[ind])
	else:
		tmp_l = abs(C[ind-1] - x)
		tmp_r = abs(C[ind] - x)
		if tmp_l > tmp_r:
			print(C[ind])
		else:
			print(C[ind-1])

Submission status: Runtime Error

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

L=[]
for i in range(100):
    L.append(i+1)
for i in range(n):
    L.remove(P[i])

m=99

for i in range(len(L)):
    if abs(L[i]-x)<=m:
        m=abs(L[i]-x)

if n==0:
    print(x)
elif x==1 and x not in L:
    print(0)
elif x==100 and x, 99 not in L:
    print(101)
elif (x-m in L) or (x-m==0):
    print(x-m)
elif (x+m in L) or (x+m==101) :
    print(x+m)

Submission status: Runtime Error

Solution code:
import collections

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

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

def calc(a):
    return abs(a - x)

if x in l:
    l.remove(x) 
for i in p:
    if i in l:
        l.remove(i)

l2 = list(map(calc, l))
m = min(l2)

if collections.Counter(l2)[m] == 2:
    print(-m + x)
else:
    print(m + x)

Submission status: Runtime Error

Solution code:
import bisect
import collections

x, n = map(int, input().split())
p = list(map(int, input().split()))
l = [i for i in range(1, 101)]

def calc(a):
    return abs(a - x)

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

if x in l:
    l.remove(x) 
for i in p:
    if i in l:
        l.remove(i)

l2 = list(map(calc, l))
m = min(l2)

if collections.Counter(l2)[m] == 2:
    print(-m + x)
else:
    print(m + x)

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()]
  p.sort()
  ans = []
  for i in range(1,101):
    if i in p:
      continue
    b = abs(x - i)
    ans.append([i,b])
  ans = sorted(ans,key = lambda x: x[1])
  #print(ans)
  print(ans[0][0])

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()]
  p.sort()
  ans = []
  for i in range(1,101):
    if i in p:
      continue
    b = abs(x - i)
    ans.append((i,b))
  ans = sorted(ans,key = lambda x: x[1])
  #print(ans)
  print(ans[0][0])

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()]
  p.sort()
  ans = []
  for i in range(1,101):
    if i in p:
      continue
    b = abs(x - i)
    ans.append((i,b))
  ans = sorted(ans,key = lambda x: x[1])
  print(ans)
  print(ans[0][0])

Submission status: Runtime Error

Solution code:
# C - Forbidden List

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

t = -100
a = [0]*100
for p in P:
    a[p-1] = 1

d = 0
while True:
    if a[x-1-d] == 0:
        t = x-d
        break
    elif a[x-1+d] == 0:
        t = x + d
        break
    else:
        d += 1

print(t)

Submission status: Runtime Error

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

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

list = [0 for _ in range(len(L))]
for i in range(len(L)):
    list[i] = abs(X - L[i])
list = sorted(list)

if min(list) != 0:
    print(X)
    eixt()
else:
    num = 1
    cnt = 0
    for i in range(1, len(list)):
        if list[i] != num:
            break
        cnt += 1
        if cnt == 2:
            cnt = 0
            num += 1
if cnt == 0:
    print(X - num)
else:
    if X + num in L:
        print(X - num)
    else:
        print(X + num)

Submission status: Runtime Error

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

if P.len == 0:
  print(X)
else:
  for i in range(1,100):
    if P.count(X-i) == 0:
      print(X-i)
      break
    elif P.count(X+1) == 0:
      print(X+1)
      break
    else:
      continue

Submission status: Runtime Error

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

if P.len == 0:
  print(X)
else:
  for i in range(X,1):
    if P.count(X-i) == 0:
      print(X-i)
      break
    elif P.count(X+1) == 0:
      print(X+1)
      break
    else:
      continue

Submission status: Runtime Error

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

if P.len == 0:
  print(X)
else:
  for i in range(X,1):
    if P.index(X-i) == 0:
      print(X-i)
      break
    elif P.index(X+1) == 0:
      print(X+1)
      break
    else:
      continue

Submission status: Runtime Error

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

p = list(map(int,input().split()))
s = []

for i in range(101):
  if i not in p:
    s.append(i)

k = abs(x-s[0])
del s[0]
for j in range(100-n):
  if abs(x-s[j]) < k:
    k = abs(x-s[j])
  else:
    answer = s[j-1]
    break
else:
  answer = s[100-n-1]
print(answer)

Submission status: Runtime Error

Solution code:
import numpy as np
X,N = map(int,input().split())

if N ==0:
    print(X)

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

    length =np.zeros(100)
    length =list(length)

    for i in range(len(length)):
        length[i]= abs(X-i)

    for i in range(N):
        length[p[i]]=1000

    ans = length.index(min(length))
    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:
    for k in range(0,58):
        if not X-k in p:
            print(X-k)
            break 
        elif not X+k in p_list:
            print(X+k)
            break

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
X,N=map(int, input().split())
p=list(map(int,input().split()))
p.sort()    
if N==0:
    print(X)
else:
    for k in range(0,51):
        if not X-k in p:
            print(X-k)
            break 
        elif not X+k in p_list:
            print(X+k)
            break

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 9999999999
    lists = []
    if n == 0:
        print(x)
        exit()
    for i in range(-1000, 1000):
        if not i in p:
            lists.append(i)
    for i in lists:
        if ans > abs(x - i):
            ans = abs(x-i)
            m = i
     
    print(m)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 9999999999
lists = []
if n == 0:
    print(x)
    exit()
for i in range(1, 101):
    if not i in p:
        print(i)
        lists.append(i)
for i in lists:
    if ans > abs(x - i):
        ans = abs(x-i)
        m = i

print(m)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
ans = 9999999999
lists = []
for i in range(1, 101):
    if i not in p:
        lists.append(i)
for i in lists:
    if ans > abs(x - i):
        ans = abs(x-i)
        m = i

print(m)

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 = 9999999999
lists = []
for i in range(1, 101):
    if i not in p:
        lists.append(i)
for i in lists:
    if ans > abs(x - i):
        ans = abs(x-i)
        m = i

print(m)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 9999999999
lists = []
for i in range(1, 101):
    if i not in p:
        lists.append(i)
for i in lists:
    if ans > abs(x - i):
        ans = abs(x-i)
        m = i

print(m)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 9999999999
for i in range(1, 101):
    if i not in p:
        if ans > abs(x - i):
            ans = abs(x-i)
            m = i
print(m)

Submission status: Runtime Error

Solution code:
from sys import exit

x, n = map(int, input().split())
p = list(map(int, input().split()))
for d in range(x+1): #0に達した時点で0を出力して終了するので、大きい側は気にしなくてよい
    for d in [-1, 1]:
        a = x + i*s
        if not a in p:
            print(a)
            exit()

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
min = 100
sa = 0
for i in range(100):
    if i in p:
        continue
    sa = abs(x - i)
    if min == sa:
        break
    elif min > sa:
        min = sa
        champ = i
            
print(champ)

Submission status: Runtime Error

Solution code:
def abc170_c_1():
    """
    もうちょいコンパクトに書いてみる
    """
    def solve():
        x, n = map(int, input().split(' '))
        if n == 0:
            return x

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

        search_range_min = min(min(p), x) - 1
        search_range_max = max(max(p), x) + 1
        search_values = [i for i in range(search_range_min, search_range_max + 1) if i not in p]

        # min関数のkeyにxとの差の絶対値を直接渡してその値の最小値を取得してしまう。
        ans = min(search_values, key=lambda a: (abs(a - x)), x)

        # こっちはたぶん絶対値の差が同じ時にリストの先にあるほうをとってしまうので結果バグっている気がする
        # ans = min(search_values, key=lambda a: abs(a - x))

        return ans

    print(solve())

if __name__ == '__main__':
    abc170_c_1()

Submission status: Runtime Error

Solution code:
import sys
import os
f = open('03_C - Forbidden List.txt', 'r')
sys.stdin = f

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

Submission status: Runtime Error

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

for i in range(-5,105):
  if max(x,ans)-min(x,ans) > max(i,x) -min(i,x):
    if i in p:
      ans = ans
    else:
      ans = i
print(ans)

Submission status: Runtime Error

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

for i in range(105):
  if (max(ans, x) - min(ans,x)) > (max(x,i) - min(x,i)):
    if i in p:
      ans = ans
    else:
      ans = i

print(ans)

Submission status: Runtime Error

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

for i in range(1,101):
  if (max(ans, x) - min(ans,x)) > (max(x,i) - min(x,i)):
    if i in p:
      ans = ans
    else:
      ans = i

print(ans)

Submission status: Runtime Error

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

for i in range(101):
  if (max(ans, x) - min(ans,x)) > (max(x,i) - min(x,i)):
    if i in p:
      ans = ans
    else:
      ans = i

print(ans)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
l = sorted(p)
new = []
t = x in l

if n == 0: 
#t == False:
#re = x #n = 0でよかった。ここでは、listの中にxがなかったときにreにxを入れている。
else:
    for i in range(len(l)):
        TorF_1 = x + i + 1 in l
        TorF_2 = x - i - 1 in l
        if TorF_1 == False:
            re = x + i + 1
            break
        elif TorF_2 == False:
            re = x - i - 1
            break

print(re)

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, rst = -1, 0
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = 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())
p=list(map(int,input().split()))
q=[int(x) for x in range(1,101) if x not in p]
l=len(q)
a=abs(q[0]-X)
m=q[0]
for i in range(l):
    if a>abs(q[i]-X):
        a=abs(q[i]-X)
        m=q[i]
print(m)

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
q=[int(x) for x in range(1,101) if x not in p]
l=len(q)
a=abs(q[0]-X)
m=0
for i in range(l):
    if a>abs(q[i]-X):
        a=abs(q[i]-X)
        m=q[i]
print(m)

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
q=[int(x) for x in range(1,101) if x not in p]
print(q)
l=len(q)
a=abs(q[0]-X)
m=0
for i in range(l):
    if a>abs(q[i]-X):
        a=q[i]-X
        m=q[i]
print(m)

Submission status: Runtime Error

Solution code:
def py():
  x, n = map(int, input().split())
  p = list(map(int, input().split()))
  if p == []:
    print(x)
    return
  list0=[]
  for i in range(1,101):
    list0.append(i)
  for j in p:
    list0.remove(j)
  list1=[]
  for i in list0:
    list1.append(abs(x-i))
  if x-min(list1) in list0:
    print(x-min(list1))
  else:
    print(x+min(list1))
    
py()

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
if N!=0:
  plist =list(map(int,input().split()))
  print (plist)
  #maxN = max(plist)
  maxN = 100
  Anslist =[i for i in range(X+1)]
  #print (Anslist)
  for i in range(len(plist)):
    Anslist.remove(plist[i])
  Anslist.remove(0)
  #print(Anslist)

  ans = 0
  min=100
  for i in range(len(Anslist)):
    if min>abs(X-Anslist[i]):
      min = abs(X-Anslist[i])
      ans = Anslist[i]
  print(ans)
else :print(X)

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
maxN = 100
if N!=0:
  plist =list(map(int,input().split()))
  #maxN = max(plist)
  Anslist =[i for i in range(100)]
  #print (Anslist)
  for i in range(len(plist)):
    Anslist.remove(plist[i])
  Anslist.remove(0)
  #print(Anslist)

  ans = 0
  min=100
  for i in range(len(Anslist)):
    if min>abs(X-Anslist[i]):
      min = abs(X-Anslist[i])
      ans = Anslist[i]
  print(ans)
else :print(X)

Submission status: Runtime Error

Solution code:
def run():
	X, N = [int(v) for v in input().rstrip().split()]
	p = []
	if N > 0:
		p = [int(v) for v in input().rstrip().split()]

	i = -1
	try:
		i = p.index(X)
	except ValueError:
		pass

	if i == -1:
		# not contained	
		return X

	d1 = {}
	for k in range(1, 101):
		d1[k] = k

	for v in p:
		del d1[v]

	l2 = sorted(list(d1.keys()))

	l2.append(X)
	l2.sort()
	i = l2.index(X)

	r = 0
	if i == 0:
		r = l2[1]
	elif (i + 1) == len(l2):
		r = l2[-2]
	else:
		v1 = l2[i + 1] - X
		v2 = X - l2[i - 1]
		if v1 < v2 :
			r = l2[i + 1]
		elif v1 > v2 :
			r = l2[i - 1]
		else:
			# v1 == v2
			r = l2[i - 1]


	return r

r = run()
print(r)

Submission status: Runtime Error

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
if len(p) == 0:
    print(x)
elif max(p) < x or x < min(p):
    print(x)
else:
    q = list(range(min(p),max(p)+1))
    r = list(set(q)-set(p))
    m = 10**9
    for i in r:
        if abs(i-x) < m:
            m = abs(i-x)
            j = i
    print(j)

Submission status: Runtime Error

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

for d in range(x + 1):
    for s in [-1, +1]:
        a = x + s * d
        if p.count(a) == 0:
            print(a)
            exit(0)

Submission status: Runtime Error

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

P.sort()
P.append(101)

excluded = P.pop(0)

ans, absolute = None, 101

for i in range(102):
    if i == excluded:
        excluded = P.pop(0)
    else:
        if abs(i - x) < absolute:
            ans = i
            absolute = abs(i - x)
    
print(ans)

Submission status: Runtime Error

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

P.sort()
P.append(101)

excluded = P.pop(0)

ans, absolute = None, 101

for i in range(0, 102):
    if i == excluded:
        excluded = P.pop(0)
    else:
        if abs(i - x) < absolute:
            ans = i
            absolute = abs(i - x)
    
print(ans)

Submission status: Runtime Error

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

P.sort()
P.append(101)

excluded = P.pop(0)

ans, absolute = None, 101

for i in range(1, 101):
    if i == excluded:
        excluded = P.pop(0)
    else:
        if abs(i - x) < absolute:
            ans = i
            absolute = abs(i - x)
    
print(ans)

Submission status: Runtime Error

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

P.sort()
P.append(101)

excluded = P.pop(0)

ans, absolute = None, 101

for i in range(1, 101):
    if i == excluded:
        excluded = P.pop(0)
    else:
        if abs(i - x) < absolute:
            ans = i
            absolute = abs(i - x)
    
print(ans)

Submission status: Runtime Error

Solution code:
X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
integer = [i+1 for i in range(100)]
for i in range(N):
   integer.remove(p[i])
integer = map(lambda x: x - X, integer)
l = len(integer)
ans = -200
for i in range(l):
   if abs(ans) > abs(integer[i]):
      ans = integer[i]
print(ans + X)

Submission status: Runtime Error

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

p = list(map(int, input().split()))
#p = [4,7,10,6,5]
if N == 0:
    print(X)
    exit()

p.sort()
all = [i for i in range(1,101)]
for i in p:
    if i in all:
        all.remove(i)
if len(all) == 0
    exit()
min = 101
min_k = 0
for k,i in enumerate(all):
    tmp = abs(X-i)
    if min > tmp:
        min = tmp
        min_k =k
print(all[min_k])

Submission status: Runtime Error

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

p = list(map(int, input().split()))
#p = [4,7,10,6,5]
if N == 0:
    print(X)
    exit()

p.sort()
all = [i for i in range(1,101)]

for i in p:
    if i in all:
        all.remove(i)
min = 101
k = 101
for k,i in enumerate(all):
    tmp = abs(X-i)
    if min > tmp:
        min = tmp
        min_k =k

print(all[min_k])

Submission status: Runtime Error

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

L = sorted([abs(X-p) for p in P])
if 0 not in L :
    print(X)
    exit()

DL = list(set([x for x in L if L.count(x) > 1]))

ans_abs = 1
for i,x in enumerate(DL) :
    if x == i+1 :
        ans_abs += 1
    else :
        break

if X-ans_abs in P :
    print(X+ans_abs)
else :
    print(X-ans_abs)

Submission status: Runtime Error

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

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

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

if X not in P:
  print(X)
else:
  for i in range(X-1,-2,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,102):
    if j not in P:
      b = abs(j - X)
      break
      
if a <= b:
  print(i)
else:
  print(j)

Submission status: Runtime Error

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

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

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

if X not in P:
  print(X)
else:
  for i in range(X-1,min(P)-2,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,max(P)+2):
    if j not in P:
      b = abs(j - X)
      break
      
if a <= b:
  print(i)
else:
  print(j)

Submission status: Runtime Error

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

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

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

if X not in P:
  print(X)
else:
  a = float("inf")
  b = float("inf")
  for i in range(X-1,0,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,max(P)+2):
    if j not in P:
      b = abs(j - X)
      break
      
if a <= b:
  print(i)
else:
  print(j)

Submission status: Runtime Error

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

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

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

if X not in P:
  print(X)
else:
  for i in range(X-1,0,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,max(P)+2):
    if j not in P:
      b = abs(j - X)
      break
      
if a <= b:
  print(i)
else:
  print(j)

Submission status: Runtime Error

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

if P == [] or X not in P:
  print(X)
else:
  for i in range(X-1,0,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,max(P)+2):
    if j not in P:
      b = abs(j - X)
      break
      
if a <= b:
  print(i)
else:
  print(j)

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
if n == 0:
  ans = x
else:
  p = [int(i.strip()) for i in input().split()]
  for i in range(n):
    ch_1 = x-i
    ch_2 = x+i
    if p.count(ch_1) == 0:
      ans = ch_1
      break
    elif p.count(ch_2) == 0:
      ans = ch_2
      break
    else:
      ans = x
print(p)

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
if n == 0:
  ans = x
else:
  p = [int(i.strip()) for i in input().split()]
  for i in range(n):
    ch_1 = x-i
    ch_2 = x+i
    if p.count(ch_1) == 0:
      ans = ch_1
      break
    elif p.count(ch_2) == 0:
      ans = ch_2
      break
print(ans)

Submission status: Runtime Error

Solution code:
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
plus_flag = 1
minus_flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
plus_index = key_index
minus_index = key_index

if n == 0:
    print(x)
else:
    while(1):
        if minus_index <= 0:
            minus_flag = 0
            
        if minus_flag == 1:
            if pN[minus_index] - 1 != pN[minus_index-1]:
                print(pN[minus_index] - 1)
                break
            else:
                minus_index = minus_index - 1

        

        if plus_index >= n:
                    plus_flag = 0

        if plus_flag == 1:
            if pN[plus_index] + 1 != pN[plus_index+1]:
                print(pN[plus_index] + 1)
                break
            else:
                plus_index = plus_index + 1

Submission status: Runtime Error

Solution code:
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
plus_flag = 1
minus_flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
plus_index = key_index
minus_index = key_index
print(key_index)
if n == 0:
    print(x)
else:
    while(1):
        if minus_index <= 0:
            minus_flag = 0
            
        if minus_flag == 1:
            if pN[minus_index] - 1 != pN[minus_index-1]:
                print(pN[minus_index] - 1)
                break
            else:
                minus_index = minus_index - 1

        

        if plus_index >= n:
                    plus_flag = 0

        if plus_flag == 1:
            if pN[plus_index] + 1 != pN[plus_index+1]:
                print(pN[plus_index] + 1)
                break
            else:
                plus_index = plus_index + 1

Submission status: Runtime Error

Solution code:
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
plus_flag = 1
minus_flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
plus_index = key_index
minus_index = key_index

if n == 0:
    print(x)
else:
    while(1):
        if minus_index <= 0:
            minus_flag = 0
            
        if minus_flag == 1:
            if pN[minus_index] - 1 != pN[minus_index-1]:
                print(pN[minus_index] - 1)
                break
            else:
                minus_index = minus_index + 1

        

        if plus_index == n:
                    plus_flag = 0

        if plus_flag == 1:
            if pN[plus_index] + 1 != pN[plus_index+1]:
                print(pN[plus_index] + 1)
                break
            else:
                plus_index = plus_index + 1

Submission status: Runtime Error

Solution code:
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
plus_flag = 1
minus_flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
plus_index = key_index
minus_index = key_index
if n == 0:
    print(x)
else:
    while(1):
        if minus_flag == 1:
            if pN[minus_index] - 1 != pN[minus_index-1]:
                print(pN[minus_index] - 1)
                break
            else:
                minus_index = minus_index + 1

        if minus_index == 0:
            minus_flag = 0



        if plus_flag == 1:
            if pN[plus_index] + 1 != pN[plus_index+1]:
                print(pN[plus_index] + 1)
                break
            else:
                plus_index = plus_index + 1

        if plus_index == n:
            plus_flag = 0

Submission status: Runtime Error

Solution code:
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
plus_flag = 1
minus_flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
plus_index = key_index
minus_index = key_index
if n == 0:
    print(x)
else:
    while(1):
        if minus_flag == 1:
            if pN[key_index] - 1 != pN[key_index-1]:
                print(pN[key_index] - 1)
                break
            else:
                minus_index = minus_index + 1

        if minus_index == 0:
            minus_flag = 0



        if plus_flag == 1:
            if pN[key_index] + 1 != pN[key_index+1]:
                print(pN[key_index] + 1)
                break
            else:
                plus_index = plus_index + 1

        if plus_index == n:
            plus_flag = 0

Submission status: Runtime Error

Solution code:
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
if n == 0:
    print(x)
else:
    while(1):
        if pN[key_index] - 1 != pN[key_index-1]:
            print(pN[key_index] - 1)
            break
        if flag == 1:
            if pN[key_index] + 1 != pN[key_index+1]:
                print(pN[key_index] + 1)
                break
        key_index = key_index + 1
        if(key_index >= n):
            flag = 0

Submission status: Runtime Error

Solution code:
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
pN.sort()
key_index = bisect.bisect(pN, x) - 1
if n == 0:
    print(x)
else:
    while(1):
        if pN[key_index] - 1 != pN[key_index-1]:
            print(pN[key_index] - 1)
            break

        if pN[key_index] + 1 != pN[key_index+1]:
            print(pN[key_index] + 1)
            break
        key_index = key_index + 1

Submission status: Runtime Error

Solution code:
import bisect


def abc170c_forbidden_list():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    if n == 0:
        print(x)
        return
    p.sort()
    for i in range(100):
        idx = bisect.bisect_left(p, x - i)
        if p[idx] != x - i:
            print(x - i)
            return
        idx = bisect.bisect_left(p, x + i)
        if p[idx] != x + i:
            print(x + i)
            return

abc170c_forbidden_list()

Submission status: Runtime Error

Solution code:
N=int(input())
ans=""
check="abcdefghijklmnopqrstuvwxyz"

while N!=0:
	N-=1
	ans+=check[N%26]
	N=N//26

print(ans[::-1])
"""
while N>0:
	N-=1
	ans+=chr(ord("a")+ N%26)
	N//=26
print(ans[::-1])
"""

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    p = list(map(int,input().split()))
    absolute = list(map(lambda i:abs(i-x),p))
    if 0 not in absolute:
        print(x)
    else:
        ab = set(absolute)
        i = 1
        while i < 100:
            if absolute.count(i) == 2:
                i += 1
            else:
                opt = set([x-i,x+i])
                ans = opt - ab
                break

        print(min(ans))

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
if n == 0 or 0 not in absolute:
    print(x)
else:
    p = list(map(int,input().split()))
    absolute = list(map(lambda i:abs(i-x),p))
    ab = set(absolute)
    i = 1
    while i < 100:
        if absolute.count(i) == 2:
            i += 1
        else:
            opt = set([x-i,x+i])
            ans = opt - ab
            break

    print(min(ans))

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
absolute = list(map(lambda i:abs(i-x),p))
ab = set(absolute)

if n == 0 or 0 not in absolute:
    print(x)
else:
    i = 1
    while i < 100:
        if absolute.count(i) == 2:
            i += 1
        else:
            opt = set([x-i,x+i])
            ans = opt - ab
            break

print(min(ans))