Problem:


Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Runtime Error

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

if N > 0:
    p = input().split()
    p = [int(i) for i in p]
    p.sort()
     
    if X > p[N - 1]:
        if X-1 == p[N-1]:
            ans = X + 1
        else :
            ans = X - 1
    else:


        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]:
                        if num - i == 0:
                            ans = p[0] -1
                            break
                        if num + i == N - 1 and X - i - 1 == p[num - i - 1]:
                            ans = p[num + 1] + 1
                            break
                        
                        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:
  p = [x - 1]
pl = sorted(p)
xn = []
mp = max(pl)
for i in range(1, 101):
  if i not in pl:
    if i <= (mp + 1):
      xn.append(i)
dxn = []
for i in range(len(xn)):
  da = abs(x - xn[i])
  dxn.append(da)
minidx = [i for i, x in enumerate(dxn) if x == min(dxn)]
print(xn[minidx[0]])

Submission status: Runtime Error

Solution code:
X, Y = map(int, input().split())
if Y == 0:
    answer = X
else:
    list_1 = list(map(int, input().split()))

    mylist = list(range(1,101))

    list_2 = list(filter(lambda x: x not in list_1, mylist))

    import numpy as np

    abslist = np.abs(list_2)

    min_num = min(abslist)

    answer = X - min_num
    
print(answer)

Submission status: Runtime Error

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

array = [[0]]*100

for i in range(100):
    array[i] = 0
tmp = input().split(' ')
for i in range(n):
    array[int(tmp[i])] += 1
dif_tmp = 999
ret = 999
for i in range(100):
    if array[99-i] == 0:
        if abs(x-(99-i)) < dif_tmp:
            ret = 99-i
            dif_tmp = abs(x-(99-i))
for i in range(100):
    if abs(x+i) <= dif_tmp:
        ret = -i
print(ret)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if(n == 0):
    print(x)
elif(n == 100):
    ff = 101-x
    gg = x
    if(ff < gg):
        print(101)
    else:
        print(0)
else:
    p = list(map(int, input().split()))
    pq = p.sorted()
    print(pq)
    m = [i for i in range(1, 101)]

    o = list(set(m) - set(p))

    ans = 100000
    dif = abs(ans - x)
    for i in range(len(o)):
        if(dif > abs(x-o[i])):
            ans = o[i]
            dif = abs(x-o[i])
    print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
X, N = map(int, input().split())
num = list(map(int, input().split()))

if N == 0:
    print(X)
else:
    num_list = [i for i in range(1, 101)]

    for i in range(X-1,-1,-1):
        if i in num:
            continue
        else:
            index1 = i
            break
            
    for i in range(X, 100):
        if i in num:
            continue
        else:
            index2 = i
            break
            
    if abs(X - index1) > abs(X - index2):
        print(index2)
    else:
        print(index1)

Submission status: Runtime Error

Solution code:
xn=input()
try:
  p=input()
except EOFError:
  x,n=xn.split()
  print(int(x))
else:
  x,n=xn.split()
  p={int(i) for i in p.split()}
  s={i for i in range(1,100)}
  s_p=list(s-p)
  d=[abs(i-int(x)) for i in s_p]
  print(s_p[d.index(min(d))])

Submission status: Runtime Error

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

if N == 0:
    print(X)
    exit()
else:
    p_int_list = list(map(int, input().split()))
    p_int_list = sorted(p_int_list)


ans_range = []
for i, j in zip(p_int_list[:-1], p_int_list[1:]):
    if j < 0:
        if abs(j) <= X <= abs(i):
            ans_range = [abs(j), abs(i)]
    else:
        if i <= X <= j:
            ans_range = [i, j]
            if i < 0:
                print(0)
                exit()

ans = 0
p_int_set = set(p_int_list)

if ans_range[1] - ans_range[0] != 1:
    if ans_range[1] == X:
        print(ans_range[1] - 1)
        exit()
    elif ans_range[0] == X:
        if X - 1 in p_int_set:
            print(X + 1)
            exit()
        else:
            print(X + 1)
            exit()
