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 numpy as np

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

def final (babs, aabs):
  if babs > aabs:
      print(a)
  elif aabs > babs or aabs == babs:
    print(b)

if n[1] == 0:
  print(n[0])
elif n[0] not in l:
  print(n[0])
elif n[0] in l:
  if n[1] == 100:
    if n[0] > 50:
      print('101')
    else:
      print('0')
  l = np.setdiff1d(l, [n[0]])
  
  pp = np.arange(1, 101)
  npp = np.setdiff1d(pp, l)

  npp = npp.tolist()
  
  if len(npp) > 0:
    ix = npp.index(n[0])
    if ix == 0:
      # before none
      a = npp[ix + 1]
      print(a)
    elif len(npp) == ix + 1:
      # after none
      b = npp[ix - 1]
      print(b)
    else:
      b = npp[ix - 1]
      babs = abs(n[0] - b)
      a = npp[ix + 1]
      aabs = abs(n[0] - a)
      final(babs, aabs)
  else:
    print(n[0])

Submission status: Runtime Error

Solution code:
import sys
# Xはもっとも近い整数，Nは与えられるP
X,N = map(int, input().split())

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

arr = list(map(int, input().split()))
mainasu = X 
purasu = X 

def saiki():
  mainasu - 1
  purasu + 1
  if X in arr:
    if mainasu in arr:
      if purasu in arr:
        saiki()
      else:
        print(purasu)
    else:
      print(mainasu)
  else:
    print(X)

saiki()

Submission status: Runtime Error

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


l=[]
l1=[]
l2=[]
if not P:
    l.append(1)
for p in P:
    l.append(abs(X-p))

for i in range(len(l)):
    if i==0:
        if l.count(0)!=1:
            l1.append(i)
    else:
        if l.count(i)<2:
            l1.append(i)
            
l1min=min(l1)
if l.count(l1min)==1:
    for p in P:
        if p==X+l1min:
            print(X-l1min)
        elif p==X-l1min:
            print(X+l1min)
else:
    print(X-l1min)

Submission status: Runtime Error

Solution code:
import numpy as np

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


if __name__ == "__main__":
    x, n = list(map(int, input().split()))
    if n == 0:
        print(x)
        exit(0)
    p = list(map(int, input().split()))
    
    if n == 100:
        print(101)
        exit(0)

    p.sort()
    Max = p[-1] * 2
    li_p = [i for i in range(1, Max)]
    diff_p = list(set(p) ^ set(li_p))

    if x in diff_p == False:
        print(x)
        exit(0)
        
    print(getNearestValue(diff_p, 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()))

    p1 = [0] * n

    for y in range(0, len(p)):
        p1[y] = abs(p[y] - x)
    
    p1.sort()
    
    i = 1
    nearAns = 0
    
    if p1[0] != 0:
        print(x)
    else:
        for y in range(0, 100):
            if p1[i] == p1[i - 1] + 1 and p1[i] == p1[i + 1]:
                i += 2
            elif p1[i] != p1[i - 1] + 1 :
                nearAns = (p1[i - 1] + 1)
                break
            elif p1[i] != p1[i + 1]:
                nearAns = p1[i]
                break
    
        if x - nearAns in p:
            print(x + nearAns)
        else:
            print(x - nearAns)

Submission status: Runtime Error

Solution code:
x,n=list(map(int,input().split()))
arr=list(map(int,input().split()))
for k in range(1,max(arr)):
  if x-k not in arr:
    print(x-k)
    break
  elif x+k not in arr:
    print(x+k)
    break

Submission status: Runtime Error

Solution code:
def readInt():
    return list(map(int,input().split()))
    
