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:
import sys

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

ans1 = int()
ans2 = int()

p.sort()

if x not in p:
    print(x)
    sys.exit()

for i in range(n):
    if x == p[i]:
        for j in range(x + 1, 100, 1):
            if j not in p:
                ans1 = j
                break
        for k in range(x - 1, 1, -1):
            if k not in p:
                ans2 = k
                break

if ans1 - x < x - ans2:
    print(ans1)
else:
    print(ans2)

Submission status: Wrong Answer

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

    mylist = list(range(-98, 101))

    list_2 = list(filter(lambda x: x not in list_1, mylist))
    
    list_3 = list(map(lambda x: x - X, list_2))

    import numpy as np

    abslist = np.abs(list_3)

    min_num = min(abslist)

    answer_lisbef = [X - min_num, X + min_num]
    
    answer_lisaf = list(filter(lambda x: x not in list_1, answer_lisbef))
    
    answer = min(answer_lisaf)
print(answer)

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
nums=[int(x) for x in input().split()]
#print(nums)
if n == 0:
	print(x)
	exit()
if x == 1:
	print(0)
	exit()
min=x
gap=x
#print('Here')
for i in range(1,101):
	if i in nums:
		continue
	else:
		if abs(x-i) < gap:
			#print("min: ",min)
			#print(x-i)
			gap=x-i
			min = i
print(min)

Submission status: Wrong Answer

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

S=[i for i in range(1,101)]

for j in range(N):
    S.remove(A[j])
    
n=1000  
x=0
for k in S:
    if abs(k - X) < n:
        n=abs(k - X)
        x=k
    elif n == abs(k - X):
        x=min(x,k)
print(x)

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
if n==0:
  print(x)
else:
  p = list(map(int, input().split()))
  p.append(0)
  while True:
    p[n]+=1
    if p[n]%2==1:
      s = x-((p[n]+1)/2)
      #print(s,"こ")
    else:
      s = x+(p[n]/2)
      #print(s,"ここ")
    if s not in p:
      print(int(s))
      break

Submission status: Wrong Answer

Solution code:
def resolve():
	X, N = map(int, input().split())
	if N == 0:
		print(X)
	else:
		A = list(map(int, input().split()))
		ymin = min(min(A), X)-1
		ymax = max(max(A), X)
		Y = {}
		for y in range(ymin, ymax):
			if y in A:
				None
			else:
				key = abs(X-y)
				if key in Y:
					Y[key] = Y[key] + [y]
				else:
					Y[key] = [y]
		key = min(Y.keys())
		print(min(Y[key]))
resolve()

Submission status: Wrong Answer

