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

pl=[]
if n==0:
    print(x)
else:
    for i in range(n):
        pl.append(abs(p[i]-x))
    sort_p=sorted(pl)
    #print(sort_p)
    if n==1:
        if sort_p[0]!=0:
            print(x)
        else:
            print(x-1)
    else:
        num=0
        if sort_p[0]!=0:
            print(x)
        else:
            for i in range(1,n):
                if i%2!=0:
                    num+=1
                if sort_p[i]!=num:
                    ans=num
                    break
            small=x-ans
            big=x+ans
            if (small not in p)&(big not in p):
                print(small)
            elif small in p:
                print(big)
            elif big in p:
                print(small)

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

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:
#!/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
    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 = map(int, input().split())
if n != 0:
  p = list(map(int, input().split()))

# 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:
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[1])
    print(Q[0][0])
else:
    print(x)

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(1,101)]
    iii = list(set(ii) - set(p))
    idx = np.searchsorted(iii, X, side='left')
    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 = list(map(int, input().split()))
p = list(map(int, input().split()))

sample = list(range(0,max(p)+2)) 
reject = list(set(p))

for i in range(len(reject)):
    sample.remove(reject[i])

champ = abs(sample[0] - x)
ans = sample[0]
for i in range(1, len(sample)):
    if abs(sample[i] - x) < champ:
        champ = abs(sample[i] - x)
        ans = sample[i]
    elif abs(sample[i] - x) == champ:
        if ans >= sample[i]:
            ans = sample[i]
        else:
            pass
    else:
        pass
    
print(ans)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n == 100:
    print("")
elif n > 0:
    ps = list(map(int, input().split()))
else:
    print(x)
nums = [n for n in range(1, 101) if n not in ps]

abs_plus = sorted([n-x for n in nums if n-x >= 0])
abs_minus = sorted([-(n-x) for n in nums if n-x < 0])
if abs_plus == []:
    print(x-abs_minus[0])
elif abs_minus == []:
    print(x+abs_plus[0])
elif abs_plus[0] >= abs_minus[0]:
    print(x-abs_minus[0])
else:
    print(x+abs_plus[0])

Submission status: Runtime Error

Solution code:
def actual(X, N, P):
    for i in range(X, -1, -1):
        if i not in P:
            left = i
            break

    for i in range(X, 101):
        if i not in P:
            right = i
            break

    if abs(left - X) <= abs(right - X):
        return left
    else:
        return right


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

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

Submission status: Runtime Error

Solution code:
x,length = map(int, input().split())
if length != 0:
  l = list(map(int, input().split()))
  l_b = list(range(1,101))
  diff = list(set(l) ^ set(l_b))
  sa = []
  for i in range(len(diff)):
    sa.append(abs(diff[i]-x))
  index = sa.index(min(sa))
  print(diff[index])
else:
  print(x)

Submission status: Runtime Error

Solution code:
import sys

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

a = []
b = []

for i in range(1, 100):
    if i not in p:
        a.append(abs(x - i))
        b.append(i)
ans = min(a)
bb = a.index(ans)
print(b[bb])

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
print(p2,p3)

if min(p3) ==0:
  while(OK==2):
    j+=1
    
    OK = p3.count(min(p3)+j)

  print(X-p2[p3.index(min(p3)+j)])
      
else:
  print(X)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect_right
def main():
    x,n=map(int,input().split())
    if n==0:
        print(x)
        sys.exit()
    P=list(map(int,input().split()))
    set_P=set(range(101))
    set_P-=set(P)
    P=list(set_P)
    P.sort()
    p_left,p_right=-10,1000
    for p in P:
        if p>=x:
            P_right=p
            break
        P_left=p
    if abs(P_left-x)<=abs(P_right-x):
        print(P_left)
    else:
        print(P_right)

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
XX, N = map(int, input().split(" "))
if N == 0:
  print(X)
  exit()
