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:
def readInt():
    return list(map(int,input().split()))
    
x,n = readInt()
a = []
if n:
    p = readInt()
    p_r = [int(i) for i in range(1,101) if i not in p]
    # print(p_r)
    for i in p_r:
        dif = abs(x-i)
        a.append(dif)
    # print(a)
    print(p_r[a.index(min(a))])
else:
    print(0)

Submission status: Runtime Error

Solution code:
nums = [int(s) for s in input().split(" ")]
str = input()
if(nums[1] == 0):
    print(nums[0])
    quit() 
nums2 = [int(s) for s in str.split(" ")]
nums3 = [1] * 100
x = nums[0]
for a in nums2:
    nums3[a] = 0
if(nums3[x] == 1):
    print(x)
for i in range(1, len(nums3)):
    if(nums3[x - i] == 0 and nums3[x + i] == 1):
        print(x + i)
        break
    if(nums3[x - i] == 1 and nums3[x + i] == 0):
        print(x - i)
        break
    if(nums3[x - i] == 1 and nums3[x + i] == 1):
        if(nums3[x - i] <= nums3[x + i]):
            if(nums3[x - i] != 0):
                print(x - i)
            else:
                print(x + i)
            break

Submission status: Runtime Error

Solution code:
x, n = [int(x) for x in input().split()]

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

P = [int(x) for x in input().split()]

before = x
after = x
while True:
    if before not in P:
        print(before)
        break
    elif after not in P:
        print(after)
        break
    before -= 1
    after += 1

Submission status: Runtime Error

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

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

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

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

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

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

if length == 0:
  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 -(diffs_abs[smallest_diff_index]) in diffs: # ターゲットよりも小さい、最も差分が小さい値を探す
    index = diffs.index(-(diffs_abs[smallest_diff_index]))
    print(nums[index])
  else:
    print(nums[smallest_diff_index])

elif length == 1:
  print(o_nums[0])

else:
  print(target)

Submission status: Runtime Error

Solution code:
XN = input().split()
X = int(XN[0])
N = int(XN[1])
if N == 0:
    print(X)
else:
    p = input.split()
    A = [None]*N
    for i in range(N):
        A[i] = abs(int(p[i])-X)
    j = 0
    while j in A:
        j += 1
    if j == 1:
        print(X-j)
    else:
        if A.count(j-1) == 2:
            print(X-j)
        else:
            if str(X-(j-1)) in p:
                print(X+(j-1))
            else:
                print(X-(j-1))

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
count=0
for i in range(N):
    for j in range(N):
        if A[i]%A[j]==0:
            count+=1
            if count==2:
                break
    if count==1:
        B[i]=1
    else:
        B[i]=0
    count=0
print(sum(B))

Submission status: Runtime Error

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

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

# pに含まれない整数リストを、最小値-1最大値+1も含めて求める
pl = min(p)-1
pr = max(p)+2
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(res)

Submission status: Runtime Error

Solution code:
import sys
x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()

if x == 1:
    print(0):
    sys.exit()


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


nun_list = list(map(int, input().split()))
answer = 0

for i in range(0, 210):
    if nun_list.__contains__(i):
        continue
    else :
        if abs(x - answer) >= abs(x - i):
            if abs(x - answer) == abs(x - i):
                if answer > i:
                    answer = i
            else:
                answer = i
if abs(x - answer) <= abs(x - 0):
    print(answer)
else :
    print(0)

Submission status: Runtime Error

Solution code:
X , N = map(int, input().split())
p = list(map(int,input().split()))
ans = []
if N == 0:
    print(X)
elif X not in  p:
    print(X)
else:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],100):
        if i not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], 0, -1):
        if i not in p:
            ans.append(i)
    ans = sorted(ans)
    ans2 = [abs(i-X) for i in ans]
    print(ans[ans2.index(min(ans2))])

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit(0)
a = [int(x) for x in input().split()]
b = [i for i in range(1,101) if i not in a]
b_tmp = list(map(lambda s:abs(s-x), b))
mnum = min(b_tmp)
address = b_tmp.index(mnum)
print(b[address])

Submission status: Runtime Error

Solution code:
import numpy as np
import sys


x, n = list(map(int, input().split()))
p_list = np.array(list(map(int, input().split())))

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

