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())
minn = 10000000
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))
for i in range(1, 101):
    if i not in p:
        tmp = abs(x-i)
        if minn > tmp:
            ans = i
            minn = tmp
        elif minn == tmp:
            ans = min(i, ans)

print(ans)

Submission status: Runtime Error

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

arr = []
tmp = input()
num = tmp.split(' ')
num_li = [int(i) for i in num]
arr.extend(num_li)

arr.sort()

min = x
max = x

for i in range(10000):
    if len(arr) == 1:
        print(x)
        break

    min -= 1
    max += 1

    if min not in arr:
        print(min)
        break

    if max not in arr:
        print(max)
        break

Submission status: Runtime Error

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



l=[i for i in range(1, 101)]
for i in range(A[1]):
  l.remove(B[i])


for i in range(len(l)):
  l[i]=abs(A[0]-l[i])

if A[1]==0:
  print(A[0])
else:
  print(min(l)+A[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()))

  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
  if n==0:
    print(x)
  else:
    print(i)

Submission status: Runtime Error

Solution code:
x,n = map(int, input().split())
p = sorted(map(int, input().split()))
if p == []:
    print(x)
else:
    a = p[-1]
    d =[]
    e = 1
    E = 0
    b = 1000
    c = 0
    for i in range(a):
        d += [e]
        e += 1
    for i in range(n):
        d.remove(p[E])
        E += 1
    for i in range(n):
        b = min(abs(x-d[c]),b)
        c += 1
    if (x+b) in d:
        print(x+b)
    else:
        print(x-b)

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

        value_left=x-1
        value_right=x+1

        if index!=0:
            index_left=index-1
        if index!=n:
            index_right=index+1
        
        if index==0:
            ans=x-1
        elif index==n:
            if num_list[index_right-1]!=x-1:
                ans=x+1
        else:
            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
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n:
                    index_right=index_right+1
                value_left=value_left-1
                value_right=value_right+1

if n==1:
    ans=x-1

if n==100:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

Submission status: Runtime Error

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

arr = [x]
tmp = input()
num = tmp.split(' ')
num_li = [int(i) for i in num]
arr.extend(num_li)

arr.sort()
arr = list(set(arr))

min = x
max = x

for i in range(10000):
    if len(arr) == 1:
        print(x)
        break

    min -= 1
    max += 1

    if min not in arr:
        print(min)
        break

    if max not in arr:
        print(max)
        break

Submission status: Runtime Error

Solution code:
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
list_p = [i for i in range(-1, 102)] 
t = x
num = x

if(x == n):
  print(x - 1)
  sys.exit()

for i in p:
  list_p[i + 1] = -2

for i in range(len(list_p)):
  if(list_p[i] == -2):
    continue
  else:
    if(abs(list_p[i] - x) <= t):
      if(abs(list_p[i] - x) != t):
        t = abs(list_p[i] - x)
        num = list_p[i]
      elif:
        t = abs(list_p[i] - x):
        num = min(num, list_p[i])

print(num)

Submission status: Runtime Error

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

if n == 0:
    print(x)
else:
    q = []
    r = []
    min_ = 1000
    for i in range(1, 101):
        if not i in p:
            q.append(i)

    for j in q:
        k = int(abs(x - j))
        if min_ == k:
            r.append(before_j)
            r.append(j)
        min_ = min(k, min_)
        if min_ == k:
            before_j = j

    print(min(r))

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
    break

print(min(q))

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  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
  if n==0:
    print(x)
  else:
    print(i)

Submission status: Runtime Error

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

np = [0]

while len(np) < 102:
    np.append(int(len(np)))

p = p - np
c = 0
d = 1
a = (p[c] - x)*(p[c] - x)
b = (p[d] - x)*(p[d] - x)

while a >= b:
    c += 1
    d += 1

print(p[c])

Submission status: Runtime Error

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

arr = [x]
tmp = input()
num = tmp.split(' ')
num_li = [int(i) for i in num]
arr.extend(num_li)

arr.sort()
arr = list(set(arr))

min = x
max = x

for i in range(10000):
    if len(arr) == 1:
        print(x)
        break

    min -= 1
    max += 1
    
    try:
        arr.index(min)
    except:
        print(min)
        break

    try:
        arr.index(max)
    except:
        print(max)
        break

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
p = list(abs(int(i)) for i in input().split())
z = list(abs(i) for i in range(1,101))
l = p + z
l2 = list(set(l))
for i in p:
  l2.remove(i)