Solution code:
import numpy as np
X,N = map(int, input().split())
p = list(map(int, input().split()))
p = sorted(p)
lista = list(range(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: Wrong Answer

Solution code:
import numpy as np
X, N = list(map(int, input().split()))
try:
	p = np.array(list(map(int, input().split())))
except EOFError:
    print(X)
    exit()
I = np.arange(1, 101)
indices = np.argsort(np.abs(I - X), kind='mergesort')
for idx in indices:
    if I[idx] not in p:
        print(I[idx])
        break

Submission status: Wrong Answer

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

p = set(map(int,input().split()))
not_p = list(set(range(0,100)) - p)
print(not_p)

minV = 101
ans = 0
for i in not_p:
    if abs(X - i) < minV:
        minV = abs(X - i) 
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split(' '))
if n > 0:
    p = list(map(int, input().split(' ')))
    r = x + 1
    l = x - 1
  
    ansr = 0
    ansl = 0
    for i in range(102):
        if r not in p:
            break
        r += 1
    ansr = r
    for i in range(102):
        if l not in p:
            break
        l -= 1
    ansl = l
    vr = ansr - x
    vl = x - ansl
    if vr == vl:
        ans = ansl if ansl < ansr else ansr
    else:
        ans = ansl if vl < vr else ansr
else:
    ans = x
print(ans)

Submission status: Wrong Answer

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[1] == 100:
  if n[0] > 50:
    print('101')
  else:
    print('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: Wrong Answer

Solution code:
import math

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

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

p.sort()

minimum = p[0]
maximum = p[len(p) - 1]
# print(minimum, maximum)

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

diff_min = abs(X - minimum - 1)
diff_max = abs(X - maximum + 1)
if diff_min == diff_max:
    answer = min(minimum - 1, maximum + 1)
else:
    answer = minimum - 1 if diff_min < diff_max else maximum + 1

for candidate in range(minimum, maximum):
    if candidate in p: continue

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

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input(). split())
l = [0]*n
m = [0]*100
ans = 0
p = list()
if n > 0:
  p = list(map(int, input(). split()))
else:
  print(x)
  sys.exit()
for i in range(n):
  l[i] = abs(x-p[i])
  m[l[i]] += 1
if m[0] == 0:
  print(x)
for j in range(1, 100):
  if m[j] != 2:
    a = x-j
    A = x+j
    b = p.count(a)
    B = p.count(b)
    if b == 0:
      ans = a
      if a > x:
        ans = 0
    else:
      ans = A
      if a > x:
        ans = 0
    break
print(ans)

Submission status: Wrong Answer

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

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

Solution code:
X,N = map(int, input().split())
if N==0:
    print(X)
    exit()
else:
    p=list(map(int,input().split()))
    A=[i for i in range(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: Wrong Answer

Solution code:
x, n = map(int, input().split())
if(n == 0):
    print(x)
elif(n == 100):
    ff = 101-x
    gg = x
    if(ff < gg):
        print(101)
    else:
        print(0)
else:
    p = list(map(int, input().split()))
    if(not(x in p)):
        print(x)
    else:
        m = [i for i in range(1, x+1)]
        for i in range(len(m)):
            if(m[i] in p):
                m[i] = 10000
            else:
                m[i] = abs(x-m[i])
        print(m.index(min(m))+1)

Submission status: Wrong Answer

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]
    elif (n == 0):
        ANS = L[1]
    elif (n == l):
        ANS = L[l - 1]

print(ANS)

Submission status: Wrong Answer

Solution code:
x,n= map(int,input().split())
u = 100
num_str=input().split()
s=list(map(int, num_str))
m = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100}
for k in s:
    m.remove(k)
print(x)
for l in m:
    a = l - x
    if abs(u) > abs(a):
        u = a
print(u+x)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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

if n > 0:
    p = sorted(list(map(int, input().split())))

    l = bisect_left(p, x)
    #右
    for i in range(1,1000):
        #print(p[l]+i)
        if p[l]+i in p:
            pass
        else:
            a = p[l]+i
            break

    for i in range(1, -1000, -1):
        if p[l]-i in p:
            pass
        else:
            b = p[l]-i
            break
    print(min(a,b))
else:
    print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = map(int, input().split())
if N > 0:
  l1=list(map(int,input().split()))
else:
  l1=[]
ans = 100
l2 = np.array([i for i in range(1,11)])

l3 = set(l1) ^ set(l2)  

for item in l3:
#  print("item",item)
#  print("X-item",(X - item)**2)
#  print("X-ans",(X - ans)**2)  
  if ((X - item) ** 2) == ((X - ans) ** 2):
    if item < ans:
      ans = item
  elif  ((X - item) ** 2) < ((X - ans) ** 2):
    ans = item
print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
if n==0:
    print(x)
    exit()
res = []
for num in range(-100,101):
    if x!=num and num not in p:
        res.append(abs(x-num))
if x-min(res) not in p:
    print(x-min(res))
else:
    print(x+min(res))

Submission status: Wrong Answer

Solution code:
import bisect
import numpy as np

X, N = map(int, input().split())
p_array = np.array(list(map(int, input().split())))

if N ==0:
    print(X)

else:
    p_array = sorted(p_array)

    left = bisect.bisect_left(p_array, X) - 1
    right = left + 2

    i = left
    left_answer = X - 1
    if i <= 0:
        pass
    else:
        while True:
            if i <= 0:
                left_answer -= 1
                break

            if p_array[i] == left_answer:
                i -= 1
                left_answer -= 1
            else:
                break
         
    j = right
    right_answer = X + 1
    if j >= N:
        pass
    else: 
        while True:
            if j >= N:
                right_answer += 1
                break

            if p_array[j] == right_answer:
                j += 1
                right_answer += 1
            else:
                break


    if X - left_answer <= right_answer - X:
        print(left_answer)
    else:
        print(right_answer)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n ==0:
    print(x)
else:
    p = list(map(int, input().split()))
    q = list(range(101))
    a = 1000
    t = 0
    for i in q:
        if p.count(i) == 0:
            b = abs(x-i)
            if b<a:
                a = b
                t = i
    print(t)

Submission status: Wrong Answer

Solution code:
import os
import sys
from io import BytesIO, IOBase
import math
def inputIntArray():
    return list(map(int, input().rstrip().split()))


def inputArray():
    return input().rstrip().split()


def inputVars():
    return map(int, input().rstrip().split())


def inputNum():
    return int(input())


def main():
    x, n = inputVars()
    if n == 0:
        print(x)
        return
    arr = inputIntArray()
    minRes = x
    if x not in arr:
        print(x)
        return
    minRes = float('inf')
    dup = float('inf')
    arr.sort()
    if arr[0] >= x:
        print(x-1)
    else:
        for num in range(-x+1, 2*x):
            if num not in arr:
                minRes = num if abs(num-x) < abs(x-minRes) else minRes
    if minRes == dup:
        minRes = arr[0]-1 if abs(arr[0]-1-x) < abs(arr[-1]+1-x) else arr[-1]+1
    print(minRes)


#.........................................FAST INPUT OUTPUT.......................................
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#....................................END OF FAST I/O............................................

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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)

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

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)
        index_left=None
        index_right=None
        if index!=0:
            index_left=index-1
        if index!=n:
            index_right=index+1
        value_left=x-1
        value_right=x+1
        
        for i in range(n):
            if index_left is not None:
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                if index_left!=0:
                    index_left=index_left-1
            elif index_right is not None:
                if num_list[index_right]!=value_right:
                    ans=value_right
                    break
                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=101
    if x<=50:
        ans=0