elif ans_range[1] - ans_range[0] == 1:
    for i in range(1, N):
        if ans_range[0] - i not in p_int_set:
            print(ans_range[0] - i)
            exit()
        elif ans_range[1] + i not in p_int_set:
            print(ans_range[1] + i)
            exit()

Submission status: Runtime Error

Solution code:
x, n = input().split(' ')
line = input()
if line == '':
    print(x)
    exit()

x = int(x)

alist = line.split(' ')
for i in range(int(n)):
    alist[i] = int(alist[i])
if not x in alist:
    print(x)
    exit()

blist = [i for i in range(1,101)]
bset = set(blist)
aset = set(alist)
cset = bset-aset
clist = list(cset)
clist.append(x)
clist.sort()

count = 0
for i,v in enumerate(alist):
    if v == int(x):
        count = i
if count == 0:
    print(alist[1])
elif count == 99:
    print(alist[-2])
else:
    minx = x - alist[count-1]
    maxx = alist[count+1]-x
    if minx > maxx:
        print(alist[count+1])
    else:
        print(alist[count-1])

Submission status: Runtime Error

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

array = [[0]]*100

for i in range(100):
    array[i] = 0
tmp = input().split(' ')
for i in range(n):
    array[int(tmp[i])] += 1
dif_tmp = 999
ret = 999
for i in range(100):
    if array[99-i] == 0:
        if abs(x-(99-i)) < dif_tmp:
            ret = 99-i
            dif_tmp = abs(x-(99-i))
for i in range(100):
    if abs(x+i) < dif_tmp:
        ret = -i
print(ret)

Submission status: Runtime Error

Solution code:
inn=[]
arr=[]
tt=0
inn=list(map(int,input().strip().split()))[:2]
arr=list(map(int,input().strip().split()))[:inn[1]]
arr.sort()
for i in range(inn[1]-1):
  if inn[0]>=arr[i] and inn[0]<=arr[i+1]:
    if inn[0]==arr[i]:
      tt=arr[i+1]+1
      break
    elif inn[0]==arr[i+1]:
      tt=arr[i+2]+1
      break
    else:
      tt=arr[i+1]+1
      break
print(tt)

Submission status: Runtime Error

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

for i in p:
    p_change.append(abs(i-x))

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

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
h = list(map(int, input().split()))
h.sort(reverse = True)
l = []
for i in range(0, N):
    d = []
    for j in range(0, max(0, len(l))):
        if l[j] % h[i] == 0:
            d.append(l[j])
    for k in range(0, len(d)):
        l.remove(d[k])
    l.append(h[i])
if len(collections.Counter(h)) == 1:
    l.clear()
print(len(l))

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
ls=inp()
ls.sort()
if n==0:
    print(x)
    exit(0)
else:
    a=x-1
    b=x+1
    flag=False
    while(not flag):
        if a not in ls:
            print(a)
            exit(0)
        else:
            a-=1
        if b not in ls:
            print(b)
            exit(0)
        else:
            b+=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 > 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)

  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:
import math
input_a= input().split(" ")
X=int(input_a[0])
N=int(input_a[1])
dis=X+3
if N!=0:
  array= input().split(" ")
else:
  array=[0,0]

num=X
num2=-100
for i in range(N+1):

  
  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(dis):
  
  if str(num) not in array:
    
    dis2=abs(X-num)
    num3=X+dis2

    if str(num3) not in array:
    	numb=min([num,num3])
    else:
      numb=num
      break
  num=num-1

if dis<dis2:
  print(numa)
elif dis==dis2:
  print(numb)
else:
  print(numb)

Submission status: Runtime Error

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

if n <= 0:
    print(x)
else:
    q = p
    q.sort()
    p2 = [x for x in range(1,q[-1]+n)]

    p_p2_diff = set(p)^set(p2)
    p_p2_diff_list = list(p_p2_diff)

    min_list = []
    for i in range(len(p_p2_diff_list)):
        val = abs(x - p_p2_diff_list[i])
        min_list.append(val)

    print(p_p2_diff_list[min_list.index(min(min_list))])

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n != 0:
  p = list(map(int, input().split()))
  print(p)