else:
  p = list(map(int, input().split(" ")))
  c = -1
  for i in range(100):
    if i+1 not in p:
      if abs(X-(i+1)) < abs(X-c):
        c = i+1
      else:
        print(c)
        exit()

Submission status: Runtime Error

Solution code:
x, y = map(int, input().split())
if(y != 0):
  p = list(map(int, input().split()))
  p.sort()  
  nonp = list()
  for i in range(p[0], p[-1] + 1):
    if(i not in p):
      nonp.append(i)
  print(min(nonp, key = lambda d:abs(d-x)))
else:
  print(x)

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))]):
        if i  not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], p[p.index(min(p))], -1):
        if i not in p:
            ans.append(i)
            break
 
    print(min(ans))

Submission status: Runtime Error

Solution code:
a = input().split()
X = int(a[0])
N = int(a[1])
OK = []
list = []
if N ==0:
    print(X)
else:
    P = input().split()
    for i in range(100):
        OK.append(str(i + 1))
    for i in range(len(P)):
        OK.remove(P[i])
    for i in range(len(OK)):
        list.append(abs(int(OK[i]) - X))
    Y = list.index(min(list))
    print(OK[Y])

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)

a = diff[ind-1]
b = diff[ind+1]

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:
x,n=map(int,input().split())
try:
  a=list(map(int,input().split()))
except:
  rr=0
  





if n==0:
  print(x)
  
a=sorted(a)

if x<a[0]:
  print(x)
if x>a[-1]:
  print(x)
  
b=list(range((a[0]),(a[-1]+1)))

for n in range(n):
  b.remove(a[n])
  
f=len(b)


d=abs(x-int(b[0]))
ans=b[0]

for n in range(f):
  c=abs(x-int(b[n]))
  if d>c:
    ans=b[n]
    d=c
  
print(ans)

Submission status: Runtime Error

Solution code:
def main():
  x, n = map(int, input().split())
  if n == 0:
    return print(x)
  else:
    li = list(map(int, input().split()))

    newli = [0]*len(li)
    for i in range(len(li)):
      newli[i]= abs(x-li[i])

    for i in range(min(newli), max(newli) + 1):
      if not i in newli:
        val = i
        break

    if x in li:
      return print(x+val-2)
    else:
      return print(x+val)


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()))
  absv = x
  for i in range(-1, 100):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)

Submission status: Runtime Error

Solution code:
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

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)
    elif abs(w1-x) >= abs(w2-x):
        print(w2)

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    x, n = [int(x) for x in input().split()]
    if n > 0:
        ps = [int(x) for x in input().split()]
        s = set(list(range(1, 101)))
        notps = s - set(ps)
        ps = np.array(list(notps))
        ps = ps - x
        ps = [abs(p) for p in ps]
        ps.sort()
        m = ps[0]
        if x - m in notps:
            print(x - m)
            return
        else:
            print(x + m)
            return
    else:
        print(x)
    

main()

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())
if n==0:
    print(x)
else:
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    while i < n and p[i] < x:
        i += 1

    if p[i] != x:
        print(x)
    else:
        j = 1
        up = x+j
        down = x-j
        while True:
            if p[i-j] != x-j:
                print(x-j)
                break
            if p[i+j] != x+j:
                print(x+j)
                break
            j += 1

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n != 0:
  n = list(map(int, input().split()))
  min_n = abs(x - min(n))
  max_n = max(n) - x
  ans = []
  for i in range(1, max(min_n, max_n) + 1):
    if n.count(x + i) == 0:
      ans.append(x + i)

    if n.count(x - i) == 0:
      ans.append(x - i)
    
    if ans != []:
      break

  print(min(ans))
else:
  print(x)

Submission status: Runtime Error

Solution code:
import sys