print(ans)

Submission status: Wrong Answer

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

p = set(map(int,input().split()))
not_p = list(set(range(0,100)) - p)
print(not_p)

minV = 101
ans = 0
for i in not_p:
    if abs(X - i) < minV:
        minV = abs(X - i) 
        ans = i
print(ans)

Submission status: Wrong Answer

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

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

s=[]
ans=0
for i in range(201):
    if x+i in p:
        ans+=1
    else:
        s.append(x+i)

t=[]
for j in range(201):
    if x-j in p:
        ans+=1
    else:
        t.append(x-j)

cnt=min(abs(min(s)-x),abs(max(t)-x))
if abs(min(s)-x)==abs(max(t)-x):
    print(x-cnt)
else:
    print(cnt+x)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N == 0 :
    print(X)
else :
    P = list(map(int,input().split()))
    a = list(range(-1,1000))
    ab = 100
    an = []
    for i in range(N):
        a.remove(P[i])
    for j in range(100 - N):
        ab = min(ab,abs(X - a[j]))
    if X - ab in a and X + ab in a:
        print(min(X - ab,X + ab))
    elif X - ab in a:
        print(X - ab)
    elif X + ab in a:
        print(X + ab)

Submission status: Wrong Answer

Solution code:
import sys

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

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

for i in range(len(list_p)):
  if(list_p[i] == -1):
    continue
  else:
    if(abs(list_p[i] - x) < t):
      t = abs(list_p[i] - x)
      num = list_p[i]

print(num)

Submission status: Wrong Answer

Solution code:
import sys
def main():
    x_num, n = map(int, input().split())
    
    p_nums = list(map(int, input().split()))
    
    if n == 0:
        print(x_num)
        sys.exit()
    
    i = 1
    while(True):
        up_num = x_num + i
        down_num = x_num - i
        
        up_sub = abs(x_num - up_num)
        down_sub = abs(x_num - down_num)
        
        if up_num in p_nums:
            if down_num in p_nums:
                i+= 1
                continue
            else:
                print(down_num)
                sys.exit()
        else:
            if down_num in p_nums:
                print(up_num)
                sys.exit()
            elif up_sub == down_sub:
                print(min(up_num, down_num)) 
                sys.exit()
            else:
                i += 1
                continue
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x, n = map(int,input().split())
if n != 0:
  p = list(map(int,input().split()))
p_change = []
m = 0
if n == 0:
  print(x)
else:
    for i in p:
        p_change.append(abs(i-x))

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if(n == 0):
    print(x)
elif(n == 100):
    ff = 101-x
    gg = x
    if(ff < gg):
        print(101)
    else:
        print(0)
else:
    p = list(map(int, input().split()))
    if(not(x in p)):
        print(x)
    else:
        m = [i for i in range(1, 101)]
        for i in range(len(m)):
            if(m[i] in p):
                m[i] = 10000
            else:
                m[i] = abs(x-m[i])
        print(m.index(min(m))+1)

Submission status: Wrong Answer