else:
  p = [x - 1]
pl = sorted(p)
xn = []
mp = max(pl)
for i in range(1, 101):
  if i not in pl:
    if i <= (mp + 1):
      xn.append(i)
dxn = []
for i in range(len(xn)):
  da = abs(x - xn[i])
  dxn.append(da)
minidx = [i for i, x in enumerate(dxn) if x == min(dxn)]
print(xn[minidx[0]])

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
l = (int(i) for i in input().split())
if N == 0:
  print(X)

QUEUE = set()
def search(x):
  global QUEUE
  small = x - 1
  large = x + 1
  if small in QUEUE or large in QUEUE:
    return
  else:
    QUEUE.add(small)
    QUEUE.add(large)
    if not small in l:
      print(small)
      sys.exit(0)
    elif not large in l:
      print(large)
      sys.exit(0)
search(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 and n!=1 and n!=100:
    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

if n==1:
    ans=x-1

if n==100:
    ans=0

print(ans)

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
p_list = set([int(i) for i in input().split()])
set_all = set(np.arange(-100, 101))
ex_list = set_all-p_list
ex_list = list(ex_list)
diff_list = [np.abs(i-X) for i in ex_list]
min_index = np.argmin(diff_list)
print(ex_list[min_index])

Submission status: Runtime Error

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

s = 0
u = -1
for i in a:
    t = 0
    for j in a:
        if j != i and i % j == 0:
            t += 1
    if j != i and t == 0:
        s += 1
print(s)

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)]
    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:
#!/usr/bin/python
# -*- Coding: utf-8 -*-

x, n = (int(x) for x in input().split())
p_li = [int(x) for x in input().split()]

if n == 0:
    print(x)
else:
    p_li.sort()
    pst = p_li.index(x)
    if x not in p_li == True:
        print(x)
    else:
        for i in range(100):
            if x - i != p_li[pst - i]:
                print(x - i)
                break;
            elif x + i != p_li[pst + i]:
                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()))
    abs_list = []
    re_list = []
    min = 1000
    min_index = 0

    for i in range(100):
        abs_list.append(i + 1)
    for j in p:
        abs_list.remove(j)
    for i in range(len(abs_list)):

        re_list.append(abs(abs_list[i] - X))
    for i in range(len(re_list)):
        if min > re_list[i]:
            min = re_list[i]
            min_index = i
    
    print(abs_list[min_index])

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)

L = []
for i in range(1, 101):
    if(i in P): continue
    else: L.append(i)
m = 1000
for l in L:
    m = min(m, abs(X - l))
ans = []
for l in L:
    if(abs(X - l) == m):
        ans.append(l)
ans.sort()
print(ans[0])

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
flaga = 0
flagb = 0
if(n == 0):
    print(x)
for i in range(n):
    p = list(input())

for i in range(1,n):
    for j in range(n):
        if x-i == p[j]:
            flaga = 1
        if x+i == p[j]:
            flagb = 1
    if(flaga == 0):
        print(x-i)
    elif(flagb == 0):
        print(x+i)
    elif(flaga == 0 and flagb == 0):
        print(x-i)

Submission status: Runtime Error

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

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

  # 含まれない整数
  Pi = [i for i in list(range(1, 101)) if i not in p]

  Pi = list(reversed(Pi))
  d = {abs(X-p): p for p in Pi}

  min_abs = sorted(d)[0]

  print(d[min_abs])

Submission status: Runtime Error

Solution code:
inn=[]
arr=[]
tt=0
inn=list(map(int,input().strip().split()))[:2]
arr=list(map(int,input().strip().split()))[:inn[1]]
arr.sort()
for i in range(inn[1]-1):
  if inn[0]>=arr[i] and inn[0]<=arr[i+1]:
    if inn[0]==arr[i]:
      tt=arr[i+1]+1
    elif inn[0]==arr[i+1]:
      tt=arr[i+2]+1
    else:
      tt=arr[i+1]+1
