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())
if N==0:
    print(X)
    exit()
p=list(map(int,input().split()))
ans_cand=[]
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_cand.append(num)
            first_or_second=1
        else:
            ans_cand.append(num)
            a=abs(X-ans_cand[0])
            b=abs(X-ans_cand[1])
            if a==b:
                ans=min(ans_cand)
                print(ans)
            elif a>b:
                ans=ans_cand[1]
                print(ans)
            else:
                ans=ans_cand[0]
                print(ans)
            exit()
        num=num+x*plmi

Submission status: Wrong Answer

Solution code:
def readInt():
    return list(map(int,input().split()))
    
x,n = readInt()
a = []
if 0<n<100:
    p = readInt()
    p_r = [int(i) for i in range(101) if i not in p]
    # print(p_r)
    for i in p_r:
        dif = abs(x-i)
        a.append(dif)
    # print(a)
    print(p_r[a.index(min(a))])
elif n==0:
    print(x)
else:
    print(0)

Submission status: Wrong Answer

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

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


        for i in p:
            if X > i:
                continue
            else :
                roof = i
                num = p.index(i)
                break

        if num == 0:
            if X == roof:
                ans = X - 1
            else:
                ans = X
        
        

        
        if num == N - 1:
            if X - 1 == p[num - 1]:
                ans = X + 1
            else :
                ans = X - 1
        else:
            i = 1
            while True:
                if X - i == p[num - i]:
                    if X + i == p[num + i]:
                        if num - i == 0:
                            ans = p[0] -1
                            break
                        if num + i == N - 1 and X - i - 1 == p[num - i - 1]:
                            ans = p[num + 1] + 1
                            break
                        
                        i += 1
                        continue
                    else :
                        ans = X + i
                        break
                else :
                    ans = X - i
                    break

else :
    ans = X

print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N==0:
  print(X)
else:
  P = list(map(int,input().split()))
  a = X+1
  b = X-1

  if X not in P:
    print(X)
  
  else:
    while a not in P:
      break
      a+=1
    while b not in P:
      break
      b-=1
      
    if abs(X-a)>abs(X-b):
      print(a)
    else:
      print(b)

Submission status: Wrong Answer

Solution code:
[X, N] = list(map(int, input().split()))
A = []
try:
  P = list(map(int, input().split()))
  list_int = [x for x in range(0, 102)]
  list_int_d = list(set(list_int) - set(P))
  list_int_d.sort()
  print(list_int_d)
  for i in list_int_d:
    A.append(abs(X - i))
  if 0 in A:
    print(X)
  else:
    Index = A.index(min(A))
    print(list_int_d[Index])
except EOFError:
  print(X)

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,102):
	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 = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    Ps = set([int(i) for i in input().split()])
    if not X in Ps:
        print(X)

    diff = 0
    while True:
        if not X - diff in Ps:
            print(X - diff)
            break
        if (not X + diff in Ps) and (X + diff < 101):
            print(X + diff)
            break
        diff += 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()))
    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=[]
for a in A:
    if abs(a-minip)<minimini:
        minimini=abs(a-minip)
        answer.append(a)
        
print(max(answer))

Submission status: Wrong Answer

Solution code:
import sys
x,n =map(int,input().split())
if n == 0:
    print(x)
    sys.exit()
p = list(map(int,input().split()))
p.sort()
wk = 101
an = 0
if n ==100:
    print(0)
    sys.exit()
for i in range(1,101):
    if x!=i:
        if p.count(i)==0:
            if abs(x-i)<wk:
                an =i
                wk = abs(x-i)
            else:
                print(an)
                sys.exit()
print(an)

Submission status: Wrong Answer

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

l = list(range(101))

for i in p:
        if i in l:
                l.remove(i)
r = 102
sa = 9999
for j in l:
        if sa > abs(x - j):
                sa = abs(x - j)
                r = j
        elif sa == abs(x - j) and r > j:
                sa = abs(x - j)
                r = j