Solution code:
import math
X,N=map(int,input().split())
p = list(map(int,input().split()))
abs_list=[0]*N
for i,a in enumerate(p):
    abs_list[i]=a-X
abs_new=sorted(abs_list, key = abs)
if N==0:
    flag=True
    print(X)
    exit()
flag1=False
flag2=False
flag=False
for i,a in enumerate(abs_new):
    if i%2==1:
        flag1=False
        flag2=False
    if i==0 and a!=0:
        print(X)
        flag=True
        break
    elif (math.floor((i-1)/2)+1)==a:#+がある
        flag1=True
    elif (math.floor((i-1)/2)+1)==(-a):#-がある
        flag2=True
    if i%2==0 and i!=0:
        if flag2==False:
            print(X-(math.floor((i-1)/2)+1))
            flag=True
            break
        elif flag1==False:
            print(X+math.floor((i-1)/2)+1)
            flag=True
            break
if flag==False:
    if abs_new[-1]<0:
        if flag1==True:
            print(X+(abs_new[-1]-1))
        else:
            print(X-abs_new[-1])
    else:
        if flag2==True:
            print(X-(abs_new[-1]+1))
        else:
            print(X-abs_new[-1])

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
l=list(map(int,input().split()))
def y(x,l):
    k=1
    if x-k not in l:
        return (x-k)

    elif x-k not in l:
        return (x+k)
    else:
        k+=1
print(y(x,l))

Submission status: Wrong Answer

Solution code:
x, y = map(int, input("").split())
a = list(map(int, input("").split()))
s= []
if x not in a:
    print(x)
elif x+1 not in a :
    print(x+1)
elif x -1 not in a:
    print(x-1)
else :
    for i in a :
        s.append(i +1)
    print(min(s))

Submission status: Wrong Answer

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

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

p_int_set = set(p_int_list)

if X not in p_int_set:
    print(X)
    exit()

for i in range(1, N):
    if X - i not in p_int_set:
        print(X - i)
        exit()
    elif X + i not in p_int_set:
        print(X + i)
        exit()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
try:
    in_li = set(map(int, input().split()))
    num_li = list({i for i in range(0,101)} - in_li)
except:
    in_li = set()
    num_li = []

num_li.sort()
res = 0

if n == 0:
    print(x)
elif x not in in_li:
    print(x)
else:
    for i in num_li:
        if abs(x-i) < abs(x-res):
            res = i
    print(res)

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(x):
    a = x+i
    b = x-i
    if p.count(b)==0:
        print(b)
        exit()
    elif p.count(a)==0:
        print(a)
        exit()

Submission status: Wrong Answer

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

def main():
    if n == 0:
        print(x)
        return

    ans_l = list(range(-100, 101))

    diff_l = list(set(p) ^ set(ans_l))
    diff_l.sort()

    cnt = 100
    ans = 100
    for i in range(0, len(diff_l)):
        check = abs(diff_l[i]-x)
        if check < cnt:
            cnt = check
            ans = diff_l[i]
    print(ans)
    return

main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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

if n > 0:
    p = sorted(list(map(int, input().split())))

    l = bisect_left(p, x)
    print(l,p[l])
    #右
    for i in range(1,1000):
        #print(p[l]+i)
        if p[l]+i in p:
            pass
        else:
            a = p[l]+i
            break

    for i in range(1, -1000, -1):
        if p[l]-i in p:
            pass
        else:
            b = p[l]-i
            break
    print(min(a,b))
else:
    print(x)

Submission status: Wrong Answer

Solution code:
import sys

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

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

for i in range(len(list_p)):
  if(list_p[i] == -1):
    continue
  else:
    if(abs(list_p[i] - x) < t):
      t = abs(list_p[i] - x)
      num = list_p[i]

print(num)

Submission status: Wrong Answer

Solution code:
x, n = [int(i) for i in input().split()]
if n > 0:
  p = [int(i) for i in input().split()]
  x1 = x
  while True:
    if x1 not in p:
      a = x1
      break
    else:
      x1 -= 1
  x1 = x
  while True:
    if x1 not in p:
      b = x1
      break
    else:
      x1 += 1
  if x-b < x-a:
    print(b)
  elif x-a < x-b:
    print(a)
  else:
    print(a) if a<b else print(b)

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = map(int, input().split())
if N > 0:
  l1=list(map(int,input().split()))
else:
  l1=[]
ans = X
l2 = np.array([i for i in range(1,11)])