x,n = readInt()
a = []
if 0<n<100:
    p = readInt()
    p_r = [int(i) for i in range(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 if n=0:
    print(x)
else:
    print(0)

Submission status: Runtime Error

Solution code:
s = list(map(int,input().split()))
t = 0
h = 0
a = s.pop(0)
b = s.pop(0)
print(a)
print(b)
d = 0
if b ==0:
  print(a)
else:
  for i in range(a+1,a+2+b):
    c = 1
    for k in range(0,b):
      if i == s[k]:
        c = 0
        break
    if c==1:
      t = i
      break
  for i in range(a-1,a-2-b,-1):
    c = 1
    for k in range(0,b):
      if i == s[k]:
        c = 0
        break
    if c==1:
      h = i
      break
  if abs(t-a)>=abs(h-a):
    print (h)
  else:
    print(t)

Submission status: Runtime Error

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

p_change = []
m = 0
for i in p:
    p_change.append(abs(i-x))

if x in p:
    for i in range(n):
        if i != 0 and p_change.count(i) != 2:
            m = i
            break
    if x-m in p:
        print(x+m)
    else:
        print(x-m)
else:
    print(x)

Submission status: Runtime Error

Solution code:
first_input = input().split()
x = int(first_input[0])
n = int(first_input[1])
if n != 0:
    second_input = map(int, input().split())
    p_a = list(map(int, second_input))
else:
    second_input = input()

def create_full_array(minimum, maximum):
    diff = maximum - minimum
    full_list = []
    for i in range(minimum,maximum+1):
        full_list.append(int(i))
    return full_list

if n == 0:
    print(x)
elif x > max(p_a) + 1 or x < min(p_a):
    ans = x - 1
    print(x - 1)
else:
    full_array = create_full_array(min(p_a), max(p_a))
    if x in p_a:
        target_list = list(set(p_a)^set(full_array))
        abs_key = {}
        for i in target_list:
            abs_key[i] = abs(x-i)
        minimum = min(abs_key.values())
        t_k = []
        t_v = []
        [t_k.append(k) for k, v in abs_key.items() if v == minimum]
        print(min(t_k))

    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())
    for i in range(0, 102):
        if x-i not in P or x+i not in P:
            if x-i not in P:
                print(x-i)
                exit(0)
            if x+i not in P:
                print(x+i)
                exit(0)

Submission status: Runtime Error

Solution code:
import numpy as np
a = np.arange(1,101)
x,y = input().split()
i = list(map(int, input().split()))

x=int(x)
y=int(y)


b=list(set(a)-set(i))

c=[]
for k in b:
    c.append(abs(k-x))

print(min(c)+x)

Submission status: Runtime Error

Solution code:
import sys
x, n = map(int, input().split())
p = [int(i) for i in input().split()]
q = []

if n == 0 or x not in p:
  print(x)
  sys.exit() 

for i in range(1, 101-x):
  if x + i not in p:
    q.append(x + i)
    if x - i not in p:
      q.append(x - i)
  break
print(min(q))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
X, N = map(int, input().split())
p = list(map(int, input().split()))
if N == 0:
    print(X)
    sys.exit()
q = list(range(1,101))
for i in range(N):
    q.remove(p[i])
def get(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
print(get(q, X))

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

X, N = map(int, input().split())
p = list(map(int, input().split()))
pos = bisect_left(p, X)
if N == 0:
    print(X)
    exit()
if pos == N:
    print(p[-1])
before = p[pos - 1]
after = p[pos]
if after - X < X - before:
    print(after)
else:
    print(before)

Submission status: Runtime Error

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

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

value = []
for i in range(1,100):
	value.append(i)

for i in input().split():
	value.remove(int(i))

left = 0
right = len(value)

while right - left > 1:
	mid = (left + right) // 2
	if value[mid] > x:
		right = mid
	else:
		left = mid
if x - value[right-1] <= value[right] - x:
	print(value[right-1])
else:
	print(value[right])

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

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

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

p = [list(map(int, input().split()))]
p_n = np.array(p)
p_n = p_n.reshape(-1)
pp = np.arange(1, 100)
for i in p_n:
    pp[i-1] += 10000
sa = min(abs(pp-x))
if pp[x-sa-1] >= 10000:
    print(x+sa)
else:
    print(x-sa)

Submission status: Runtime Error

Solution code:
import math

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

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

if X < minimum or maximum < X:
    print(X)
    exit()

answer = 1
for candidate in range(1, 100 + 1):
    if candidate in p : continue

    diff_candidate = abs(X - candidate)
    diff_answer = abs(X - answer)

    if diff_candidate == diff_answer:
        answer = min(candidate, answer)
    elif diff_candidate < diff_answer:
        answer = candidate

print(answer)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

X, N = map(int, input().split())
p = list(map(int, input().split()))
pos = bisect_left(p, X)
if N == 0:
    print(X)
    exit()
if pos == N:
    print(p[-1])
before = p[pos - 1]
after = p[pos]
if after - X < X - before:
    print(after)
else:
    print(before)

Submission status: Runtime Error

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

l=[]
for i in range(1,101):
  l.append(i)
for i in p:
  if i in l:
    l.remove(i)
list=[]
for i in l:
  list.append(abs(x-i))
ans=min(list)
for i in l:
  if abs(x-i) == ans:
    break
print(i)

Submission status: Runtime Error

Solution code:
#import numpy as np
#import random
#import time
from collections import defaultdict, Counter

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    #N = 20
    #A = [random.randint(1, int(1e6)) for _ in range(int(N))]
    N = int(input())
    A = [int(c) for c in input().split(' ')]
    #t1 = time.time()
    dup_cnt = Counter(A)
    dup = set(x for x in dup_cnt if dup_cnt[x] > 1)
    A = list(set(A))
    N = len(A)
    A.sort()
#    B = [factorization(x) for x in A]
#    B.sort()

    d = defaultdict(list)
    B = []
    for x in A:
        x_fac = factorization(x)
        B.append(x_fac)
        for y in x_fac:
            d[y[0]].append(x)
    assert len(A)==len(B)
    #print(A)
    #print(B)
    #print(d)
    not_divided = set()
    for i in range(N):
        bi = A[i]
        bi_fac = B[i]
        can_divide = False
        for y in bi_fac:
            for a in d[y[0]]:
                if bi % a == 0 and bi != a:
                    #print(a,bi)
                    can_divide = True
                    break
                elif a > bi:
                    break
            if can_divide:
                break
        if can_divide or bi in dup:
            continue
        else:
            not_divided.add(bi)
    #print(A)
    #print(dup)
    #print(not_divided)
    print(len(not_divided))
    #print(time.time() - t1)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import warnings
warnings.simplefilter('ignore')

from numba import jit

N = int(input())
As = list(map(int, input().split(' ')))


@jit
def test(As):
    not_divisible = 0
    for num_i, Ai in enumerate(As):
        for num_j, Aj in enumerate(As):
            if num_i==num_j:
                continue
            if Ai%Aj==0:
                break
        else:
            not_divisible += 1
    print(not_divisible)
    
test(As)

Submission status: Runtime Error

Solution code:
s = list(map(int,input().split()))
t = 0
h = 0
a = s.pop(0)
b = s.pop(0)
print(a)
print(b)
d = 0
for i in range(a+1,a+2+b):
  c = 1
  for k in range(0,b):
    if i == s[k]:
      c = 0
      break
  if c==1:
    t = i
    break
for i in range(a-1,a-2-b,-1):
  c = 1
  for k in range(0,b):
    if i == s[k]:
      c = 0
      break
  if c==1:
    h = i
    break
if abs(t-a)>=abs(h-a):
  print (h)
else:
  print(t)

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
if N==0:
    print(X)
    exit()
sp = input().split()
p= [int(s) for s in sp]
tmp=[]
ans=[]
tans=[]
hans=[]
for i in p:
    tmp.append(abs(X-i))
ans_min = min(tmp)-1
ans_max =max(tmp)+1
fa=[]
for i in range(ans_min,ans_max):
    fa.append(X+i)
for n in fa:
    if n not in p:
        tans.append(n)
for m in tans:
    hans.append(m-X)
print(tans[hans.index(min(hans))])

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
if N == 0:
    print(X)
else:
    s=input()
    array = s.split()
    array = list(map(int, array))
    array1 = array #与えられた整数列
    for i in array:
        if i == X:
            i=201
    def calc(x):
        return abs(x-X)
    array = list(map(calc,array)) #差の絶対値を持つ整数列
    index = [i for i, v in enumerate(array) if v == min(array)]
    for i in index:
        answer.append(array[i])
    print(min(answer))

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    p1 = [0] * n
    
    for y in range(0, len(p)):
        p1[y] = abs(p[y] - x)
    
    p1.sort()
    
    i = 1
    nearAns = 0

    for y in range(0, 100):
        if p1[i] == p1[i - 1] + 1 and p1[i] == p1[i + 1]:
            i += 2
        elif p1[i] != p1[i - 1] + 1 :
            nearAns = (p1[i - 1] + 1)
            break
        elif p1[i] != p1[i + 1]:
            nearAns = p1[i]
            break

    if x - nearAns in p:
        print(x + nearAns)
    else:
        print(x - nearAns)

Submission status: Runtime Error

Solution code:
def main():
    import copy

    num, quantity = map(int, input().split())
    nums = list(map(int, input().split()))
    nums.sort()
    
    if quantity == 0:
        print(num)
        return
    
    i = 0

    minus_num = copy.copy(num)
    plus_num = copy.copy(num)

    while i < len(nums)
        if num not in nums:
            print(num)
            return
        
        if minus_num not in nums:
            print(minus_num)
            return
        
        if plus_num not in nums:
            print(plus_num)
            return
        
        minus_num = minus_num - 1
        plus_num = plus_num + 1
        i = i + 1

main()

Submission status: Runtime Error

Solution code:
a=input().split()
x=a[0]
o=[]
l=list(map(int,input().split()))
l.sort()
if(x not in l):
    print(x)
elif(l.index(x)==0):
    print(x-1)
elif(l.index(x)!=0):
    for i in range(len(l)):
        if(abs(x-l[i])!=abs(l.index(x)-i)):
            o.append(x+abs(l.index(x)-i))
            o.append(x-abs(l.index(x)-i))
print(min(o))

Submission status: Runtime Error

Solution code:
X,N = map(int, input().split())
if N==0:
    print(X)
    exit()
else:
    p=list(map(int,input().split()))
    A=[i for i in range(1,100) if i not in p]

mini=101
minip=101
for i in range(N):
    if abs(p[i]-X) <=mini:
        mini= abs(p[i]-X)
        minip=p[i]
        

minimini=101
answer=101
for a in A:
    if abs(a-minip)<minimini:
        minimini=abs(a-minip)
        answer.append(a)

print(answer)

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 > 1:
  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)
  
  if len(nums) == 0:
    print(target)

  else:
    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])

