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: Wrong Answer

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    X, N = mulinputs()
    ps = set(mulinputs())

    # mins = [ [] for _ in range(100)]
    mins = []
    m = INF
    for p in range(1,101):
        if p in ps:
            continue
        tmp = abs(X-p)
        if tmp < m:
            m = tmp
            mins = []
            mins.append(p)
        elif tmp == m:
            mins.append(p)

    mins.sort()
    # 出力
    if mins:
        print(mins[0])
    else:
        print(X)

Submission status: Wrong Answer

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

p = sorted(list(map(int, input().split())))
P = []

for i in range(102):
    P.append(i)


MOD = 10**9+7
tmp = 0
m = 9999999999999
ans = 0

P[0] = MOD


for i in range(N):
    P[p[i]] = MOD


for i in reversed(range(1,len(P))):

    tmp = abs(P[i]-X)
    m = min(m,tmp)
    if m == tmp:
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
if n == 0:
    ans = x
else:
    p = sorted(p)
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = 0
    for i in range(min_p+1, max_p):
        if i == p[j+1]:
            j += 1
        else:
            if abs(ans-x) > abs(i-x):
                ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
absP=[abs(X-i) for i in P]

def b():
    if(N==0):
        print(X)
        return X
    for n in range(1,N+1):
        a=X-n
        if(a not in P):
            return a
        a=X+n
        if(X+n not in P):
            return a
print(b())

Submission status: Wrong Answer

Solution code:
def iput(): return int(input())
def mput(): return map(int, input().split())
def lput(): return list(map(int, input().split()))