l3 = set(l1) ^ set(l2)  

for item in l3:
#  print("item",item)
#  print("X-item",(X - item)**2)
#  print("X-ans",(X - ans)**2)  
  if ((X - item) ** 2) == ((X - ans) ** 2):
    if item < ans:
      ans = item
  elif  ((X - item) ** 2) < ((X - ans) ** 2):
    ans = item
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
X,N = map(int,input().split())
if N==0:
    print(X)
    exit()
p=list(map(int,input().split()))
ans=[]
num=X
first_or_second=0

for x in range(101):
    if x%2==0:
        plmi=1
    else:
        plmi=-1
    flag=0
    for i in range(N):
        if num==p[i]:
            flag=1
    if flag==1:
        num=num+x*plmi
        # print(num)
    else:
        if first_or_second==0:
            ans.append(num)
            first_or_second=1
        else:
            ans.append(num)
            print(min(ans))
            exit()
        num=num+x*plmi

Submission status: Wrong Answer

Solution code:
import bisect

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

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

p.sort()

if x not in p:
    i = bisect.bisect_left(p, x)
    p = p[:i] + [x] + p[i:]
    
#print(p)
for i in range(n):
    if p[i] == x:
        index = i
        break

right = x + 1
for i in p[index + 1:]:
    if i != right:
        break
    right += 1

left = x - 1
for i in reversed(p[:index]):
    if i != left:
        break
    left -= 1

if x - left <= right - x:
    print(left)
else:
    print(right)

Submission status: Wrong Answer

Solution code:
s = {i+1 for i in range(-101,100)}
#print(s)
x, n =map(int,input().split())

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

for i in range(n):
  s.discard(il[i])
s = list(s)

absmin = 100
ans = 0

for i in range(len(s)):
  j = abs(x-int(s[i]))
  if j < absmin:
    ans = s[i]
    absmin = j

print(ans)

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.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-1:
            if ans != P[cri+i]:
                print(ans)
                exit()
print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p_list=list(map(int,input().split()))
f_list=list(range(101))
for i in p_list:
    f_list.remove(i)
ans=f_list[0]
for i in f_list:
    if abs(X-ans)>abs(X-i):
        ans=i
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()))

    num=[1]*102
    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<103:
            if num[x+count]==1:
                print(x+count)
                break    
        count+=1

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N != 0:
  P = list(map(int, input().split()))
else:
  print(X)
  exit()
list = []
list2 = []

for i in range(max(P)+50):
  if i not in P and i != X:
    res = abs(X - i)
    list.append(res)
    list2.append(i)
    
maxres = list.index(min(list))
print(list2[maxres])

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N == 0 :
    print(X)
else :
    P = list(map(int,input().split()))
    a = list(range(1000))
    ab = 100
    an = []
    for i in range(N):
        a.remove(P[i])
    for j in range(100 - N):
        ab = min(ab,abs(X - a[j]))
    if X - ab in a and X + ab in a:
        print(min(X - ab,X + ab))
    elif X - ab in a:
        print(X - ab)
    elif X + ab in a:
        print(X + ab)

Submission status: Wrong Answer

Solution code:
import sys

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

a = []
b = []

for i in range(0, 101):
    if i not in p:
        a.append((x - i)**2)
        b.append(i)
ans = min(a)
bb = a.index(ans)
print(b[bb])

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
c=0
if n==0:
  print(x)
  sys.exit()
for i in range(x,-100,-1):
  c+=1
  if not i in p:
    print(i)
    sys.exit()
  if not (n+c) in p:
    print(n+c)
    sys.exit()

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

for i in range(len(list_p)):
  if(list_p[i] == -1):
    continue
  else:
    if(abs(list_p[i] - x) < t):
      t = abs(list_p[i] - x)
      num = list_p[i]

print(num)

Submission status: Wrong Answer

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

for i in range(x):
    a = x+i
    b = x-i
    if p.count(b)==0:
        print(b)
        exit()
    elif p.count(a)==0:
        print(a)
        exit()

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
P = list(map(int, input().split()))
sortP = sorted(P)
if N==0:
    print(X)
elif sortP[0]>X:
    print(X)
elif sortP[N-1]<X:
    print(X)
else:
    for n in range(sortP[0]-2,sortP[N-1]+2):
        if n in sortP:
            continue
        if n ==X:
            print(X)
        elif n>X:
            if X-a<=n-X:
                print(a)
                break
            else:
                print(n)
                break
        a = n