else:
  print(target)

Submission status: Runtime Error

Solution code:
import numpy as np

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


if __name__ == "__main__":
    x, n = list(map(int, input().split()))
    if n == 0:
        print(x)
        exit(0)
    p = list(map(int, input().split()))

    p.sort()
    Max = p[-1] * 2
    li_p = [i for i in range(1, Max)]
    diff_p = list(set(p) ^ set(li_p))

    if x in diff_p == False:
        print(x)
        exit(0)
        
    print(getNearestValue(diff_p, x))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import fractions

def main():
    n = int(input())
    A = list(map(int, input().split()))

    A.sort()
    ans = len(A)
    if n == 1:
        print(1)
        return
    for i in range(n):
        for j in range(n):
            ri = -i-1
            r = A[ri]
            l = A[j]
            if (ri!=-n and r == A[ri-1]) or (i!=n-1 and r == A[ri+1]):
                ans -= 1
                break
            if n+ri == j:
                break
            if r % l == 0:
                ans -= 1
                break
            if l >= r**(1/2):
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
# Xはもっとも近い整数，Nは与えられるP
X,N = map(int, input().split())

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

arr = list(map(int, input().split()))
mainasu = X 
purasu = X 

def saiki():
  mainasu = mainasu - 1
  purasu = purasu + 1
  if X in arr:
    if mainasu in arr:
      if purasu in arr:
        saiki()
      else:
        print(purasu)
    else:
      print(mainasu)
  else:
    print(X)