if x in l2:
  l2.remove(x)
z = []
for i in l2:
    a = abs(i - x)
    z.append(a)
if n == 0:
    print(x)
else:
    print(min(z) + x)

Submission status: Runtime Error

Solution code:
    X, N = map(int, (input().split(' ')))
    if N > 0:
        P = sorted(map(int, input().split(' ')))
        P_max = max(P)
        P_min = min(P)
        if X in P:
            for i in range(1, max(P_max-X + 1 , X-P_min +1)):
                if (X-i) not in P:
                    print(X-i)
                    break

                elif (X+i) not in P:
                    print(X+i)
                    break
        elif X not in P:
            print(X)
        else:
            print(" ")
    else:
        print(" ")

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

if not result:
    print X
else:
    print(result[ans.index(min(ans))])

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()
x_range = []
for i in range(0, 101):
    if i in pn:
        continue
    x_range.append(i)
diff_x = abs(x - x_range[0])
for i in range(1, len(x_range)):
    if diff_x <= abs(x - x_range[i]):
        print(x_range[i-1])
        break
    else:
        diff_x = abs(x - x_range[i])

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
m=X
for i in range(101):
    diff=abs(X-i)
    if i not in p and diff<m and diff!=m:
        m=diff
        ans=i
print(ans)

Submission status: Runtime Error

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

np = [0]

while len(np) < 102:
    np.append(int(len(np)))

p = p - np
c = 0
d = 1
a = (p[c] - x)^2
b = (p[d] - x)^2

while a >= b:
    c += 1
    d += 1

print(p[c])

Submission status: Runtime Error

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

p_under = list(filter(lambda v: v<x, p))
p_upper = list(filter(lambda v: v>x, p))
p_under.sort(reverse=True)
p_upper.sort()

cnt = 0
while(True):
    if x - cnt not in p_under:
        print(x - cnt)
        break
    if x + cnt not in p_upper:
        print(x + cnt)
        break
    cnt += 1

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())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  numbers=list(range(-100,1000)
  ans=0

  for i in range(len(p)):
    numbers.remove(p[i])

  if numbers.count(X)==1:
    print(ans)
  else:
    for j in range(1000):
      if numbers.count(X-j)==1:
        ans=X-j
        break
      elif numbers.count(X+j)==1:
        ans=X+j
        break
  print(ans)

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)
ans1=int(-1000)
ans2=int(1000)
#print(B[3])
#print(kouho2)
for k in range(len(B)):
    if int(B[k])==int(kouho1):
        ans1=int(B[k])
        #sys.exit()
for l in range(len(B)):
    if int(B[l])==int(kouho2):
        ans2=int(B[l])
        #sys.exit()
aa1=X-0
aa2=X-ans1
aa3=ans2-X
aa4=101-X
if min(aa1,aa2,aa3,aa4)==aa1:
    print("0")
if min(aa1,aa2,aa3,aa4)==aa2:
    print(ans1)
if min(aa1,aa2,aa3,aa4)==aa3:
    print(ans2)
if min(aa1,aa2,aa3,aa4)==aa4:
    print("101")

Submission status: Runtime Error

Solution code:
import numpy as np

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

for i in p:
	notp = list(range(1,101)).remove(i)
	

index = np.abs(np.asarray(notp)-X.argmin())

print(notp[index])

Submission status: Runtime Error

Solution code:
X,N = map(int, input().split())
try:
  p = list(map(int, input().split()))
except EOFError:
  p = []

int_list = [i for i in range(1,101)]
forbidden_list = list(set(int_list) - set(p))
num_X = int_list.index(X)
c = 10000000

if X in forbidden_list:
  print(X)
else:
  for i in range(len(forbidden_list) - 1):
    a = abs(X - forbidden_list[i])
    b = abs(X - forbidden_list[i + 1])
    if a == b:
      print(forbidden_list[i])
      break
    elif c > a:
      c = a
    elif c <= a and b > a:
      print(forbidden_list[i - 1])
      break
    else:
      print(forbidden_list[i])
      break
  else:
    print(forbidden_list[-1])

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(0)
    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:
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(x)

        value_left=x-1
        value_right=x+1

        if index!=0:
            index_left=index-1
        if index!=n:
            index_right=index+1
        
        if index==0:
            ans=x-1
        elif index==n:
            if num_list[index_right-1]!=x-1:
                ans=x+1
        else:
            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
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n-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:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