p_sub = p_list - x

ans_list = np.array(list(set(np.arange(-n-1, n+1)) - set(p_sub)))
ans_list_abs = abs(ans_list)

m = min(ans_list_abs)

ans = ans_list[np.where(ans_list == m)[0][0]]

if np.count_nonzero(ans_list_abs == m) == 2:
    ans = -m
print(ans + x)

Submission status: Runtime Error

Solution code:
def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    else:
        p = [int(i) for i in input().split()]

    s = []
    for i in range(101):
        if not i in p:
            s.append(i)
    if not x in p:
        print(x)
        return
    
    t = s + [x]
    t.sort()
    pos = t.index(x)
    if abs(x-t[pos-1]) <= abs(x-t[pos+1]):
        print(t[pos-1])
        return
    else:
        print(t[pos+1])

resolve()

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if not n == 0:
  p = list(map(int, input().split()))
if not x in p:
  print(x)
elif not x-1 in p:
  print(x-1)
elif not x+1 in p:
  print(x+1)
elif not x-2 in p:
  print(x-2)
elif not x+2 in p:
  print(x+2)
elif not x-3 in p:
  print(x-3)

Submission status: Runtime Error

Solution code:
import sys
import bisect

def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())


def main():
  X,N = LI()[:]
  if N > 0:
    P = LI()
    P.sort()
  else:
    print(X)
    exit()
    
  index = bisect.bisect_left(P, X)
  if index >= N or index == 0:
    print(X)
    exit()
    
  l = index
  r = index
  for i in range(0,200):
    up = X + i
    down = X - i
    
    if l < 0:
      print(down)
      break
    
    if r > N:
      print(up)
      break
     
    # Left優先
    if P[l] != down:
      print(down)
      break
     
    if P[r] != up:
      print(up)
      break
    
    l -= 1
    r += 1
    
if __name__ == '__main__':
	main()

Submission status: Runtime Error

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

if N == 0:
    print(X)

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

Submission status: Runtime Error

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

if n == 0:
    print(x)
elif n ==100:
    if x >50:
        print(101)
    else:
        print(0)
else:
    p = list(map(int, input().split()))
    d = []
    c=0
    w1 = str(0)
    w2 = str(1)
    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 w1 == str(0):
        print(w2)
    elif w2 == str(1):
        print(w1)
    elif w2 < 0:
        print(w1)
    elif abs(w1-x) < abs(w2-x):
        print(w1)
    else:
        print(w2)

Submission status: Runtime Error

Solution code:
status = list(map(int, input().split()))
aru = list(map(int, input().split()))

if status[1] == 0:
    print(status[0])
else:
    sort_aru = sorted(aru)

    num = status[0]
    total = sort_aru[-1]


    target_list = list()
    for i in range(1, total):
        for j in sort_aru:
            if i == j:
                break
            elif i < j:
                target_list.append(i)
                break
        else:
            target_list.append(i)

    result = target_list[0]
    zettai = (num - target_list[0]) * (num - target_list[0])
    for i in target_list:
        if zettai > (num - i) * (num - i):
            zettai = (num - i) * (num - i)
            result = i
            if zettai == 0:
                break

    print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
input_a= input().split(" ")
X=int(input_a[0])
N=int(input_a[1])

if N!=0:
  array= input().split(" ")
else:
  array=[0,0]

num=X
num2=-100
for i in range(101-X):

  
  if str(num) not in array:
    dis=abs(X-num)
    num2=X-dis
    num1=num
    if str(num2) not in array:
    	numa=min([num,num2])
    else:
      numa=num1
    break
  num=num+1
    

num=X
i=0
for i in range(X+3):
  
  if str(num) not in array:
    
    dis2=abs(X-num)
    num3=X+dis2
    #print(num,dis2,num3)
    if str(num3) not in array:
    	numb=min([num,num3])
    else:
      numb=num
      break
  num=num-1
#print(numa,numb,dis,dis2)
if dis<dis2:
  print(numa)
elif dis==dis2:
  print(numb)
else:
  print(numb)

Submission status: Runtime Error

Solution code:
x, n = map(int,input().split())
p = [int(input()) for _ in range(n)]
mi = max(min(p)-1, 1)
mx = min(max(p)+1, 100)
n_list = [i for i in range(mi,mx)]
for j in p:
    n_list.remove(j)

