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:
N = int(input())
A = list(map(int, input().split()))
ans = 0
A = sorted(A)
if N == 0:
  ans = 0
else:
  for i in range(len(A)-1,-1,-1):
    for j in range(0,i+1,1):
      if i==j:
        ans+=1
        if i==0 and A[0]==A[1]:
          ans-=1
        break
      if A[i]%A[j]==0:
        break
      if A[i]<A[j]*2:
        ans+=1
        break

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

x,n = [int(i) for i in input().split()]
if n >0:
  table = [int(i) for i in input().split()]
  min = min(table)
  b = table
  a = np.array(table)
  a = a - x
  a = np.abs(a)
  a = np.sort(a)
    #print(a)

  for i in range(n):
    if a[0] > 0:
      print(x)
      break
    elif a[i+1]-a[i]>1 and i < n:
      if i == 0:
        if x-a[i]-1 in b or x-a[i]-1 < min:
          print(x+a[i]+1)
          break
        else:
          print(x-a[i]-1)
          break
      elif i > 0 and a[i] == a[i-1]:
        if x-a[i]-1 in b or x-a[i]-1 < min:
          print(x+a[i]+1)
          break
        else:
          print(x-a[i]-1)
          break
      else:
        if x-a[i] in b or x-a[i] < min:
          print(x+a[i])
          break
        else:
          print(x+a[i])
          break
else:
  print(x)

Submission status: Runtime Error

Solution code:
X, N = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    Ps = set([int(i) for i in input().split()])
    # coords = set(range(min(Ps), max(Ps)+1))
    # for p in Ps:
    #     coords.remove(p)
    # if X in coords:
    #     print(X)
    # else:
    #     ret = [ (v, abs(X-v)) for v in coords ]
    #     minval = min(ret, key=lambda elm: elm[1])[0]
    #     print(
    #         min([ elm[0] for elm in ret if minval == elm[0] ])
    #     )
    coords = list(range(1, 101))
    if not X in Ps:
        print(X)
    i = X - 1
    diff = 0
    while True:
        if not coords[i - diff] in Ps:
            print(coords[i - diff])
            break
        if not coords[i + diff] in Ps:
            print(coords[i + diff])
            break
        diff += 1

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
try:
    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)
except EOFError as e:
    print(x)

Submission status: Runtime Error

Solution code:
x,n = input().split(' ')
X = int(x)
N = int(n)
if N == 0:
  print(X)
else:
  p = input().split(' ')
  P = []
  for pp in p:
    P.append(int(pp))

  diffs = []
  min_num = []
  
  for i in range(1,max(P)):
    if i not in P:
      diffs.append(abs(X-i))
      min_num.append(i)
  print(min_num[diffs.index(min(diffs))])

Submission status: Runtime Error

Solution code:
import numpy as np

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

P = np.array(map(int, input().split()))

greater = np.arange(X, X+N+1)
lower = np.arange(X+N+1, X, -1)
total = np.concatenate((greater, lower))

mask = []
for p in P:
  mask.append(np.where(total == p))

mask = np.array(mask).flatten()

min_ = total - X
min_[mask] = 1e10

result = total[np.argmin(min_)]

print(total.min())

Submission status: Runtime Error

Solution code:
a=input().split(' ')
X=int(a[0])
N=int(a[1])

if N!=0:
  Ls=input().split(' ')
  L=[]
  for i in range(N):
    L.append(int(Ls[i]))
  for i in range (N):
    if X-i in L and X+i in L:
      pass
    elif X-i not in L:
      s=X-i
      break
    elif X-i in L and X+i not in L:
      s=X+i
      break
else:
  s=X


print(s)

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

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-lmin)
        elif p==X-l1min:
            print(X+l1min)
else:
    print(X-l1min)

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(0,6))



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

        l[p[i]] = 200


    for i in reversed(range(len(l))):
     
  

        if l[i] != 200:

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



print(kotae)

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
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())
p = list(map(int,input().split()))