saiki()

Submission status: Runtime Error

Solution code:
a=input().split()
x=a[0]
l=list(map(int,input().split()))
l.sort()
if(x not in l):
    print(x)
elif(l.index(x)==0):
    print(x-1)
elif(l.index(x)!=0):
    for i in range(len(l)):
        if(abs(x-l[i])!=abs(l.index(x)-i)):
            o.append(x+abs(l.index(x)-i))
            o.append(x-abs(l.index(x)-i))
print(min(o))

Submission status: Runtime Error

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


all_l = [i for i in range(1,101)]
for p in P:
    all_l.remove(p)

ans = []
c = 0
dic = {}
for a in all_l:
    if c == 0:
        diff = abs(x-a)
    c+=1
    diff_now = abs(x-a)
    diff = min(diff,diff_now)
    memo = diff_now
    if memo == diff:
        dic['{}'.format(str(a))] = diff
        
l = []
for k,v in  dic.items():
    l.append(v)
m = min(l)
k_list = []
for k,v in dic.items():
    if v==m:
        k_list.append(k)
print(int(max(k_list)))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

def solve():
    N = II()
    A = LI()

    cost = {}
    for a in A:
        if cost.get(a, -1) == -1:
            cost[a] = 1
        else:
            cost[a] = 0

    A = sorted(A)

    memo = {}
    ans = 0
    for a in A:
        divs = make_divisors(a)
        for d in divs:
            if memo.get(d, -1) != -1:
                break
        else:
            ans += cost[a]
        memo[a] = 1
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
n = list(map(int,input().split()))
xn = list(range(1,101))
for i in range(N):
  xn.remove(n[i])