Submission status: Runtime Error

Solution code:
a,b = map(int, input().split())
arr = list(map(int, input().split()))
m = -1
if b == 0:
  print(a)
for i in range(min(arr)+1, max(arr)):
  if i not in arr:
    if m > abs(i-a):
      m = abs(i-a)
      o = i
print(o)

Submission status: Runtime Error

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

q = []
r = []
min_ = 1000
for i in range(1, 101):
    if not i in p:
        q.append(i)
        
for j in q:
    k = int(abs(x - j))
    if min_ == k:
        r.append(before_j)
        r.append(j)
    min_ = min(k, min_)
    if min_ == k:
        before_j = j

print(min(r))

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
if N > 0:
    l = list(map(int, input().split()))
    A = [0] * N
    ok == 0

    for i in range(N):
        A[i] = abs(l[i] - X)

    S = A.count(0)
    if S == 0:
        print(X)
        ok = 1

    if ok == 0:
        for i in range(1, 101):
            S = A.count(i)
            if S == 0:
                print(X - 1)
                break
            if S == 1:
                if l.count(X - i) == 0:
                    print(X - i)
                    break
                else:
                    print(X + i)
                    break
            else:
                pass

else:
    print(X)

Submission status: Runtime Error

Solution code:
#C

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

l.sort()


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
            mi = mi - 1

print(min(abs(n),abs(mi),abs(mx)))

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(ans)
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())
minn = 10000000
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))

for i in range(1, 101):
    if not i in p:
        tmp = abs(x-i)
        if minn > tmp:
            ans = i
            minn = tmp
        elif minn == tmp:
            ans = min(i, ans)

print(ans)

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
t = abs(P[0]-X)
s = P[0]
for i in range(1,N):
  T = abs(P[i]-X)
  if T < t:
    t = T
    s = P[i]
  elif T == t:
    if s > P[i]:
      s = P[i]
    
print(s)

Submission status: Runtime Error

Solution code:
# x:整数
x, _ = map(int, input().split())

num_list = list(map(int, input().split()))
l = [abs(a-x) for a in num_list]
print(l)
min = num_list[l.index(min(l))]
ans = 0
for l in range(100):
  m_pla = min + l
  if ans!=0:
    break
  if min - 1 > 0:
    m_min = min-l
      
  for i in num_list:
    if m_pla != i:
      ans = m_pla
      break
    elif m_min != i:
      ans = m_min
      break

print(ans)

Submission status: Runtime Error

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

P = a[1] - 1 

list = list(map(lambda x: x+1, list(range(b[P]))))

if a[1] == 0:
  print(a[0])
  exit()

for i in range(a[1]):
  list.remove(b[i])

num = 0

result = []

for i in range(a[1]):
  x = a[0] - b[num]
  result.append(abs(x))
  num += 1

print(min(result))

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 = map(int, input().split())
p = sorted(map(int, input().split()))
if p == []:
    print(x)
else:
    a = p[-1]
    d =[]
    e = 1
    E = 0
    b = 1000
    c = 0
    for i in range(a):
        d += [e]
        e += 1
    for i in range(n):
        d.remove(p[E])
        E += 1
    for i in range(n):
        b = min(abs(x-d[c]),b)
        c += 1
    if (x-b) in d:
        print(x-b)
    else:
        print(x+b)

Submission status: Runtime Error

Solution code:
s = [input() for i in range(2)] 
xn = list(map(int, s[0].split()))
x = xn[0]
n = xn[1]
p = list(map(int, s[1].split()))
dif = 100
flag = 0
for i in range(n):
    if dif > abs(p[i] - x):
        dif = abs(p[i] - x)
        flag = i
    if dif == abs(p[i] - x):
        if p[i] < p[flag]:
            flag = i
r = p[flag]
t = p[flag]
ckflagr = 1
ckflagt = 1
if r == x:
    r = r-1
    t = t+1