print(r)

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)

        value_left=x-1
        value_right=x+1

        index_left=0
        index_right=n
        if index_left!=0:
            index_left=index-1
        if index_right!=n:
            index_right=index+1
        
        if index_left==0:
            ans=x-1
        elif index_right==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: Wrong Answer

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

result = x
sa = 100
count = 0
a = 0
for l in range(1,101):
    
    if l in p:
        a = 1
        continue
    
    if sa <= abs(x-l):
        result = count
        a = 0
        break

    count = l
    sa = abs(x -l)
else:
    result = count
    a = 0
if a == 1:
    result = ""
print(result)

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]

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(1, 100 + 1):
    if candidate in p : continue

    diff_candidate = abs(X - candidate)
    diff_answer = abs(X - answer)

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

print(answer)

Submission status: Wrong Answer

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

D = 10000
res = 0
for i in range(1,100+1):
  if i in P:
    continue
  X2 = abs(X-i)
  if X2 < D:
    D = X2
    res = i
#
print(res)

Submission status: Wrong Answer

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

if N == 100:
    index = X

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

Solution code:
X, N = map(int, input().split())
try:
  list_  = list(map(int, input().split()))
except:
  print(X)

else:
    for i in range(1, 101):
        if not (X-i) in list_ and (X-i) > 0:
            print(X-i)
            break
        
        elif not(X+i) in list_:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
if n == 0:
  print(x)
  exit()
p=list(map(int, input().split()))
all=set(range(-100,101))
s_p=set(p)
kouho=sorted(all-s_p)

min_dis=201
for i in kouho:
  dis=abs(i-x)
  if min_dis > dis:
    min_i=i
    min_dis=dis
print(min_i)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)

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

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


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

l=[0] * 100

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

diff=min(101-x,x)
ans=-1 if x < 51 else 101
for i in range(100):
    if l[i] == 0 and diff > abs(x-(i+1)):
        diff= abs(x-(i+1))
        ans=i+1

print(ans)

Submission status: Wrong Answer

Solution code:
X, N = input().split()
p = input().split()
X = int(X)
N = int(N)
min = 101
ans = -100
for i in range(-101, 101):
    if str(i) in p:
        continue
    a = abs(i - X)
    if a < min:
        min = a
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
def serch(x,p,i):
    if not x+i in p:
        print(x+i)
        exit()
    else:
        if i>0:
            i = -1*(i+1)
        if i<0:
            i = -1*i
        serch(x,p,i)

X,N = map(int, input().split())
if N == 0:
    print(X)
p = list(map(int, input().split()))
if not X in p:
    print(p) 
else:
    serch(X,p,-1)

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]

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

answer = 1
for candidate in range(1, 100 + 1):
    if candidate in p : continue

    diff_candidate = abs(X - candidate)
    diff_answer = abs(X - answer)

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

print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

x,n=(int(y) for y in input().split())

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

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

st = []
for i in range(n):
  st.append(s[i] - x)

ss = np.abs(st)
ss.sort()

for t in range(n):
  if ss[t] != t:
    ans = t
    break
fans = x - t
ffans = x + t
if fans in s :
  print(ffans)
else:
  print(fans)

Submission status: Wrong Answer

Solution code:
def readInt():
    return list(map(int,input().split()))
    
x,n = readInt()
a = []
if 0<n<100:
    p = readInt()
    p_r = [int(i) for i in range(101) if i not in p]
    # print(p_r)
    for i in p_r:
        dif = abs(x-i)
        a.append(dif)
    # print(a)
    print(p_r[a.index(min(a))])
else:
    print(x)

Submission status: Wrong Answer

Solution code:
tmp = list(map(int, input().split()))
x = tmp[0]
n = tmp[1]
if n == 0:
    print(x)
    exit()

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

i = 1

while True:
    if not x-i in p:
        print(x-i)
        break
    if not x+i in p:
        print(x+i)
        break
    i += 1

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 = 101
l2 = np.array([i for i in range(1,101)])
l3 = set(l1) ^ set(l2)  
for item in l3:
  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())



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