def Forbidden_List():
    X ,N = map(int, input().split())
    
    if N == 0:
        return X
    
    p = list(map(int, input().split()))

    other_integer = [i for i in range(min(p)+1, max(p))]

    other_integer = set(other_integer) - set(p)

    min_abs = sys.maxsize
    for i in other_integer:
        next_min = abs(i - X)
        #print(next_min, min_abs)
        if next_min < min_abs:
            min_num = i
            min_abs = next_min
        else:
            break
    return min_num

print(Forbidden_List())

Submission status: Runtime Error

Solution code:
def readInt():
    return list(map(int,input().split()))
    
x,n = readInt()
p = list()
a = []
if n:
    p = readInt()
    p_r = [int(i) for i in range(1,200)]
    for i in p:
        p_r.remove(i)
    # print(p_r)
    
    
    for i in range(200-x):
        dif = abs(p_r[i]-x)
        a.append(dif)
    # print(a)
    print(p_r[a.index(min(a))])
else:
    print(0)

Submission status: Runtime Error

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

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

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:
X,N = input().split()
 
import sys
X = int(X)
N = int(N)
 
if N ==0:
    print(X)
    sys.exit()
    
n = input().split()
n = [int(s) for s in n]
 
for i in range(1,N+1):
    if X -i not in n:
        print(X-i)
        break
    elif X + i not in n:
        print(X+i)
        break
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

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
try:
    p=list(map(int,input().split()))
    p.sort()
    min=abs(p[n-1])
    for i in range(p[0],p[n-1]):
        if i not in p:
            if min>abs(i-x):
                min=abs(i-x)
                ans=i
                if ans>x and x-min not in p:
                    ans-=min
except:
    ans=x

print(ans)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n > 0:
    ps = list(map(int, input().split()))
else:
    ps = []
nums = [n for n in range(1, 101) if n not in ps]

if x in nums:
    print(x)
else:
    abs_plus = sorted([n-x for n in nums if n-x >= 0])
    abs_minus = sorted([-(n-x) for n in nums if n-x < 0])
    if abs_plus == []:
        print(x-abs_minus[0])
    elif abs_minus == []:
        print(x+abs_plus[0])
    elif abs_plus[0] >= abs_minus[0]:
        print(x-abs_minus[0])
    else:
        print(x+abs_plus[0])

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

if N==0:
    _=input()
    print(X)

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

d=0
while 1:
    d+=1
    if X-d not in  Ps:
        print(X-d)
        break
    elif X+d not in Ps:
        print(X+d)
        break

Submission status: Runtime Error

Solution code:
#C
X,N = map(int,input().split())
p = list(map(int,input().split()))
r = max(100,max(p),abs(min(p)))
for i in range(max(min(min(p)-2,-1),101),min(min(p)-2,-1),-1):
    if i in p:
        pass
    else:
        if abs(r-X) >= abs(i-X):
            r = i
        else:
            pass
print(r)

Submission status: Runtime Error

Solution code:
z = list(map(int, input().split()))
x = z[0]
if z[1] == 0:
  print(x)
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())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  for i in range(1, 100):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)

Submission status: Runtime Error

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


  
if x not in i:
  print(x)
  break
  
else:
  p = 1
  while True:
    z = x - p
    if z not in i:
      print(z)
      break
        
    z = x + p
    if z not in i:
      print(z)
      break
        
    p = p +1

Submission status: Runtime Error

Solution code:
def actual(X, N, P):
    for i in range(X, -1, -1):
        if i not in P:
            left = i
            break

    for i in range(X, 101):
        if i not in P:
            right = i
            break

    if abs(left - X) <= abs(right - X):
        return left
    else:
        return right


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

if P == '':
    print(X)
else:
    P = list(map(int, P.split()))
    print(actual(X, N, P))

Submission status: Runtime Error

Solution code:
import numpy as np
X,N = map(int, input().split())
p = list(map(int, input().split()))
all_num = list(range(1,11))

mi = 1000
for i in p:
    all_num.remove(i)