def solve():
    x, n = mput()
    p = lput()
    ans = []
    for i in range(x, x-n-1, -1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    for i in range(x, x+n+1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    print(min(ans))
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

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

p.sort()

minp = 999
minv = x
if n == len(p):
    print()
else:
    for i in range(1, 101):
        if i in p:
            continue
        else:
            if abs(i - x) < minp:
                minp = abs(i - x)
                minv = i
            else:
                break
    print(minv)

Submission status: Wrong Answer

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

diff_max = 100

"""
for value in p_list:
    if abs(x-value) <= diff_max:
        diff_max = abs(x -value)
        check = value

print(diff_max)
print("CHECK", check)
"""
check = x
tansaku = 1
count = 0
while True:
    count += 1
    if not(check in p_list):
        print(check)
        exit()
    
    check -= tansaku
    tansaku = -tansaku
    if tansaku <0:
        tansaku -= 1
    else:
        tansaku += 1
    if count >= 60:
        exit()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
x, n = map(int, input().split())
p = list(map(int, input().split()))
if (n == 0):
    print(x)
    sys.exit()
diff = 1000
ans = 0
p.sort()
diff=1000
for i in range(1,101):
    if (i in p):
       continue
    else:
        if (abs(x - i) < diff):
            diff = abs(x - i)
            ans = i
print(ans)

Submission status: Wrong Answer

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

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

min_diff_val = X
min_val = 0
for y in range(100):
    if not (y in p):
        if min_diff_val > abs(y - X):
            min_val = y
            min_diff_val = abs(y - X)
print(min_val)

Submission status: Wrong Answer

Solution code:
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
b=sorted(b)
base = 0
for i in range(-100, 101):
  if abs(a[0]-base)>abs(a[0]-i) and i not in b:
    base = i
print(base)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n==0:
    print(x)
else:
    p = list(map(int,input().split()))
    ans,ans_x = 100,100
    for i in range(x,101):
        if i not in p:
            ans = i
            ans_x = abs(x-i)
            break
    for i in range(x,-101,-1):
        if i not in p:
            if ans >= i and ans_x>=abs(x-i):
                ans = i
                break
    print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    P = list(map(int, input().split()))
    for i in range(1,100):
        if (X-i) not in P:
            print(X-i)
            break
        elif (X+i) not in P:
            print(X+i)
            break
    else:
        print(X)

Submission status: Wrong Answer

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

if x not in p:
    print(x)
else:
    for num in p:
        ll.remove(num)
    l2 = []
    ans = 9999
    for i in ll:
        if abs(i-x) < abs(x-ans):
            ans = i
        if abs(i-x) == abs(ans-x):
            ans = min(i, ans)

    print(ans)

Submission status: Wrong Answer

Solution code:
import math
X,N=map(int,input().split())
p=list(map(int,input().split()))
a=[]
if N==0:
  print(X)
else:
  for i in range(-100,101):
    for j in range(N):
      if i==p[j]:
      	i=1000
    a.append(i)
  tmp=10000
  ans=0
  for i in range(200):
    if abs(a[i]-X)<tmp:
      tmp=abs(a[i]-X)
      ans=a[i]
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

if N == 0:
    print(X)

for i in range(N):
    if p.count(X - i) == 0:
        print(X - i)
        sys.exit()
    elif p.count(X + i) == 0:
        print(X + i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
d = [0]*101

for j in p: d[j] = 1

else:
    i = 0
    while True:
        if x-i>=0:
            if d[x-i] == 0:
                print(x-i)
                break
        if x+i<=100:
            if d[x+i] == 0:
                print(x+i)
                break
        i += 1

Submission status: Wrong Answer

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

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

p = set(p)
now = 0
diff = 100
indx = 102

while True:
    if now not in p:
        now_diff = abs(now - x)
        if diff > now_diff:
            diff = now_diff
            indx = now
        else:
            break
    now += 1

print(indx)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
lp=list(map(int,input().split()))
if n==0:
    print(x)
a=x
b=x
while True:
    if a not in lp and b not in lp:
        print(a)
        break
    elif a not in lp:
        print(a)
        break
    elif b not in lp:
        print(b)
        break
    a-=1
    b+=1

Submission status: Wrong Answer

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

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

ans = 100000
for i in range(101):
    if not i in p:
        if abs(i - x) < abs(ans - x):
            ans = i
            
print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
  print(100)
else:
  a=list(map(int,input().split()))
  l=[x+i for i in range(101)]
  s=[x-i for i in range(101)]
  m=min(len(l),min(s))
  mada=1
  k=0
  while mada:
    if s[k] not in a:
      ans=s[k]
      mada=0
      break
    elif l[k] not in a:
      ans=l[k]
      mada=0
      break
    else:
      k+=1
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
X, N = map(int, input().split())
Mylist = input().split()
Mylist = [int(s) for s in Mylist]

for i in range(X):
    if not (X - i) in Mylist:
        print(X-i)
        sys.exit()
    elif not (X + i) in Mylist:
        print(X+i) 
        sys.exit()

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
msf = 1000
for i in range(100,-1,-1):
    if i not in lis:
        diff = abs(i-x)
        if(min(diff,msf)==diff):
            msf = diff
            ans = i
print(ans)

Submission status: Wrong Answer

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

    if P.count(X)== 0:
        print(X)
    else:
        hi = 0
        lo = 0
        i = 1
        j = 1
        while lo == 0:
            a = X-i
            if P.count(a)==0:
                lo += 1
            else:
                i += 1
            if i >= X:
                i = 114514
                break
                
            
        while hi == 0:
            a =X+j 
            if P.count(a)==0:
                hi += 1
            else:
                j += 1 
            if (X + j) >= 100:
                j = 114514
                break
                
            
        if i > j:
            print(X+j)
        elif i<j:
            print(X-i)
        else:
            print(X-i)

Submission status: Wrong Answer

Solution code:
stand = []
emp = [100]
ans = []

line = input().split()
x = int(line[0])
if int(line[1]) == 0:
  ans = x
  
elif int(line[1]) != 0:
  line2 = input().split()
  for i in range(1,101):
    stand.append(int(i))
  for i in line2:
    if int(i) in stand:
      stand.remove(int(i))
  for i in stand:
    candi = abs(x - i)
    if candi < emp[0]:
      emp[0] = candi
      ans = i
      
print(ans)

Submission status: Wrong Answer

Solution code:
import math
x,n  = map(int,input().split())
if n==0:
    print(x)
    exit()
p = [int(i) for i in input().split()]


max_ = max(p)



a= [i+1 for i in range(max_)]
aa = [-max_+i+1 for i in range(max_)]
m=0
for i in p:
    a[i-1]=100000
min_=100000

for j in aa:
    b=abs(j-x)
    if min_ > b:
        min_=b
        m = j
for i in a:
    b = abs(i-x)
    if min_ > b:

        min_=b
        m = i
print(m)

Submission status: Wrong Answer

Solution code:
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
flag = [False]*101
for i in p:
    flag[i-1] = True
for j in range(0, n+1):
    l = max(0, x-1-j)
    r = min(101, x-1+j)
    if not flag[l]:
        print(l+1)
        sys.exit()
    if not flag[r]:
        print(r+1)
        sys.exit()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P =  set(map(int, input().split()))
Nums = set(range(1, 101))
Nums = Nums - P
sorted(Nums)


minNum = 99999;
minIndex = 0;
for n in Nums:
    if abs(X - n)< minNum:
        minNum = abs(X - n)
        minIndex = n

print(minIndex)

Submission status: Wrong Answer

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

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

p = list(map(int,input().split()))
q = [i for i in range(-100,101)]
li = list(set(p) ^ set(q))
li.sort()
minabs = 10**9
ans = 0
for i in li:
    if minabs>abs(X-i):
        minabs = abs(X-i)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
    quit()
p = set(map(int, input().split()))
not_p = sorted(set(range(0, 101)) - p)
ans = 0
minval = 101
for i in not_p:
    if minval > abs(X - i):
        minval = abs(X - i)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=list(map(lambda i:abs(x-i),p))
c=collections.Counter(p)
p.sort()

for i in range(len(p)):
  if p[i]!=(i+1)//2:
    if p[i-1]==p[i-2]:
      if x-p[i-1]-1 in p:
        print(x-p[i-1]+1)
      else:
        print(x-p[i-1]-1)
      sys.exit()
    elif i==1:
      if x-1 in p:
        print(x+1)
      else:
        print(x-1)
      sys.exit()
    else:
      if x-p[i-1] in p:
        print(x+p[i-1])
      else:
        print(x-p[i-1])
      sys.exit()
print(x)

Submission status: Wrong Answer

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

ans = x

for i in range(n):
    tmp1 = x - i
    tmp2 = x + i
    if not tmp1 in p:
        ans = tmp1
        break
    if not tmp2 in p:
        ans = tmp2
        break

print(ans)

Submission status: Wrong Answer

Solution code:

x,n = map(int, input().split())
if n != 0:
    num_list = list(map(int, input().split()))
    max_num = max(num_list)
else:
    num_list = []
    max_num = 1
flag = 0
for i in range(0,max_num):
    a = x - i
    b = x + i
    # print(a, b)
    if not(a in num_list):
        print(a)
        flag = 1
        break
    if not(b in num_list):
        print(b)
        flag = 1
        break
    if flag == 1:
        break

Submission status: Wrong Answer

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

# 0~100
data_list = [1 for i in range(101)]

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

# 候補外を0にする
for i in range(len(in_value)):
	data_list[in_value[i]] = 0

min_abs = 10**4
ans_i = 0
for i in range(101):
	# 候補の値
	if(data_list[i] == 1):
		# 絶対値を求める
		t_abs = abs(X - i)
		# 絶対値が小さい場合は更新
		if(min_abs > t_abs):
			min_abs = t_abs
			ans_i = i

print(ans_i)

Submission status: Wrong Answer

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

if len(p)==0:
    print(X)
    exit()

for i in range(N):
    if p.count(X-i)==0:
        if X-i != 0:
            print(X-i)
            exit()
    if p.count(X+i)==0:
        print(X+i)
        exit()

Submission status: Wrong Answer

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

min_p = 200
for i in range(-100,101):
    if not (i in p):
        min_p = min(min_p, abs(i-x))
if x-min_p > 0:
    if not (x-min_p in p):
        print(x-min_p)
    else:
        print(x+min_p)
else:
    if not (x+min_p in p):
        print(x+min_p)
    else:
        print(x-min_p)

Submission status: Wrong Answer

Solution code:
X, N = map(int,input().split())
if N > 0:
  P = set([int(_) for _ in input().split()])
else:
  P = []
l_cand = -1
r_cand = 101

for i in range(1,X+1):
  if i not in P:
    l_cand = i
    
for i in range(100,X,-1):
  if i not in P:
    r_cand = i

diff_l = abs(l_cand - X)
diff_r = abs(r_cand - X)

if diff_l <= diff_r:
  print(l_cand)
else:
  print(r_cand)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
#p = [0]*N
p = list(map(int,input().split()))
ans = 0

for i in range(101):
    if i in p:
        continue
    else:
        if abs(X-ans)>abs(X-i):
            ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = [int(i) for i in input().split()]
ps = [int(i) for i in input().split()]
ans = 0
d = 100
for i in range(1, 101):
    if i not in ps:
        tmp = abs(i-x)
        if d > tmp:
            d = tmp
            ans = i
        elif d == tmp:
            ans = min(i, ans)
        else:
            pass

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

X, N = list(map(int, input().split(' ')))
ps = input()
if len(ps)!=0:
    ps = list(map(int, ps.split(' ')))

ps_sort = list(sorted(ps))
not_in_ps = np.array([[abs(i-X), i] for i in range(-1, 101) if i not in ps_sort])
print(not_in_ps[np.argmin(not_in_ps[:,0], 0), 1])

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n ==0:
    print(x)
    exit()
p = set(list(map(int,input().split())))
s = {i for i in range(1,101)}
kouho = s.difference(p)
sa = float('inf')
ans = float('inf')
for i in kouho:
    if sa > (abs(i-x)):
        sa = abs(i-x)
        ans = i

print(ans)

Submission status: Wrong Answer

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

i=[0]*100
for n in range(100):
    i[n]=n+1

ans=list(set(i) ^ set(p))
dif=100
count=0
for j in range(100-N):
    dif_now=abs(X-ans[j])
    if dif>dif_now:
        dif=dif_now
        count=ans[j]
print(count)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
List=[int(i) for i in input().split()]
A=X
B=X
if X in List == True:    
    p=True
    q=True
    while p==True:
        A=A-1
        p= A in List
    while q==True:
        B=B+1
        q= B in List
    if X-A <= B-X:
        print (A)
    else:
        print (B)
else:
    print(X)

Submission status: Wrong Answer

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

f = 0
d = 0
ans1 = x
while f == 0:
    d += 1
    ans1 -= 1
    if ans1 in P:
        pass
    else:
        f = 1

f = 0
d2 = 0
ans2 = x
while f == 0:
    d2 += 1
    ans2 += 1
    if  ans2 in P:
        pass
    else:
        f = 1
    
if d <= d2:
    print(ans1)
else:
    print(ans2)

Submission status: Wrong Answer

Solution code:
import sys
X,N=map(int, sys.stdin.readline().split())
P=map(int, sys.stdin.readline().split())

L=[ 0 for _ in range(101) ]

for p in P:
    L[p]=1

kyori=float("inf")
ans=None
for i,x in enumerate(L):
    if x==0:
        new_kyori=abs(i-X)
        if new_kyori<kyori:
            ans=i
            kyori=new_kyori
print ans

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
  quit()
else:
  P = list(map(int,input().split()))
P.sort()
ans = 0
for i in range(101):
  if i not in P and abs(i-x) < abs(ans-x):
    ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N:
  P = list(map(int, input().split()))
  distance = 10000
  ans = 0
  for cadi in range(100, 0, -1):
    if not cadi in P :
      if distance >= ( cadi - X ) * ( cadi - X ):
        distance = ( cadi - X ) * ( cadi - X )
        ans = cadi
  print(ans)
else:
  print(X)

Submission status: Wrong Answer

Solution code:
X, N = (map(int, input().split()))
p = list(sorted(map(int, input().split())))
lmin = 10000
if(X not in p):
    print(X)
    exit()
for i in range(1, N):
    if(X+i in p and X-i in p):
        continue
    if((X-i not in p) and (X+i in p)):
        print(X-i)
        exit()
    elif((X-i in p) and (X+i not in p)):
        print(X+i)
        exit()
    elif((X-i not in p) and (X+i not in p)):
        print(X-i)
        exit()

Submission status: Wrong Answer

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

int_set = set(list(range(1,101)))

for x in input().split():
    int_set.remove(int(x))

for i in range(51):
    if X - i in int_set:
        print(X - i)
        break
    elif X + i in int_set:
        print(X + i)
        break

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

x, n, *p = map(int, read().split())

min_d = 1000000

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

for i in range(100):
    if i in p:
        continue
    d = abs(x - i)
    if d < min_d:
        min_d = d
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
import sys
if n==0:
    print(x)
    sys.exit()
    
p_list=list(map(int,input().split()))
r=list(range(100))
a=list(set(r)-set(p_list))

ans=100000
kkk=100000
for i in a:
    tem=abs(i-x)
    if ans>tem:
        ans=tem
        kkk=i
    
print(kkk)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
 
if n != 0:
    p = list(map(int,input().split()))
 
s = []
 
for i in range(-100,101):
    s.append(i)
    
if n != 0:
    for i in p:
        s.remove(i)
 
if n == 0:
    print(x)
else:
    if x in s:
        print(x)
    elif x<s[0]:
        print(s[0])
    elif x>s[-1]:
        print(s[-1])
    else:
        for i in range(len(s)-1):
            if s[i]<=x<=s[i+1]:
                if abs(x-s[i])<abs(x-s[i+1]):
                    print(s[i])
                elif abs(x-s[i])==abs(x-s[i+1]):
                    print(s[i])
                else:
                    print(s[i+1])
                break

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

X, N = read_ints()
if N == 1:
    print(X)
    exit()
P = read_ints()
candi = []
for i in range(0, 102):
    if i in P:
        continue
    candi.append(i)
candi.sort(key=lambda x: abs(X - x))
print(candi[0])

Submission status: Wrong Answer

Solution code:

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

d=100
pa = 0
px =range(1,101,1)
py = list(set(px) - set(p))

for i in py:
    if d> abs(i-x):
        pa = i
        d = abs(i-x)
    elif d == abs(i-x):
        if i < pa:
            pa =i

print(pa)

Submission status: Wrong Answer

Solution code:
import numpy as np
X,N = map(int, input().split())
if N != 0:
  p = list(map(int, input().split()))
  min_val = 1
  max_val = 100
  not_p = [i for i in range(min_val,max_val+1,1)]
  
  for i in range(N):
    not_p.remove(p[i])
  #print(not_p)

  min_val = 101
  out_num = 101
  for i in range(len(not_p)):
    if abs(X-not_p[i]) < min_val:
      min_val = abs(X-not_p[i])
      out_num = not_p[i]
else:
  out_num = 0
print(out_num)

Submission status: Wrong Answer

Solution code:
def main():
    x,n = map(int,input().split())
    if n>0:
        p = list(map(int,input().split()))
    else:
        p = []
    d = [i for i in range(1,101)]
    for i in range(len(d)):
        if d[i] in p:
            d[i] = 0
    d = sorted(d)
    m = 10000
    ans = 0
    for i in range(len(d)):
        if d[i]==0:
            continue
        if m>abs(d[i]-x):
            m = abs(d[i]-x)
            ans = d[i]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

absn = 100
ans = 1000

for i in numlist:
    if absn >= abs(X-i) and i not in p:
        if absn == abs(X-i):
            break
        else:
            ans = i
            absn = abs(X-i)

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


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

diff = INF
res = None

for i in range(-100, 100 + 1):
    if i in P:
        continue
    if abs(x - i) < diff:
        res = i
        diff = abs(x - i)

print(res)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
if(b!=0):
    l=list(map(int,input().split()))
    st=1
else:
    l=[0]
    st=0
for i in range(st,101):
    if((a-i) not in l)and((a-i)>0):
        print(a-i)
        break
    elif((a+i) not in l):
        print(a+i)
        break

Submission status: Wrong Answer

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

for i in range(len(p)):
    ans1 -= 1
    ans2 += 1
    if ans1 not in p:
        print(ans1)
        exit()
    if ans2 not in p:
        print(ans2)
        exit()