print(tt)

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)
    for i in range(a,100):
        if i in ccc:
            continue
        else:
            x = i
            break
    for i in reversed(range(-100, a)):
        if i in ccc:
            continue
        else:
            y = i
            break
    if x-a<a-y:
        print(x)
    else:
        print(y)
else:
    d = input()
    print(a)

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()
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)
    
d = abs(diff_p[0] - x)
ans = diff_p[0]
for i in range(1, len(diff_p)):
    d1 = abs(diff_p[i] - x)
    if d1< d:
        d = d1
        ans = diff_p[i]
    else:
        break
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

if N == 0:
    print(X)
else:
    A = [i for i in range(1,101)]

    for i in P:
        A.remove(i)

    a = (np.array(A) - X)**2
    j = np.argmin(a)
    if (A[j] - X)**2 >= X**2:
        print(0)
    else:
        print(A[j])

Submission status: Runtime Error

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


else:
    p = list(map(int, input().split()))
    abs_list = []
    re_list = []
    min = 1000
    min_index = 0

    for i in range(100):
        abs_list.append(i + 1)
    for j in p:
        abs_list.remove(j)
    for i in range(len(abs_list)):

        re_list.append(abs(abs_list[i] - X))
    for i in range(len(re_list)):
        if min > re_list[i]:
            min = re_list[i]
            min_index = i
    print(abs_list[min_index])

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
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))
address = b_tmp.index(min(b_tmp))
print(b[address])

Submission status: Runtime Error

Solution code:
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
x,n=get_ints()
p=get_array()
for i in range(1,102):
    if i==x:
        for j in range(i,0,-1):
            if j in p:
                continue 
            else:
                ans1=j
                break
        for k in range(i,102):
            if k in p:
                continue 
            else:
                ans2=k 
                break
        break 
if ans2-x<x-ans1:
    print(ans2)
elif x-ans1<ans2-x:
    print(ans1)
else:
    print(ans1)

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
if N > 0:
    A = list(map(int,input()))
    for i in range(100):
        x = X - i
        y = X - i
    if x not in A:
        print(x)
        quit()
    if y not in A:
        print(y)
        quit()
else:
    print(N)

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

Submission status: Runtime Error

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

  # 含まれない整数
  Pi = [i for i in list(range(1, 101)) if i not in p]

  Pi = list(reversed(Pi))
  d = {abs(X-p): p for p in Pi}

  min_abs = sorted(d)[0]

  print(d[min_abs])

Submission status: Runtime Error

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

array = [[0]]*100

for i in range(100):
    array[i] = 0
tmp = input().split(' ')
for i in range(n):
    array[int(tmp[i])] += 1
dif_tmp = 999
ret = 999
for i in range(100):
    if array[99-i] == 0:
        if abs(x-(99-i)) < dif_tmp:
            ret = 99-i
            dif_tmp = abs(x-(99-i))
            
print(ret)

Submission status: Runtime Error

Solution code:
n=int(input())
li = list(map(int,input().split()))
count=0

for i in range(100):
  for j in range(n):
    if i == j:pass
    elif li[i]%li[j] == 0:break
    elif j == n-1:count +=1

print(count)

Submission status: Runtime Error

Solution code:
def forbidden(x,p):
    res = []
    for num in range(1,101):
        if x!=num and num not in p:
            res.append(abs(x-num))
    if x-min(res) not in p and x-min(res)!=0:
        return x-min(res)
    return x+min(res)

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

Submission status: Runtime Error

Solution code:
import numpy as np
d=np.arange(0,101)
a, b = map(int, input().split())
c=(map(int, input().split()) 
e=(np.delete(d, np.where(c)[1], 1)-a)
print(min(e))

Submission status: Runtime Error

Solution code:
X,N = map(int,input())
if N > 0:
    A = list(map(int,input()))
    for i in range(100):
        x = X - i
        y = X - i
    if x not in A:
        print(x)
        quit()
    if y not in A:
        print(y)
        quit()
else:
    print(N)

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()
Max = p[-1] * 2
li_p = [i for i in range(1, Max)]
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)):
    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:
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))],101):
        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]
    #ans2 = sorted(ans2)
    print(ans[ans2.index(min(ans2))])
   # print(min(ans))