for i in range(0,101):
    if l.count(int(X))==0:
        print(int(X))
        break 


    elif l.count(int(X-i))==0:
        print(int(X-i))
        break 

    

    if X+i<=100:
        if l.count(int(X+i))==0:
         print(int(X+i))
         break

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)
else :
    P = list(map(int,input().split()))
    a = list(range(-X,10000000))
    ab = 100
    an = []
    for i in range(N):
        a.remove(P[i])
        a = a
    for j in range(101 - N):
        ab = min(ab,abs(X - a[j]))
    if X - ab in a :
        print(X - ab)
    elif X + ab in a:
        print(X + ab)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
import sys
INF=1e9
import bisect
def get_int(): return int(stdin.readline().strip())
def get_ints(): return map(int,stdin.readline().strip().split()) 
def get_array(): return list(map(int,stdin.readline().strip().split()))
def get_string(): return stdin.readline().strip()
def op(c): return stdout.write(c)
#from collections import defaultdict 
#for _ in range(int(stdin.readline())):
x,n=get_ints()
p=get_array()
if n==0:
    print(x)
else:
    diff1=INF
    ans=0
    for i in range(-100,101):
        if i not in p:
            diff=abs(i-x)
            if diff<diff1:
                diff1=diff
                ans=i
    print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
try:
  a=list(map(int,input().split()))
  
  
  a=sorted(a)
  ff=a[-1]-a[0]+1

  if x<a[0]:
    print(x)
  elif x>a[-1]:
    print(x)
  else:
    bb=list(range((a[0]-1),(a[-1])))
    b=list(range((a[0]-1),(a[-1])+ff))
    for n in range(n):
      b.remove(a[n])
  
    f=len(b)


    d=abs(x-int(b[0]))
    ans=b[0]

    for n in range(f):
      c=abs(x-int(b[n]))
      if d>c:
        ans=b[n]
        d=c
  
    print(ans)

    print(bb)
except:
  print(x)

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(-1, 110):
            if num not in arr:
                minRes = num if abs(num-x) < abs(x-minRes) else minRes
    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 = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    Ps = set([int(i) for i in input().split()])
    if not X in Ps:
        print(X)

    diff = 0
    while True:
        if not X - diff in Ps:
            print(X - diff)
            break
        if not X + diff in Ps:
            print(X + diff)
            break
        diff += 1

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,-200,-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:
x,n = map(int,input().strip().split())
list = []
list1 = []
if n==0:
    print(x)
else:
    dic = {}
    a = input().split()
    for i in range(0, len(a)):
        list.append(int(a[i]))
    print(list)
    i = 1
    while True:
        b = x+i
        c = x-i
        if list.__contains__(b) and list.__contains__(c):
            i = i+1
        else:
            list1.append(b)
            list1.append(c)
            if(b>n and c<n):
                print(b)
            else:
                print(min(list1))
            break

Submission status: Wrong Answer

Solution code:
import sys
x,n = map(int,input().split())
a = list(map(int,input().split()))
if x in a:
    s = 0; t = 0
    for i in range(x+1,100):
        if i not in a:
            s = i
            sys.exit()
    for j in reversed(range(x-1,-100)):
        if i not in a:
            t = j
            sys.exit()
    if abs(x-s) < abs(x-t):
        print(s)
    elif abs(x-s) > abs(x-t):
        print(t)