if (1 <= X <= 100) and (0 <= N <= 100) and (((max(p) <= 100) and (1 <= min(p))) or N == 0) :
    ans = X-1
    bns = X+1
    if N != 0:
    
        for i in range(N):
            if ans not in p:
                print(ans)
                break
            
            if ans in p:
                ans-=1         
                if ans not in p:
                    print(ans)
                    break
                
            if bns not in p:
                print(bns)
                break
            
            if bns in p:
                bns+=1
                if bns not in p:
                    print(bns)
                    break
    elif N ==0:
        print(X)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
if n = 0:
  print(x)
  break
  
l=list(map(int, input().split()))
a = x
b = x

if not x in l:
  print(x)
else:
  for i in range((len(l)-1)//2):
    a -= 1
    b += 1
    if not a in l and not b in l:
      print(a)
      break
    elif a in l and not b in l:
      print(b)
      break
    elif not a in l and b in l:
      print(a)
      break
    else:
      pass

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:
    if y in a:
        z=y+1
    elif not y in a:
        print('y')
        break
    elif z in a:
        z+=1
    else:
        break
while:
    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, i1.split(' '))]
pn = [x for x in map(int, i2.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
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:
# 初期入力
import sys
input = sys.stdin.readline
X,N = (int(i) for i in input().split())
if N !=0:
    p = list(map(int, input().split()))
else:
    p=[-1]
#
ans =[]
for i in range(1,101):
    if i not in p:
        ans.append((abs(i-X),i))
ans.sort()
print(ans[0][1])

Submission status: Runtime Error

Solution code:
A, B = map(int, input().split())
if B == 0:
    print(A)
else:
    L=list(map(int,input().split()))
    K = L.copy()
    L = [abs(i - A) for i in L]
    L +=[0]
    L=sorted(L)
    x=0
    i,j=0,1
    while True:
        if L[i] == x and L[j] == x :
            i,j = i+2,j+2
            x += 1
        else:
            break
    S , Y = A-x , A+x
    if S in K == True :
        print(Y)
    else:
        print(S)

Submission status: Runtime Error

Solution code:
X_N = [int(i) for i in input().split()]
X = X_N[0]
N = X_N[1]


if N != 0:
    p = [int(i) for i in input().split()]
    ary = [i for i in range(1,101)]
    for j in range(N):
        if p[j] in ary:
            ary.remove(p[j])
    min = abs(X-ary[0])
    index = ary[0]
    for j in range(1,len(ary)):
        if min > abs(X-ary[j]):
            min = abs(X-ary[j])
            index = ary[j]

elif N == 0:
    index = X

print(index)

Submission status: Runtime Error

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

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

    num=[1]*101
    count=1

    for i in p:
        num[i]=0   
    if num[x]==1:
        print(x)
    while True:
        if x-count>-1:
            if num[x-count]==1:
                print(x-count)
                break
        if x+count<102:
            if num[x+count]==1:
                print(x+count)
                break    
        count+=1

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:
A = list(map(int,input().split()))
X=A[0]
N=A[1]
lists=[]
for i in range(N+1,1,-1):
  lists.append(abs(X-A[i]))
j=0
while j in lists:
  j=j+1
print(X-j)

Submission status: Runtime Error

Solution code:
ans = []
x,n = map(int,input().split())
l = list(map(int,input().split()))

l.sort()

ans.append(x)

nl = [0] * 100


for i in l:
    nl[i] = i

if(not (n == 0)):
    #プラス方向
    mx = x+1
    if(mx < 100):
        for i in range(x+1,len(nl)+1):
            if( nl[i] ==  0):
                ans.append(mx)
                break
            mx = mx + 1
    
    
    mi = x - 1
    if(mi > 1):
        for i in range(x-1,1,-1):
            if( nl[i] ==  0):
                ans.append(mi)
                break
            mx = mx + 1        

print(min(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
A = sorted(A)
if N == 0:
  ans = 0
else:
  for i in range(len(A)-1,-1,-1):
    for j in range(0,i+1,1):
      if i==j:
        ans+=1
        if i==0 and A[0]==A[1]:
          ans-=1
        break
      if A[i]%A[j]==0:
        break
      if A[i]<A[j]*2:
        ans+=1
        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 = sorted(p)
lista = list(range(1,101))
for i in p:
    if i in lista:
        lista.remove(i)
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    print(list[idx])
if N == 0:
    print(X)
else:
    getNearestValue(lista, X)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
q=[]
for i in range(100):
    q.append(i)

for j in range(0,n):
    q.remove(p[j])

b=101
min=999
for k in range(0,len(q)):
    a=x-q[k]
    if min>=abs(a):
        min=abs(a)
        b=k
        
print(b+1)

Submission status: Runtime Error

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

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

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

ss = []
for i in range(s[0],s[N-1]+1):
    ss.append(i)
    
result = list(set(ss) - set(s))

ans = []
for i in range(len(result)):
    ans.append(abs(X - result[i]))

print(result[ans.index(min(ans))])

Submission status: Runtime Error

Solution code:
import numpy as np

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


if N == 0:
    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:
X, N = list(map(int, input().split()))
if N == 0:
  print(X)
  exit()
p = list(map(int, input().split()))

p_ = [i for i in range(101)]
p_ = list(set(p_) - set(p))

list = []
list_ = []
for j in p_:
  C = abs(X-j)
  list.append(C)
  list_.append(X-j)
list.sort()
if list[0] == list[1]:
  print(X-list[0])
elif list_.count(list[0]) == 0:
  print(X+list[0])
else:
  print(X-list[0])

Submission status: Runtime Error

Solution code:
import sys

X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

comp = 101
for i in range(100):
    i += 1    
    x = abs(X - i)
    if comp > x and i not in p:
        comp = x
        result = i

print(result)

Submission status: Runtime Error

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

if (1 <= X <= 100) and (0 <= N <= 100) and (max(p) <= 100) and (1 <= min(p)) :
    ans = X-1
    bns = X+1
    if N != 0:
    
        for i in range(N):
            if ans not in p:
                print(ans)
                break
            
            if ans in p:
                ans-=1         
                if ans not in p:
                    print(ans)
                    break
                
            if bns not in p:
                print(bns)
                break
            
            if bns in p:
                bns+=1
                if bns not in p:
                    print(bns)
                    break
    elif N ==0:
        print(X)

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)

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

print(ANS)

Submission status: Runtime Error

Solution code:
import numpy as np

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

if N == 0:
    print(X)
else:
    # 降順にソート
    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:
X,N = map(int, input().split())
if N==0:
    print(X)
else:
    p=list(map(int,input().split()))
    A=[i for i in range(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=a

print(answer)

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
lst = list(map(int,input().split()))
lst.sort()
if len(lst) == 0 :
    print(x)
    exit()
a = X
while a in lst :
    a += 1
b = X
while b in lst:
    b -= 1
if X-b > X-a :
    print(a)
else :
    print(b)

Submission status: Runtime Error

Solution code:
#C

ans = []
x,n = map(int,input().split())
l = list(map(int,input().split()))

l.sort()

ans.append(x)

print(x,n)
print(l)

nl = [0] * 100


for i in l:
    nl[i] = i

if(not (n == 0)):
    #プラス方向
    mx = x+1
    if(mx < 100):
        for i in range(x+1,len(nl)+1):
            if( nl[i] ==  0):
                ans.append(mx)
                break
            mx = mx + 1
    
    
    mi = x - 1
    if(mi > 1):
        for i in range(x-1,1,-1):
            if( nl[i] ==  0):
                ans.append(mi)
                break
            mx = mx + 1        

print("ans=",ans)
print(min(ans))

Submission status: Runtime Error

Solution code:
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(-100, 101) if i != 0]

    for i in range(X-1,-1,-1):
        if i in num:
            continue
        else:
            index1 = i
            break
            
    for i in range(X+1, 101):
        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:
X, N = list(map(int, input().split()))
if N == 0:
  print(X)
  exit()
p = list(map(int, input().split()))

p_ = [i for i in range(101)]
p_ = list(set(p_) - set(p))

list = []
list_ = []
for j in p_:
  C = abs(X-j)
  list.append(C)
  list_.append(X-j)
list.sort()
if list[0] == list[1]:
  print(X-list[0])
elif list_.count(list[0]) == 0:
  print(X-list[0])
else:
  print(X+list[0])

Submission status: Runtime Error

Solution code:
import sys

X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

comp = 101
for i in range(1, 101):
    x = abs(X - i)
    if comp == x:
        break
    if comp > x and i not in p:
        comp = x
        result = i

print(result)

Submission status: Runtime Error

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

A.sort()
L = []
pre_val = A[0]
count = 0
for a in A:
    if pre_val == a:
        count += 1
    else:
        temp = [pre_val, count]
        L.append(temp)
        count = 1
        pre_val = a
L.append([pre_val, count])

res = 0
for i in range(len(L)):
    flag = False
    if L[i][1] != 1:
        continue
    Ai = L[i][0]
    for j in range(i):
        Aj = L[j][0]
        if Ai % Aj == 0:
            flag = True
            break
    if flag is False:
        res += 1
print(res)

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

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

X, T = map(int, input().split())
Y = list(map(int, input().split()))
L = list(map(abs,Y))
print(gnv(L, X))

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
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 = map(int,input().split())
p = list(map(int,input().split()))
ue = 0
shita = p[0]

#xより値の大きい値を順にひかくしていき、リストpに存在しない最小値を取得する
for i in range(x+1,p[-1]):
    if False == i in p:
        ue = i
        break

#xより値の小さい値を順に比較していき、リストpに存在しない最大値を取得する
for i in range(p[0],x):
    if False == i in p:
        if shita < i:
            shita = i

if ue == 0 and shita == p[0]:
    print(x)       
elif abs(x-ue) >= abs(x-shita):
    print(shita)
else:
    print(ue)

Submission status: Runtime Error

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

A.sort()
L = []
pre_val = A[0]
count = 0
for a in A:
    if pre_val == a:
        count += 1
    else:
        temp = [pre_val, count]
        L.append(temp)
        count = 1
        pre_val = a
L.append([pre_val, count])

res = 0
for i in range(len(L)):
    flag = False
    if A[i][1] != 1:
        continue
    Ai = L[i][0]
    for j in range(i):
        Aj = L[j][0]
        if Ai % Aj == 0:
            flag = True
            break
    if flag is False:
        res += 1
print(res)
N = int(input())
A = list(map(int, input().split()))

A.sort()
L = []
pre_val = A[0]
count = 0
for a in A:
    if pre_val == a:
        count += 1
    else:
        temp = [pre_val, count]
        L.append(temp)
        count = 1
        pre_val = a
L.append([pre_val, count])

res = 0
for i in range(len(L)):
    flag = False
    if A[i][1] != 1:
        continue
    Ai = L[i][0]
    for j in range(i):
        Aj = L[j][0]
        if Ai % Aj == 0:
            flag = True
            break
    if flag is False:
        res += 1
print(res)

Submission status: Runtime Error

Solution code:
X, N = map(int,input().split())
 
if N == 0:
  print(X)
else:
  p = list(map(int, input().split()))
  if X not in p:
    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:
import sys

X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

comp = 101
for i in range(1, 101):
    x = abs(X - i)
    if comp > x and i not in p:
        comp = x
        result = i

print(result)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
if(n==0):
  print(x)
else:
    l=[]
    l1=[]
    li=list(map(int,input().split()))
    for i in range(n):
        if x-i not in li:
            l.append(x-i)
        if x+i not in li:
            l1.append(x+i)
    a=max(l)
    b=min(l1)
    if(abs(a-x)>abs(b-x)):
        print(b)
    else:
        print(a)

Submission status: Runtime Error

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

ans = X
for j in range(N):
    if ans == P[j]:
        judge = 1
        cri = j
if judge == 0:
    print(ans)
    exit()
else:
    for i in range(1,X):
        ans = X - i
        if cri - i >= 0:
            if ans != P[cri-i]:
                print(ans)
                exit()
            ans = X + i
        if cri + i <= N:
            if ans != P[cri+i]:
                print(ans)
                exit()
print(ans)

Submission status: Runtime Error

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

p.sort()

p0 = []
j = 0
for i in range(1,100):
    if p[j]!=i:
        p0.append(i)
    elif p[j] == i:
        j+=1
    if j == N:
        for i0 in range(i+1,100):
            p0.append(i0)
        break

p1 = [0 for i in range(len(p0))]
for i in range(len(p0)):
    p1[i] = p0[i]-X
    p1[i] = np.abs(p1[i])
    
ii = np.argmin(p1)

print(p0[ii])

Submission status: Runtime Error

Solution code:
a=input().split(' ')
X=int(a[0])
N=int(a[1])

if N!=0:
  Ls=input().split(' ')
  L=[]
  for i in range(N):
    L.append(int(Ls[i]))
else:
  s=X

for i in range (N):
  if X-i in L and X+i in L:
    pass
  elif X-i not in L:
    s=X-i
    break
  elif X-i in L and X+i not in L:
    s=X+i
    break
print(s)

Submission status: Runtime Error

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

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

a = [i for i in range(-110,210)]

for j in p:
    d = a.index(j)
    a.pop(d)

a.append(x)
a = set(a.sort())

idx_x = a.index(x)

if (idx_x == 0):
    print(a[idx_x+1])
    sys.exit()
if (idx_x == len(a)-1):
    print(a[-2])
    sys.exit()

lesser = a[idx_x-1]
greater = a[idx_x+1]

dl = abs(x - lesser)
dg = abs(greater - x)

if (dl <= dg):
    print(lesser)
else:
    print(greater)

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()
    if x not in p_li == True:
        print(x)
    else:
        pst = p_li.index(x)
        for i in range(1,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:
import sys

X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

comp = 101

for i in range(1, 101):
    x = abs(X - i)
    if x == comp:
        break
    if comp > x and i not in p and:
        comp = x
        result = i

print(result)

Submission status: Runtime Error

Solution code:
n, ls = [int(x) for x in input().strip().split(' ')]
if ls==0:
    print(n)
elif ls==1:
    print(n-1)
else:
    x = [int(x) for x in input().strip().split(' ')]
    x.sort()
    a = []
    for y in range(1,x[-1]):
        if y not in x:
            a.append(y)
    # print(a)
    b = {}
    for y in range(len(a)):
        b.update({a[y]: abs(n-a[y])})
    print(min(b.keys(), key=(lambda k: b[k])))

Submission status: Runtime Error

Solution code:
k = []
for i in range(1,101):
    k.append(int(i))
x,n = map(int,input().split())
try:
    p = list(map(int,input().split()))
except EOFError:
    pass

if n == 0:
    print(x)
else:
    for i in range(0,len(p)):
        if p[i] != x:
            k.remove(p[i])
    l = k.index(x)
    if abs(k[l]-k[l-1]) < abs(k[l]-k[l+1]) or x < k[l+1]:
        print(k[l-1])
    else:
        print(k[l+1])

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
try:
  P = list(map(int,input().split()))
except:
  print(100)
  exit()
  
list100 = list(range(100))

for i in range(N):
  list100.remove(P[i])
  
list100.sort()
list100_X = [abs(X - num) for i,num in enumerate(list100)]
 
min_list100_X = min(list100_X)   

print(min(abs(X - min_list100_X),abs(min_list100_X - X)))

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])
n
mindis = 100
for i in range(100-len(n)):
  dis = abs(X-xn[i])
  if dis < mindis:
    mindis = dis
    answer = xn[i]
print(answer)

Submission status: Runtime Error

Solution code:
def main():
  x, n = map(int, input().split())
  m = list(map(int, input().split()))
  
  for i in range(n+1):
    hui = list(abs(x-m[i]))
    k=hui.index(min(hui)
    
    
    if k > 1:
      for j in range(k+1):
                oui = list(m[j])
                yue = min(oui)
                print(yue)
    else:
                print(k)
main()

Submission status: Runtime Error

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

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

# x, n = 1, 1
# # p = list(range(1, 101))
# p = [1]

# 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 = np[0]
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 = list(map(int,input().split()))


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

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

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

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

Submission status: Runtime Error

Solution code:
import sys

X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

comp = 101

for i in range(1, 101):
    x = abs(X - i)
    if x == comp:
        sys.exit()
    if comp > x and i not in p and:
        comp = x
        result = i

print(result)