ans = {}
for k in n_list:
    ans[k] = abs(x-k)

print(min(ans, key=ans.get))

Submission status: Runtime Error

Solution code:
nums = [int(s) for s in input().split(" ")]
if(nums[1] == 0):
    print(nums[0])
    quit() 
nums2 = [int(s) for s in input().split(" ")]
nums3 = [1] * 100
x = nums[0]
for a in nums2:
    nums3[a] = 0
if(nums3[x] == 1):
    print(x)
for i in range(1, len(nums3)):
    if(nums3[x - i] == 0 and nums3[x + i] == 1):
        print(x + i)
        break
    if(nums3[x - i] == 1 and nums3[x + i] == 0):
        print(x - i)
        break
    if(nums3[x - i] == 1 and nums3[x + i] == 1):
        if(nums3[x - i] <= nums3[x + i]):
            if(nums3[x - i] != 0):
                print(x - i)
            else:
                print(x + i)
            break

Submission status: Runtime Error

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

p.sort()
li_p = [i for i in range(1, p[-1]+1)]
diff_p = list(set(p) ^ set(li_p))
#print(li_p)
#print(p)
#print(diff_p)

if x in diff_p == False:
    print(x)
    exit(0)
    
d = abs(diff_p[0] - x)
ans = diff_p[0]
for i in range(1, len(diff_p)):
    #print(d, diff_p[i],abs(diff_p[i] - x ))
    if abs(diff_p[i] - x) < d:
        d = abs(diff_p[i] - x)
        ans = diff_p[i]
    else:
        break
print(ans)

Submission status: Runtime Error

Solution code:
def solution(X, N, P):
    if N <= 0 or X not in P:
        return X

    P.sort()
    diff = [abs(p - X) for p in P]
    X_idx = diff.index(0)
    left = sorted(diff[:X_idx])
    right = sorted(diff[X_idx+1:])

    for i in range(1, len(P)):
        left = X - i
        right = X + i

        nearest_l = None
        nearest_r = None
        if left not in P and left >= 1:
            nearest_l = left
            break
        if right not in P:
            nearest_r = right
            break
    else:
        nearest_r = len(P) + 1
    if nearest_l and nearest_r:
        nearest = min(nearest_l, nearest_r)
    else:
        nearest = nearest_l or nearest_r
    return nearest

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

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()))
    num = max(p)
    ans = [0]*(num+1)
    temp = -1
    val2 = num

    for i in range(1+num):
        temp += 1
        ans[i] = temp
    # print(ans)

    for i in range(n):
        temp1 =p[i]
        # print(temp1)
        ans.remove(temp1)


    for i in range(1+num-n):
        val1 = abs(ans[i]-x)
        if val1 < val2:
            val2 = val1
            xx = i

    # print(ans)
    # print(min(ans)) 
    # print(min(ans)+x) 
    print(ans[xx] )

Submission status: Runtime Error

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

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

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

PZ.append(X)
P2=sorted(PZ)
t=P2.index(X)
if P2[t]==P2[0]:
    print(P2[1])
    exit()
elif P2[t]==P2[-1]:
    print(P2[-2])
    exit()
else:
    dist1=abs(P2[t-1]-P2[t])
    dist2=abs(P2[t]-P2[t+1])
    if dist1<=dist2:
        print(P2[t-1])
        exit()
    else:
        print(P2[t+1])
        exit()

Submission status: Runtime Error

Solution code:
def read_int():
    return int(input())


def read_ints():
    return map(int, input().split(' '))


x, n = read_ints()
p = list(read_ints())
ans = -1
delta = 1000
for i in range(102):
    ok = True
    for j in p:
        if p == i:
            ok = False
            break
    if ok:
        d = abs(x - i)
        if d < delta:
            ans = i
print(ans)

Submission status: Runtime Error

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

while X+i<=100:
    if X+i not in P:
        ans1 = X+i
        break
    i += 1
while X-i>=-100:
    if X-i not in P:
        ans2 = X-i
        break
    i += 1
if ans1-X>=X-ans2:
    print(ans2)
else:
    print(ans1)

Submission status: Runtime Error