mindis = 100
for i in range(len(xn)):
  dis = abs(X-xn[i])
  if dis < mindis:
    mindis = dis
    answer = xn[i]
print(answer)

Submission status: Runtime Error

Solution code:
import numpy as np
X, N = map(int, input().split())
p = list(map(int, input().split()))
q = list(range(1,101))
for i in range(N):
    q.remove(p[i])
def get(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
print(get(q, X))

Submission status: Runtime Error

Solution code:
a=input().split()
x=a[0]
l=list(map(int,input().split()))
l.sort()
if(x not in l):
    print(x)
elif(l.index(x)==0):
    print(x-1)
elif(l.index(x)!=0):
    for i in range(len(l)):
        if(abs(x-l[i])!=abs(l.index(x)-i)):
            o.append(x+abs(l.index(x)-i))
            o.append(x-abs(l.index(x)-i))
print(min(o)):

Submission status: Runtime Error

Solution code:
x,y=(int(x) for x in input().split())
a=[int(x) for x in input().split()]
1<=x<=100
0<=y<=100
while y>0:
    if y in a:
        z=y+1
    elif not y in a:
        print('y')
        break
    elif z in a:
        z+=1
    else:
        break
while y>0:
    if y in a:
        b=y-1
    elif b in a:
        b+=1
    else:
        break
c=z-y
d=b-y
if not y in a:
    pass
elif abs(c)<abs(d):
    print(c)
else:
    print(d)

Submission status: Runtime Error

Solution code:
[x, n] = [x for x in map(int, input().split(' '))]
pn = [x for x in map(int, input().split(' '))]
pn.sort()
min_pn = [y for y in pn if x >= y]
max_pn = [y for y in pn if x <= y]
min_pn_fix = None
max_pn_fix = None
if n == 0:
    print(x-1)
else:
    for i in range(len(min_pn) -1, 0, -1):
        if min_pn[i] < min_pn[i-1] - 1:
            min_pn_fix = min_pn[i-1] - 1
            break
    if min_pn_fix is None:
        min_pn_fix = min_pn[0] - 1
    for i in range(0, len(max_pn)-1):
        if max_pn[i] +1 < max_pn[i+1]:
            max_pn_fix = max_pn[i] +1
            break
    if max_pn_fix is None:
        max_pn_fix = max_pn[-1] + 1
    if abs(x - max_pn_fix) < abs(x - min_pn_fix):
        print(max_pn_fix)
    else:
        print(min_pn_fix)

Submission status: Runtime Error

Solution code:
X, N = map(int,input().split())
if N == 0:
    print(X)
    exit()
else:
    P = list(map(int,input().split()))
L = [i for i in range(0,101) if i not in P]

if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    l = len(L) - 1


    if (0 < n < l):
        if (L[n+1]-L[n] < L[n] - L[n-1]):
            ANS = L[n+1]
        else:
            ANS = L[n - 1]

print(ANS)

Submission status: Runtime Error

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


l=[]
l1=[]
l2=[]
if not P:
    l.append(1)
for p in P:
    l.append(abs(X-p))

for i in range(max(l)):
    if i==0:
        if l.count(0)!=1:
            l1.append(i)
    else:
        if l.count(i)<2:
            l1.append(i)
            
l1min=min(l1)
if l.count(l1min)==1:
    for p in P:
        if p==X+l1min:
            print(X-l1min)
        elif p==X-l1min:
            print(X+l1min)
else:
    print(X-l1min)

Submission status: Runtime Error

Solution code:
import sys
import collections
import heapq

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))