Submission status: Runtime Error

Solution code:
def linked_merge_sort(l): #マージソート
    if len(l) == 1:
        return
    q, r = divmod(len(l), 2)
    left = [l.pop() for _ in range(q)]
    right = [l.pop() for _ in range(q + r)]
    
    linked_merge_sort(left)
    linked_merge_sort(right)
    
    left.reverse()
    right.reverse()
    while left and right:
        if left[-1] <= right[-1]:
            l.append(left.pop())
        else:
            l.append(right.pop())
    while left:
        l.append(left.pop())
    while right:
        l.append(right.pop())
    return

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

for i in range(n):
    p[i]=p[i]-x
if n>1:
    linked_merge_sort(p)
    j=n-1
    for i in range(n):
        if p[i]>=0:
            j=i
            break
    for i in range(50):
        if j-i>=0:
            if p[j-i]!=-i:
                ans = x-i
                break
        elif j-i<0:
            ans=x+p[0]-1
            break
        if j+i<n:
            if p[j+i]!=i:
                ans = x+i
                break
        else:
            ans=x+p[n-1]+1
            break
elif n==1:
    if p[0]==0:
        ans=x-1
    else:
        ans=x
elif n==0:
    ans=x
print(ans)

Submission status: Runtime Error

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

# 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:
[x,n]=[int(i) for i in input().split()]

if n!=0:
    p_list=[int(i) for i in input().split()]


    abs_list=[]
    a_list=list(range(min(p_list),max(p_list)+1))

    for i in p_list:
        a_list.remove(i)

   

    for i in a_list:
     abs_list.append(abs(x-i))
    
    num=abs_list.index(min(abs_list))
    print(a_list[num])

else:
    print(x)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
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>1:
    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)
elif n==0:
    print(x)
elif n==1:
    if x==p[0]:
        print(x-1)
    else:
        print(x)

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
p_list = set([int(i) for i in input().split()])
set_all = set(np.arange(0, 101))
ex_list = set_all-p_list
ex_list = list(ex_list)
diff_list = [np.abs(i-X) for i in ex_list]
min_index = np.argmin(diff_list)
print(ex_list[min_index])

Submission status: Runtime Error

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

for i in p:
    p_change.append(abs(i-x))

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

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 :
    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:
#!/usr/bin/python
# -*- Coding: utf-8 -*-

x, n = (int(x) for x in input().split())
p_li = [int(x) for x in input().split()]

if n == 0:
    print(x)
else:
    p_li.sort()
    pst = p_li.index(x)
    if x not in p_li == True:
        print(x)
    else:
        for i in range(n):
            if x - i != p_li[pst - i]:
                print(x - i)
                break;
            elif x + i != p_li[pst + i]:
                print(x + i)
                break;

Submission status: Runtime Error

Solution code:
import math
input_a= input().split(" ")
X=int(input_a[0])
N=int(input_a[1])
dis=X+3
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(dis):
  
  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:
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()
if X <=50:
    print("0")
else:
    print("101")

Submission status: Runtime Error

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

result = 100

l = list(range(1,101))


if len(p) == 0:
    kotae = x
else:
    for i in range(len(p)):

        l[p[i]-1] = 0

    for i in reversed(range(len(l))):
        #print(l[i])
  

        if l[i] != 0:

            if result >= abs(l[i] - x):
                result = abs(l[i] - x)
               
                kotae = l[i]
          
            



print(kotae)

Submission status: Runtime Error

Solution code:
import collections
x,n=map(int,input().split())
l=list(map(int,input().split()))
v=collections.Counter(l)
if n==0:
    print(x)
else:
    for i in  range(101):
        if x not in v:
            ans=x
            break
            
        if x+1 not in v:
            ans=x+1
            break
        if x-1 not in v:
            ans=x-1
            break
    print(ans)

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:
    d = input()
    print(a)