Solution code:

x, n = input().strip().split()
x, n = [int(x), int(n)]
if n==0:
    p=[0]
else:    
    p = list(map(int, input().strip().split()))
if n>0:
    q=[0]*n
    for i in range (n):
        q[i]=abs(x-p[i])
    q.sort()

    if q[0]>=1:
        print(x)
    else:
        for i in range (n+1):
            if p.count(x-(q[0]+i))==0:
                s=x-(q[0]+i)
                break
        for i in range (n+1):
            if p.count(x+q[0]+i)==0:
                t=x+(q[0]+i)
                break
    if (x-s)<=(t-x):
        print(s)
    else:
        print(t)
else:
    print(x)

Submission status: Runtime Error

Solution code:
X,N = map(int, input().split())
P = list(map(int, input().split()))
sortP = sorted(P)
if N==0:
    print(X)
elif sortP[0]>X:
    print(sortP[0]-1)
elif sortP[N-1]<X:
    print(sortP[N-1]+1)
else:
    for n in range(sortP[0],sortP[N-1]+2):
        if n in sortP:
            continue
        if n ==X:
            print(X)
        elif n>X:
            if X-a<=n-X:
                print(a)
                break
            else:
                print(n)
                break
        a = n

Submission status: Runtime Error

Solution code:
import numpy as np

i = input()
n = [int(x) for x in i.split(' ')]
l = input()
l = np.fromstring(l, dtype=int, sep=' ')

if n[1] == 0:
  print(n[0])
elif n[0] not in l:
  print(n[0])
elif n[0] in l:
  l = np.setdiff1d(l, [n[0]])
  
  pp = np.arange(1, 101)
  np = np.setdiff1d(pp, l)

  np = np.tolist()

  ix = np.index(n[0])
  b = np[ix - 1]
  a = np[ix + 1]
  
  babs = abs(n[0] - b)
  aabs = abs(n[0] - a)
  
  if babs > aabs:
    print(a)
  elif aabs > babs or aabs == babs:
    print(b)

Submission status: Runtime Error

Solution code:
import math
N= int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
prod = math.prod(A)

count = 0

for i in range(N):
    qualify = 1

    if i > 1 and A[i - 1] == A[i]:
        continue

    if prod/A[i] % A[i] != 0:
        continue

    for j in range(i+1, N):
        if (A[i] % A[j]) == 0:
            qualify = 0
            break


    count += qualify


print(count)

Submission status: Runtime Error

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

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

# 1から100のリスト
num_li = [i for i in range(101)]

# num_liのリストにpiに含まれていたら0にする
for i in pi:
	if i<0:
		continue
	else:
		num_li[i]=0
	
# X以上の一番近い値
for i in range(X,101):
	if num_li[i] != 0:
		xup = num_li[i]
		break

# X以下の一番近い値
for i in range(X,0,-1):
	if num_li[i] != 0:
		xdown = num_li[i]
		break


if xup-X >= X-xdown:
	ans = xdown
else :
	ans = xup
print(ans)

Submission status: Runtime Error

Solution code:
x, N = map(int, input().split(" "))
data = list(map(int, input().split(" ")))
point = 0
i = 0
while(1):
    if x not in data:
        print(x)
        break
    elif x+i not in data:
        print(x+i)
        break
    elif x+(-1*i) not in data:
        print(x+(-1*i))
        break
    else:
        i=i-1

Submission status: Runtime Error

Solution code:
import numpy as np
listA=[]
lis=[]
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
#print(listA)

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

X_=listA[0]
X=X_[0]
N=X_[1]
if N!=0:
    P =listA[1]

    arr = np.array(lis)
    P_max = max(P)
    P_min = min(P)   

    for i in range(P_max+1):
        lis.append(i)
    lis.remove(0)
    
    arr=arr[arr<=P_max]
    arr=arr[arr>=P_min]
    lis=arr.tolist()
    for p in P:
        lis.remove(p)
    #print(lis)
    lis_=[]
    for l in lis:
        lis_.append(abs(l-X))
    #print(lis_)
    lis_min=min(lis_)
    print(lis[my_index(lis_, lis_min)])
else:
    print(X)

Submission status: Runtime Error