for l in range(100):
    if ckflagr == 1:
        ckflagr = 0
        for k in range(n):
            if r == p[k]:
                r = r - 1
                ckflag = 1
    
    if ckflagt == 1:
        ckflagt = 0
        for m in range(n):
            if t == p[m]:
                t = t + 1
                ckflag = 1
diffr = x-r
difft = t-x
if diffr > difft:
    print(t)
if diffr <= difft:
    print(r)

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 (sa >= 101):
  print("0")
  exit()
if pp[x-sa-1] >= 10000:
    print(x+sa)
else:
    print(x-sa)

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)
ans1=int(-1000)
ans2=int(1000)
#print(B[3])
#print(kouho2)
for k in range(len(B)):
    if int(B[k])==int(kouho1):
        ans1=int(B[k])
        #sys.exit()
for l in range(len(B)):
    if int(B[l])==int(kouho2):
        ans2=int(B[l])
        #sys.exit()
aa1=X-0
aa2=X-ans1
aa3=ans2-X
aa4=101-X
if min(aa1,aa2,aa3,aa4)==aa1:
    print("0")
if min(aa1,aa2,aa3,aa4)==aa2:
    print(aa2)
if min(aa1,aa2,aa3,aa4)==aa3:
    print(aa3)
if min(aa1,aa2,aa3,aa4)==aa4:
    print("101")

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  numbers=list(range(-100,1000)
  ans=X

  for i in range(len(p)):
    numbers.remove(p[i])

  if numbers.count(X)==1:
    print(ans)
  else:
    for j in range(1000):
      if numbers.count(X-j)==1:
        ans=X-j
        break
      elif numbers.count(X+j)==1:
        ans=X+j
        break
  print(ans)

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])
    if ary[0]!=None:
        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:
import numpy as np 

X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    l = list(map(int, input().split()))
    l = sorted(l)
    number_list = []
    for i in range(l[-1] * X):
        number_list.append(i+1)
    for k in l:
        if k in number_list:
            for num, li in enumerate(number_list):
                if li == k:
                    number_list.pop(num)
    number_list.append(X)
    number_list = sorted(number_list)
    for n,b in enumerate(number_list):
        if b == X:
            if np.abs(number_list[n-1] - X) > np.abs(number_list[n+1] - X):
                print(number_list[n+1])
                
            elif np.abs(number_list[n-1] - X) < np.abs(number_list[n+1] - X):
                print(number_list[n+1])
                
            elif np.abs(number_list[n-1] - X) == np.abs(number_list[n+1] - X):
                if number_list[n-1] > number_list[n+1]:
                    print(number_list[n+1])
                elif number_list[n-1] < number_list[n+1]:
                    print(number_list[n-1])

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
if N > 0:
    l = list(map(int, input().split()))
    A = [0] * N

    for i in range(N):
        A[i] = abs(l[i] - X)

    S = A.count(0)
    if S == 0:
        print(X)
        ok = 1

    if ok != 1:
        for i in range(1, 101):
            S = A.count(i)
            if S == 0:
                print(X - 1)
                break
            if S == 1:
                if l.count(X - i) == 0:
                    print(X - i)
                    break
                else:
                    print(X + i)
                    break
            else:
                pass

else:
    print(X)

Submission status: Runtime Error

Solution code:
s = [input() for i in range(2)] 
xn = list(map(int, s[0].split()))
x = xn[0]
n = xn[1]
p = list(map(int, s[1].split()))
dif = 100
flag = 0
for i in range(n):
    if dif > abs(p[i] - x):
        dif = abs(p[i] - x)
        flag = i
    if dif == abs(p[i] - x):
        if p[i] < p[flag]:
            flag = i
r = p[flag]
t = p[flag]
# print(r)
ckflagr = 1
ckflagt = 1
if r == x:
    r = r-1
    t = t+1
for l in range(100):
    if ckflagr == 1:
        ckflagr = 0
        for k in range(n):
            if r == p[k]:
                r = r - 1
                ckflag = 1
    
    if ckflagt == 1:
        ckflagt = 0
        for m in range(n):
            if t == p[m]:
                t = t + 1
                ckflag = 1
# print(r)
# print(t)
diffr = x-r
difft = t-x
if diffr > difft:
    print(t)
if diffr <= difft:
    print(r)

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

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