else:
    print(x)

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 = int(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 math
def main():
    x, n = map(int, input().split())
    if n==0:
        out = x
    else:
        p_l = [int(_) for _ in input().split()]

        c_l = []
        for i in range(-101, 101):
            c_l.append(i)
        
        for p in p_l:
            if p in c_l:
                c_l[c_l.index(p)]=1000
        
        abs_c_l = []
        for i in range(-101, 101):
            abs_c_l.append(i)

        for i, c in enumerate(c_l):
            abs_c_l[i] = abs(c_l[i] - x)
        
        m = min(abs_c_l)
        out = c_l[abs_c_l.index(m)]
        
    print(out)

main()

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(0,10000000))
    ab = 100
    an = []
    for i in range(N):
        a.remove(P[i])
        a = a
    for j in range(101 - N):
        ab = min(ab,abs(X - a[j]))
    if X - ab in a :
        print(X - ab)
    elif X + ab in a:
        print(X + ab)

Submission status: Wrong Answer

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

result = x
sa = 100
count = 0
a = 0
for l in range(1,101):
    a = 1
    if l in p:
        continue
    
    if sa <= abs(x-l):
        result = count 
        break

    count = l
    sa = abs(x -l)
else:
    result = count
if a == 0:
    result = ""
print(result)

Submission status: Wrong Answer

Solution code:
def test(X, N, P):
  P_int = []
  
  for i in P:
    P_int.append(int(i))

  lis = []
  
  for i in list(range(101)):
    if i not in P_int:
      lis.append(i)
  
  min_adv = 1000
  min_num = 1000

  for i in lis:
    rec_adv = abs(X - i)

    if rec_adv < min_adv:
      min_num = i
      min_adv = rec_adv

  print(str(min_num))

X, N = input().split()
P = input().split()

test(int(X), int(N), P)

Submission status: Wrong Answer

Solution code:
def main():
    import copy

    num, quantity = map(int, input().split())
    nums = list(map(int, input().split()))
    nums.sort()
    
    if quantity == 0:
        print(num)
        return
    
    i = 0

    minus_num = copy.copy(num)
    plus_num = copy.copy(num)

    while i < len(nums):
        if num not in nums:
            print(num)
            return
        
        if minus_num not in nums:
            print(minus_num)
            return
        
        if plus_num not in nums:
            print(plus_num)
            return
        
        minus_num = minus_num - 1
        plus_num = plus_num + 1
        i = i + 1

main()

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()))
    m = [i for i in range(1, 1000)]
    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 = [int(i) for i in input().split()]

p = [int(i) for i in input().split()] if N > 0 else [0]
p = sorted(p, key=lambda x: x)

if min(p) == X :
   print(min(p) - 1)
   exit()

if max(p) == X and max(p)-1 not in p:
   print(max(p)-1)
   exit()
elif max(p) == X  :
   print(max(p)+1)
   exit()
else:
   None

minDistance = 10**9
minNum = -10**9

for i in range(min(p), max(p)+1, 1):
  if (i not in p) and minDistance > abs(X - i) :
     minNum = i
     minDistance = abs(X - i)

minNum = min(p)-1 if minNum == -10**9 and min(p) == X else minNum
minNum = max(p)-1 if minNum == -10**9 and max(p) == X else minNum

print(X if N==0 else minNum )

Submission status: Wrong Answer

Solution code:
import math
def main():
    x, n = map(int, input().split())
    if n==0:
        out = x
    else:
        p_l = [int(_) for _ in input().split()]

        c_l = []
        for i in range(-101, 101):
            c_l.append(i)
        
        for p in p_l:
            if p in c_l:
                c_l[c_l.index(p)]=100
        
        abs_c_l = []
        for i in range(-101, 101):
            abs_c_l.append(i)

        for i, c in enumerate(c_l):
            abs_c_l[i] = abs(c_l[i] - x)
        
        m = min(abs_c_l)
        out = c_l[abs_c_l.index(m)]
        
    print(out)

main()

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

answer = 1
for candidate in range(1, 100 + 1):
    if candidate in p : continue

    diff_candidate = abs(X - candidate)
    diff_answer = abs(X - answer)

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

print(answer)

Submission status: Wrong Answer

Solution code:
x,n,*p=map(int,open(0).read().split())
if n==0:
    print(x)