least = []
for i in all_num:
    if abs(X-i) < mi:
        least = []
        mi = abs(X-i)
        least.append(i)
    elif abs(X-i) == mi:
        least.append(i)
if least != []:
    print(sorted(least)[0])
else:
    print()

Submission status: Runtime Error

Solution code:
import numpy as np
X, N = (int(i) for i in input().split())
p = sorted([int(i) for i in input().split()])
if X in p:
    s = p.index(X)
    i = 0
    while ((s-i)>=0) or ((s+i)<N):
        if p[s-i] != (X-i):
            print(X-i)
            break
        if p[s+i] != (X+i):
            print(X+i)
            break
        i = i + 1
    else:
        print(p[0]-1)
else:
    print(X)

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()
    y = 0

    for i in range(n):
        if p[i] <= x:
            y = i
            if i != n-1 and x < p[i+1]:
                break 

    i = 0
    while 1 == 1:
        if 0 <= y - i and x - i != p[y - i]:
            print(x - i)
            break
        if x + i != p[y + i]:
            print(x + i)
            break
        i = i + 1

Submission status: Runtime Error

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

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

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


ans = 10 *100000000000

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

Submission status: Runtime Error

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

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

dif = 100
ans = 0

for i in range(min(p) - 1, max(p) + 2):
    if not (i in p):
        if dif > abs(x - i):
            dif = abs(x - i)
            ans = i

print(ans)

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)+1):
    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 nums:
    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:
    print(X)
    exit()
p = list(map(int, input().split()))
p = sorted(p)

ans = 101
ls = []


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

ans = 101
ls = []

if N == 0:
    print(X)
else:
    for i in range(1, 100):
        if i not in p:
            ls.append(i)
    ls.append(X)
    ls = sorted(ls)
    for i in range(len(ls)):
        if ls[i] == X:
            if X - ls[i - 1] <= ls[i + 1] - X:
                print(ls[i - 1])
                break
            else:
                print(ls[i + 1])
                break

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]
# ->9が解

# pに含まれない整数リストを、最小値-1最大値+1も含めて求める
p.sort()
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:
#C
X,N = map(int,input().split())
p = list(map(int,input().split()))
r = (max(100,max(p),abs(min(p))))
for i in range(101,min(min(p)-2,-1),-1):
    if i in p:
        pass
    else:
        if abs(r-X) >= abs(i-X):
            r = i
        else:
            pass
print(r)

Submission status: Runtime Error

Solution code:
oin = input()
x, n = int(oin.split(" ")[0]), int(oin.split(" ")[1])
p = input().split(" ")
xpo = x+1
xdetect = list(range(1, 101))
if n == 0:
  print(x)
  exit()
if x == 1:
  print(0)
import numpy as np 
def closest(lst, K): 
     lst = np.asarray(lst) 
     idx = (np.abs(lst - K)).argmin()
     return lst[idx]
for b in p:
  try:
    xdetect.remove(int(b))
  except ValueError:
    continue
print(closest(xdetect, x))

Submission status: Runtime Error

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

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

P_set = list(set(P))
#print(P_set)
#print(P_set[1])

ans_chk = 0

if ( X < P[0] or X > P[N-1] ):
  print(X)
  ans_chk = 1

if ( ans_chk==0 ):
  for i in range(len(P)):
    if ( P_set[i] == X ):
      X_i = i
      break
    elif ( P_set[i] > X ):
      print(X)
      ans_chk = 1
      break

if ( ans_chk==0 ):
  
  if ( X_i >= N-(X_i+1) ):
    M = N-(X_i+1)
    temp_ans = X + N-(X_i+1) +1
  else:
    M = X_i
    temp_ans = X - X_i -1
  
  for i in range(1,M+1):
    if ( P_set[ X_i -i ] != X-i ):
      print(X-i)
      ans_chk = 1
      break
    elif ( P_set[ X_i +i ] != X+i ):
      print(X+i)
      ans_chk = 1
      break