Solution code:
import sys
X,N=map(int,input().split())
A=list(map(int,input().split()))
if N==0:
    print(X)
    sys.exit()
B=[]
for i in range(1,101):
    CH=int(0)
    for k in range(N):
        if i==A[k]:
            CH=1
    if CH==0:
        B.append(int(i))
C=[0 for _ in range(len(B))]
for j in range(len(B)):
    if B[j]-X>=0:
        C[j]=int(B[j]-X)
    else:
        C[j]=int(X-B[j])
m=min(C)
kouho1 = int(X-m)
kouho2 = int(X+m)
#print(B[3])
#print(kouho2)
for k in range(len(B)):
    if int(B[k])==int(kouho1):
        print(B[k])
        sys.exit()
for l in range(len(B)):
    if int(B[l])==int(kouho2):
        print(B[l])
        sys.exit()

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
try:
    p=list(map(int,input().split()))
    mina=100
    for i in range(min(p),max(p)):
        if i not in p:
            if mina>abs(i-x):
                mina=abs(i-x)
                ans=i
                if ans>x and (x-mina) not in p:
                    ans=x-mina
except:
    ans=x

print(ans)

Submission status: Runtime Error

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

if N > 0:
    p = input().split()
    p = [int(i) for i in p]
    p.sort()
     



    for i in p:
        if X > i:
            continue
        else :
            roof = i
            num = p.index(i)
            break

    if num == 0:
        if X == roof:
            ans = X - 1
        else:
            ans = X

    if X != roof:
        ans = X

    else :
        i = 1
        while True:
            if X - i == p[num - i]:
                if X + i == p[num + i]:
                    i += 1
                    continue
                else :
                    ans = X + i
                    break
            else :
                ans = X - i
                break

else :
    ans = X

print(ans)

Submission status: Runtime Error

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

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

# pに含まれない整数リストを、最小値-1最大値+1も含めて求める
pl = min(p)-1
pr = max(p)+2
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(res)

Submission status: Runtime Error

Solution code:
k, n = map(int, input().split())
if n == 0:
    print(0)
else:
    l = list(map(int, input().split()))
    l.sort()
    k1 = [i for i in range(min(l), max(l) + 1) if i not in l]
    d = {}
    for i in range(len(k1)):
        d[k1[i]] =max(k1[i],k)-min(k1[i],k)
    k2 = min(d, key=d.get)
    if len(d)==0 or len(k1)<=1:
        print(0)
    else:
        print(k2)

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())
if b !=0:
    c = input()
    l = c.split()
    cc = [int(s) for s in l]
    ccc =list(cc)
    z = max(ccc) + 2
    for i in range(a,z):
        if i in ccc:
            continue
        else:
            x = i
            break
    for i in reversed(range(1, a)):
        if i in ccc:
            continue
        else:
            y = i
            break
    if x-a<a-y:
        print(x)
    else:
        print(y)
else:
    print(a)

Submission status: Runtime Error

Solution code:
import numpy as np
input()

def no_Divisible(num,num_list):
    for row in set(num_list):
        if num%row==0:
            return 0
    return 1

input_list = np.array(sorted(list(map(lambda x:int(x),input().split(" "))),reverse=True))
count = 0
prev_num = 0
for i,num in enumerate(input_list):
    if num == prev_num:
        continue
    #print(num)
    #print(input_list[i+1:]%num)
    #if sum(input_list[i+1:]%num==0):
    if no_Divisible(num,input_list[i+1:]):
        count += 1
    prev_num = num
print(count)

Submission status: Runtime Error

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

if a not in c:
    print(a)
    exit()

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 len(m)<=3:
    print(m[m.index(a)-1])

elif 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:
import numpy as np

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

if N != 0:
    
    p_list = [int(n) for n in p.split()]
    
    X_near = np.array(list(range(int(np.ceil(X - N/2)), int(np.floor(X + N/2)) + 1)))
 
    remain_list = []
 
    for i in X_near:
        if i not in p_list:
            remain_list.append(i)
        

    remain_array = np.array(remain_list)
    min_bool = np.abs(X - remain_array).min() == np.abs(X - remain_array)
    print(remain_array[min_bool].min())
    
else:
    print(X)

Submission status: Runtime Error

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

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

ans=x

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

print(ans)