def heapsort(iterable):
  h = []
  for value in iterable:
    heapq.heappush(h, value)
  l = []
  for _ in range(len(h)):
    l.append(heapq.heappop(h))
  return l

n = ri()
li = rl()
dic = collections.Counter(li)
li1 = []
li2 = []
for k, v in dic.items():
    if v > 1:
        li1.append(k)
    else:
        li2.append(k)
li1 = heapsort(li1)
li2 = heapsort(li2)
le1 = len(li1)
le2 = len(li2)
cnt = 0
for i in range(le2):
    li2i = li2[i]
    for j in range(i):
        if li2i % li2[j] == 0:
            break
    else:
        for k in range(le1):
            li1k = li1[k]
            if li1k > li2i**0.5:
                cnt += 1
                break
            if li2i % li1k == 0:
                break
        else:
            cnt += 1
print(cnt)

Submission status: Runtime Error

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


all_l = [i for i in range(1,101)]
for p in P:
    all_l.remove(p)

ans = []
c = 0
dic = {}
for a in all_l:
    if c == 0:
        diff = abs(x-a)
    c+=1
    diff_now = abs(x-a)
    diff = min(diff,diff_now)
    #print(diff,diff_now)
    memo = diff_now
    #print('memo:',memo,'diff:',diff)
    if memo == diff:
        dic['{}'.format(str(a))] = diff
        
        
l = []
for k,v in  dic.items():
    l.append(v)
m = min(l)
k_list = []
for k,v in dic.items():
    if v==m:
        k_list.append(k)
#print(k_list)
int(max(k_list))

Submission status: Runtime Error

Solution code:
def main():
    import copy

    num, quantity = map(int, input().split())
    nums = list(map(int, input().split()))
    nums.sort()
    
    if quantity == 0:
        print(num)
        return
    
    i = 0

    minus_num = copy.copy(num)
    plus_num = copy.copy(num)

    while i = 1
        if num not in nums:
            print(num)
            return
        
        if minus_num not in nums:
            print(minus_num)
            return
        
        if plus_num not in nums:
            print(plus_num)
            return
        
        minus_num = minus_num - 1
        plus_num = plus_num + 1



main()

Submission status: Runtime Error

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

l = list(map(int,input().split()))
l = [i for i in range(1,101) if not i in l]