if ( ans_chk==0 ):
  print(temp_ans)

Submission status: Runtime Error

Solution code:
a,b = 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()))

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

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:
X, N = map(int,input().split())
p = list(map(int, input().split()))
#print(p)
p.sort()
dis = p[0] - X
ans_1 = X
ans_2 = X
for pi in p :
  if pi == ans_1:
    ans_1 += 1

p.reverse()
for pi in p:
  if pi == ans_2:
    ans_2 -= 1

ans = X
if abs(ans_1 - X) < abs(ans_2 - X):
  ans = ans_1
elif ans_1 - X == -abs(ans_2 - X):
  ans = ans_1
else:
  ans = ans_2
print(ans)

Submission status: Runtime Error

Solution code:
for i in range(100):
    plus_abs=X+i
    minus_abs=X-i

    for j in range(N):
        if plus_abs == int(list2[j]):
           plus_abs=1000


    for k in range(N):
        if minus_abs == int(list2[k]):
            minus_abs=1000

    if plus_abs !=1000 or minus_abs!=1000:
        if plus_abs >= minus_abs:
            result = minus_abs
        else:
            result = plus_abs

        print(result)
        break

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
t = abs(min(p)-x)+1
u = min(p)-1
for i in range(min(x-1,min(p)-1),max(x+1,max(p)+2)):
	if not( i in p ):
		if abs(i-x)<t:
			t = abs(i-x)
			u = i
		elif  abs(i-x)==t:
			if i < u:
				u = i
print(u)

Submission status: Runtime Error

Solution code:
(x, n) = [int(s) for s in input().split()]
p = set([int(s) for s in input().split()])
s = set(range(1, 101))

a = s - p

b = []
for i in a:
    b.append(abs(i - x))

bb = sorted(b)

min_val = bb[0]
ans = 0

for (i, diff) in zip(a, b):
    if min_val == diff:
        ans = i
        break

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

pnt_big = 0
pnt_small = 0
for i in range(101):
    if p.count(x+i) == 0:
        ans_big = x+i
        pnt_big = 1
    if p.count(x-i) == 0:
        ans_small = x-i
        pnt_small = 1
    if pnt_small == 1 or pnt_big == 1:
        break

if pnt_big == pnt_small:
    print(ans_small)
else:
    print(ans_big)

Submission status: Runtime Error

Solution code:
kazulist = []
for i in range(100):
    kazulist.append(i+1)
 
a = list(input().split(" "))
target = int(a[0])
syokyo = int(a[1])
 
b = list(input().split(" "))
for i in b:
    kazulist.remove(int(i))
 
saisyosa = 100
kotae = 0
for i in kazulist:
    sa = target - int(i)
    if sa < 0:
        sa *= -1
    if sa < saisyosa:
        saisyosa = sa
        kotae = i
 
print(kotae)

Submission status: Runtime Error

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

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	x, n = map(int, sys.stdin.readline().split())
	p = list(map(int, sys.stdin.readline().split()))
	p.sort()
	a = [0]*100
	if n == 0:
		print(x)
		exit()
	for i in range(n):
		a[p[i]-1] = 1
	i = x - 1
	log.print(p, i)
	lower = 0
	while i >= -1:
		log.print(i, a[i])
		if a[i] == 0:
			lower = i + 1
			break
		i -= 1
	i = x - 1
	upper = 0
	while i <= 101:
		log.print(i, a[i])
		if a[i] == 0:
			upper = i + 1
			break
		i += 1
	if abs(x - lower) == abs(x - upper):
		print(lower)
		exit()
	if abs(x - lower) < abs(x - upper):
		print(lower)
	else:
		print(upper)

main()

Submission status: Runtime Error

Solution code:
X,N = map(int, input().split())
p = list(map(int, input().split()))
p = sorted(p)
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)