Submission status: Runtime Error

Solution code:
x , n = map(int,input().split())
p_str = input().split()#pはlist
list = []
for i in p_str :
    p = int(i)
    list.append(p)

if not x  in list :
    print(x)
else :
    for i  in range(101):
        y = x - i
        if not y in list :
            print(y)
            break
            z = x + i
        if not z in list :
            print(z)
            break

Submission status: Runtime Error

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

if a not in c:
    print(a)
    exit()

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 len(m)=<3:
    print(m[m.index(a)-1])

elif 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:
XN_list = list(map(int, input().split()))
p_list = list(map(int, input().split()))
X = XN_list[0]
N = XN_list[1]
not_p_list = []
Xj_list = []
for i in range(1, 100):
    if not i in p_list:
        not_p_list.append(i)
if X in p_list:
    for j in not_p_list:
        Xj_list.append(abs(X-j))
    print(min(Xj_list) + X)
else:
    print(X)

Submission status: Runtime Error

Solution code:
k, n = map(int, input().split())
if n == 0:
    print(0)
else:
    l = list(map(int, input().split()))
    l.sort()
    k1 = [i for i in range(min(l), max(l) + 1) if i not in l]
    d = {}
    for i in range(len(k1)):
        d[k1[i]] =max(k1[i],k)-min(k1[i],k)
    k2 = min(d, key=d.get)
    if len(d)==0 or len(k1)==0:
        print(0)
    else:
        print(k2)

Submission status: Runtime Error

Solution code:
import numpy as np

x, n = list(map(int, input().split()))
p_list = np.array(list(map(int, input().split())))

p_sub = p_list - x

ans_list = np.array(list(set(np.arange(-n-1, n+1)) - set(p_sub)))
ans_list_abs = abs(ans_list)

m = min(ans_list_abs)

ans = ans_list[np.where(ans_list == m)[0][0]]

if np.count_nonzero(ans_list_abs == m) == 2:
    ans = -m
print(ans + x)

Submission status: Runtime Error

Solution code:
import sys

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

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

li.sort()
index = li.index(x)

result1 = 0
counter1 = 1
kekka1 = 0
while(True):

    try:
        result1 = li.index(x+counter1)
        kekka1 = li[result1]
        counter1 = counter1+1
    except ValueError as e:
        break

result2 = 0
counter2 = 1
kekka1 = 0
while(True):
    try:
        result2 = li.index(x-counter2)
        kekka1 = li[result2]
        counter2 = counter2+1
    except ValueError as e:
        break

if counter1 < counter2:
    print(x+counter1)
elif counter1 > counter2:
    print(x+counter2)
elif counter1 == counter2:
    print(x-counter2)

Submission status: Runtime Error

Solution code:
import sys
import bisect

def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())


def main():
  X,N = LI()[:]
  if N > 0:
    P = LI()
    P.sort()
  else:
    print(X)
    exit()
    
  index = bisect.bisect_left(P, X)
  
  l = index
  r = index
  for i in range(0,200):
    up = X + i
    down = X - i
    
    if l < 0:
      print(down)
      break
    
    if r > N:
      print(up)
      break
     
    # Left優先
    if P[l] != down:
      print(down)
      break
     
    if P[r] != up:
      print(up)
      break
    
    l -= 1
    r += 1
    
if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split(" "))
data = list(map(int, input().split(" ")))
point = 0
i = -1
while(1):
    if x not in data:
        print(x)
        break
    elif x+i not in data:
        print(x+i)
        break
    elif x+(-1*i) not in data:
        print(x+(-1*i))
        break
    else:
        i=i-1

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

Submission status: Runtime Error

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

if N > 0:
    p = input().split()
    p = [int(i) for i in p]
    p.sort()
    print(p)
    



    for i in p:
        if X > i:
            continue
        else :
            roof = i
            num = p.index(i)
            break

    if num == 0:
        if X == roof:
            ans = X - 1
        else:
            ans = X

    if X != roof:
        ans = X

    else :
        i = 1
        while True:
            if X - i == p[num - i]:
                if X + i == p[num + i]:
                    i += 1
                    continue
                else :
                    ans = X + i
                    break
            else :
                ans = X - i
                break

else :
    ans = X

print(ans)