Z = abs(l[0] - X) + 1

for i in range(len(l)):
    Y = abs(l[i] - X)
    if Y < Z:
        Z = Y
    else:
        print(l[i-1])
        sys.exit()

Submission status: Runtime Error

Solution code:
x, n = map(int,input().split())
p = list(map(int,input().split()))
if n == 0:
    print(x)
else:
    mi = max(min(p)-1, 1)
    mx = min(max(p)+1, 100)
    n_list = [i for i in range(mi,mx)]
    ans = {}
    for k in n_list:
        if k not in p:
            ans[k] = abs(x-k)
    print(min(ans, key=ans.get))

Submission status: Runtime Error

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

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

min_value = min(p)
max_value = max(p)

if x < min_value:
    print(x)
    exit()
if x > max_value:
    print(x)
    exit()

tmp_min_value = 100

for i in range(x, 101):    
    flag = 0
    for j in range(n):
        if i == p[j]:
            flag = 1
    if flag == 1:
        continue

    if tmp_min_value > i:
        tmp_min_value = i
        tmp_min_dif = i-x

tmp_max_value = 0

for i in range(x, 0, -1):    
    flag = 0
    for j in range(n):
        if i == p[j]:
            flag = 1
    if flag == 1:
        continue

    if tmp_max_value < i:
        tmp_max_value = i
        tmp_max_dif= x-i

if tmp_min_dif < tmp_max_dif:
    print(tmp_min_value)
    exit()
elif tmp_min_dif > tmp_max_dif:
    print(tmp_max_value)
    exit()
else:
    print(min(tmp_min_value, tmp_max_value))

Submission status: Runtime Error

Solution code:
import sys
# Xはもっとも近い整数，Nは与えられるP
X,N = map(int, input().split())

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

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

def saiki():
  mainasu = X - 1
  purasu = X + 1
  if X in arr:
    if mainasu in arr:
      if purasu in arr:
        saiki()
      else:
        print(purasu)
    else:
      print(mainasu)
  else:
    print(X)

saiki()

Submission status: Runtime Error

Solution code:
import sys
import math

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

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

p_list.sort()

if p_list[-1] < x:
    print(x)
    sys.exit()
elif p_list[-1] == x:
    if p_list[-2] == x-1:
        print(x +1)
    else:
        print(x -1)
    sys.exit()

for i in range(n):
    if p_list[i] == x:
        j = i
        k = 1
        while j <= n-1:
            if p_list[i-k] != x-k and i != 0:
                print(x-k)
                sys.exit()
            elif p_list[i+k] != x+k and i != n-1:
                print(x+k)
                sys.exit()
            
            if p_list[i+k] == p_list[-1]:
                break
            elif p_list[i-k] == p_list[0]:
                break
            j += 1
            k += 1
            
    if p_list[i] > x:
        print(x)
        sys.exit()


#sub = min(abs(p_list[j] - x), abs(p_list[j-1] -x))

Submission status: Runtime Error

Solution code:
import numpy as np

X, N=(int(x) for x in input().split())

if N == 0 or N == 100:
    print(X)
else:
    p = list(map(int, input().split()))
    # 降順にソート
    p.sort(reverse=True)
    m = list(range(1,101))
    for aaa in p:
        m.pop(aaa-1)
    y = [X] * (100 - N)
    for i in range(0,100-N):
        y[i] = m[i] - X
    z = abs(np.array(y))
    z.sort()
    if z[0] == z[1]:
        print( X - z[0])
    else:
        print( X + z[0] )

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

X,n=map(int,input().split())
p=list(map(int,input().split()))
if n==0:
    print(X)
pp = list(map(lambda x: abs(x-X), p))
pp.sort()
for i in range(1,100):
    tmp=X-pp[0]-i
    if not tmp in p:
        print(tmp)
        sys.exit()
    tmpp=X-pp[0]+i
    if not tmpp in p:
        print(tmpp)
        sys.exit()