if n == 0:
    print(x)
else:
    p_li.sort()
    if x in p_li == False:
        print(x)
        sys.exit()
    else:
        pst = my_index(x, p_li)
        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:
X, N = map(int, input().split())
try:
  P = list(map(int,input().split()))
except:
  print(X)
  exit()
  
list100 = list(range(100))

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

print(list100[index100])

Submission status: Runtime Error

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

mina =101
y = []
minc = []


for i in range(1,101):
    y.append(i)

if n == 0:
    print(x)
else:
    for j in range(n):
        y.remove(p[j])

    z = copy.copy(y)

    for k in range(len(y)):
        if abs(x - y[k]) < mina:
            mina = abs(x - y[k])
            minb = y[k]
            z.remove(minb)

    minc.append(minb)
    mina = 101

    for m in range(len(z)):
        if abs(x - z[m]) < mina:
            mina = abs(x - z[m])
            minb = z[m]

    minc.append(minb)

    print(min(minc))

Submission status: Runtime Error

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

arr = [x]
tmp = input()
num = tmp.split(' ')
num_li = [int(i) for i in num]
arr.extend(num_li)

arr.sort()
arr = list(set(arr))

min = x
max = x

for i in range(100):
    if len(arr) == 1:
        print(x)
        break

    min -= 1
    max += 1
    
    try:
        arr.index(min)
    except:
        print(min)
        break

    try:
        arr.index(max)
    except:
        print(max)
        break

Submission status: Runtime Error

Solution code:
x,y=map(int,input().split())
if y==0:
  print(x)
else:
  lis=list(map(int,input().split()))
  li=sorted(lis)
  l=[]
  for i in range(1,101):
    if i in li:
      continue
    else:
      l.append(i)
  
  p=[]
  for i in l:
    p.append(abs(x-i))
  p=sorted(p)

  if p[0]>x:
    print(0)
  
  elif x-p[0] in l:
    print(x-p[0])
  else:
    print(p[0]+x)

Submission status: Runtime Error

Solution code:
x,n = map(int, input().split())
p = sorted(map(int, input().split()))
if p == []:
    print(x)
else:
    a = p[-1]
    d =[]
    D =[]
    e = 1
    E = 0
    b = 1000
    c = 0
    for i in range(a):
        d += [e]
        e += 1
    for i in range(n):
        d.remove(p[E])
        E += 1
    for i in range(n):
        b = min(abs(x-d[c]),b)
        c += 1
    if (x-b) in d:
        print(x-b)
    else:
        print(x+b)

Submission status: Runtime Error

Solution code:
x,n = [int(x) for x in input().split()]
if n == 0:
    print(x)
                    # n == 0なら何もせず終了
else: 
    nums = [int(x) for x in input().split()]
    nums_abs = []

    for i in range(n):
        nums_abs.append(abs(nums[i]-x))
                    # xとの差を求める
    min_num = min(nums_abs)
    for i in range(n):
        if nums_abs[i] == min_num:
            s_num = nums[i]
                    # 一番近い数字を求める
        
    for i in range(1,max(nums_abs)):
        if s_num-i not in nums:
            ans = s_num-i
            break
        elif s_num+i not in nums:
            ans = s_num+i
            break
        else:
            print("through")
    print(ans)

Submission status: Runtime Error

Solution code:
a = input().split()
b = int(a[0])
c = int(a[1])
d = [int(i) for i in input().split()]
e = sorted(d)


f = int(e[0]-1)
g = int(e[-1]+1)


h = int(g-f)

X = []
for I in range(int(h+1)):
    J = int(f+I)
    if e.count(J) == 0:
        X.append(J)

Y = len(X)
H = []
for S in range(Y):
    Q = X[S]
    if Q>=b:
        g = Q-b
        H.append(g)
    else:
        g = b-Q
        H.append(g)
P = sorted(H)
F = P[0]
O = H.index(F)
print(X[O])

Submission status: Runtime Error

Solution code:
X,N = map(int, input().split())
if N==0:
    print(X)
else:
    p=list(map(int,input().split()))
    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,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)
        z=y
        break
    elif z in a:
        z+=1
    else:
        break
while y<100:
    if y in a:
        b=y-1
    elif not y in a:
        b=y
        break
    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)