else:
    q=[i for i in range(101) if not(i in p)]
    m=[]
    for j in q:
        m.append(abs(j-x))
    a,b=x-min(m),x+min(m)
    if a in q:
        print(a)
    else:
        print(b)

Submission status: Wrong Answer

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

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

arr = [0]*101
tmp=float('inf')
for i in range(len(P)):
  target=P[i]
  arr[target]=1

near=float('inf')
value =0
idx =0
for i in range(len(arr)):
  if arr[i] == 0:
    if near > abs(X-i):
      near = abs(X-i)
      idx = i
if idx == 0:
  print(idx)
elif 0 <= min(idx, 0):
  print(0)
elif (idx +1 in P) or (idx-1 in P):
  print(idx)
else:
  print(-idx)

Submission status: Wrong Answer

Solution code:
def forbidden_list():
    input_value = [int(i) for i in input().split()]
    num =input_value[0]
    length = input_value[1]
    seqence = [int(i) for i in input().split()]
    close = 999
    best = 0

    next_close = 999
    next_best = 0
    if length == 0:
        print(num)
    else:
        for i in range(len(seqence)):
            temp = abs(num - seqence[i])
            if temp < close and temp != 0:
                close = temp
                best = seqence[i]
                #print(best)
        best_range = list(range(best-10, best+10))
        for i in range(len(best_range)):
            next_temp = abs(num - best_range[i])
            if (next_temp < next_close) and best_range[i] not in seqence:
                next_close = next_temp
                next_best = best_range[i]
        print(next_best)
    
forbidden_list()

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, 101, 1):
            if j not in p:
                ans1 = j
                break
        for k in range(x - 1, 0, -1):
            if k not in p:
                ans2 = k
                break
        break

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

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(-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):
      t = abs(list_p[i] - x)
      num = list_p[i]

print(num)

Submission status: Wrong Answer

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

D = 10000
res = 0
for i in range(1,100):
  if i in P:
    continue
  X2 = abs(X-i)
  if X2 < D:
    D = X2
    res = i
#
print(res)

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)
s.sort()
#print(s)

absmin = 10000000
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p =list(map(int, input().split()))
al=set(range(101))
not_p = list(set(al) - set(p))

not_p_diff = list(map(lambda n: abs(n - X), not_p))
num = not_p_diff.index(min(not_p_diff))

print(not_p[num])

Submission status: Wrong Answer

Solution code:
s = input().split()
intX = int(s[0])
intN = int(s[1])
inList = list(map(int,input().split()))

iCnt = 100
minDiv = 100
rCnt = -1
div = 0
while iCnt > 0 :
    if (inList.count(iCnt) == 0) : 
        div = abs(intX - iCnt)
        if (minDiv >= div) :   
            minDiv = div
            rCnt = iCnt
    iCnt -= 1
print(rCnt)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
list2 = set(map(int, input().split()))
list1=list(range(-98,101,1))
result = list(set(list1) - set(list2))
for i in range(100):
    if a-i in result:
        print(a-i)
        exit()
    elif a+i in result:
        print(a+i)
        exit()
else:
  exit()

Submission status: Wrong Answer

Solution code:
import math
def main():
    x, n = map(int, input().split())
    if n==0:
        out = x
    else:
        p_l = [int(_) for _ in input().split()]

        c_l = []
        for i in range(-100, 100):
            c_l.append(i)
        
        for p in p_l:
            if p in c_l:
                c_l[c_l.index(p)]=100
        
        abs_c_l = []
        for i in range(-100, 100):
            abs_c_l.append(i)

        for i, c in enumerate(c_l):
            abs_c_l[i] = abs(c_l[i] - x)
        
        m = min(abs_c_l)
        out = c_l[abs_c_l.index(m)]
        
    print(out)

main()

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 = []
p_min=min(p)
p_max=max(p)
for i in range(abs(p_min-1),abs(p_max+1)):
    if i not in p:
        a.append((x - i)**2)
        b.append(i)
ans = min(a)
bb = a.index(ans)
print(b[bb])