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:
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(-5,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:
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,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())
if n == 0:
    print(x)
else:
    l = [k for k in range(101)]
    for p in input().split():
        p = int(p)
        l[p] = 1000
    l_d = [x-k for k in l]
    l_sorted = sorted(l_d,key= lambda x: (-x+0.1, x)[x > 0])
    print(x - l_sorted[0])

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

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 = 9999
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 = map(int, input().split())
if n==0:
  print(x)
else:
  p = list(map(int, input().split()))
  
  for i in range(n):
    if not (x-(i+1)) in p:
      print(x-(i+1))
      break
    elif not (x+(i+1)) in p:
      print(x+(i+1))
      break

Submission status: Wrong Answer

Solution code:
X,N=list(map(int,input().split()))
if N>0:p=list(map(int,input().split()))
else:p=[]
memo=[False for i in range(105)]
for i in range(N):memo[p[i]]=True


riget=X+1
left=X-1
ans_r=0
ans_l=0

while(True):
    if memo[riget]==False:
        ans_r=riget
        break
    riget+=1
    
while(True):
    if memo[left]==False:
        ans_l=left
        break
    left-=1
    
if N==0:print(X)
elif abs(X-ans_r)>=abs(X-ans_l):print(ans_l)
else:print(ans_r)

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(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:
import sys
X, N = map(int, input().split())
P = list(map(int, input().split()))

if len(P) == 0 or not X in P:
    print(X)
    sys.exit()

flg = 1000
ans = 1000
m = max(P)
itera = list(range(1, m + 1))
itera.reverse()

for i in itera:
    if not i in P and flg > abs(X - i):
        flg = abs(X - i)
        ans = min(ans, i)

if ans == 1000:
    if abs(X - m - 1) <= X:
        ans = m + 1

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: 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(1, 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:
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(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()]
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 abs(x-b) < abs(x-a):
    print(b)
  elif abs(x-a) < abs(x-b):
    print(a)
  else:
    print(a) if a<b else print(b)

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)
for l in m:
    a = l - x
    if abs(u) > abs(a):
        u = a
print(u+x)

Submission status: Wrong Answer

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

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

  if (int(x) not in p):
    print(int(x))
    count=1


  while (count==0):
    for i in range(int(n)):
      if (abs(int(p[i])-int(x)) == add):
        count = count+1
    if (count==2):
        add = add+1
        count=0
    if (count==1):
      if (int(x)-add in p):
        print(int(x)+add)
      else:
        print(int(x)-add)
    if (count==0):
      print(int(x)-add)
      count=1
else:
  print(int(x))

Submission status: Wrong Answer

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

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

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

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

if (x in a):
    pass
else:
    a.append(x)
    a.sort()

idx_x = a.index(x)

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

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

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

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

Submission status: Wrong Answer

Solution code:
X, N = input().split()
p = input().split()
X = int(X)
N = int(N)
min = 101
ans = 0
if N == 100:
    ans = ""
else:
    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:
a,b= map(int,input().split())
N = list(map(int,input().split()))
S =[]
key = 9999
for i in range(b):
	c = [N[i]-a]
	S.extend(c)
for i in range(b):
	if key > abs(S[i]):
		key= abs(S[i])
if key ==0:
	print(a)
else:
	if a - key in S:
		print(a-key)
	else:
		print(a+key)

Submission status: Wrong Answer

Solution code:
def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    else:
        p = [int(i) for i in input().split()]

    s = []
    for i in range(101):
        if not i in p:
            s.append(i)
    if not x in p:
        print(x)
        return
    
    t = s + [x]
    t.sort()
    pos = t.index(x)
    if pos == 0:
        print(t[pos+1])
        return
    try:
        if abs(x-t[pos-1]) <= abs(x-t[pos+1]):
            print(t[pos-1])
            return
        else:
            print(t[pos+1])
    except:
        print(s[-1])
        return

resolve()

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(X)==0:
        print(int(X))
        break 


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

    

    if X+i<=100:
        if l.count(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)
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, 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:
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
    if x < abs(minRes-x):
        minRes = 0
    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:
def nears_impl(x, dis, is_minus):
    def cal(x, dis):
        if is_minus:
            r = x - dis
            return r if r >= 0 else 0
        else:
            r = x + dis
            return r if r <= 100 else 100

    res = cal(x, dis)
    return res


def nears(start_x):
    yield start_x
    i = 1
    while True:
        yield nears_impl(start_x, i, True)
        yield nears_impl(start_x, i, False)
        i += 1


x, n = [int(x) for x in input().split(" ")]
    
if n == 0:
    print(x)
    exit()

p = [int(x) for x in input().split(" ")]

for near in nears(x):
    if near not in p:
        print(near)
        break

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,10**7):
        #print(p[l]+i)
        if p[l]+i in p:
            pass
        else:
            a = p[l]+i
            break

    for i in range(1, 10**7*-1, -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:
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  numbers=list(range(102))
  ans=X

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

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

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

try:
    p = list(map(int, input().split()))
except:
    print(X)
    exit()

if p.count(X) == 1:
    for i in range(1,N + 1):
        if p.count(X - i) != 1 or p.count(X + i) != 1:
            if p.count(X - i) == 1:
                print(X + i)
                exit()
            else:
                print(X - i)
                exit()

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

def solution(X, N, P):
    if N <= 0 or X not in P:
        return X

    P.sort()
    diff = [abs(p - X) for p in P]
    X_idx = diff.index(0)
    left = sorted(diff[:X_idx])
    right = sorted(diff[X_idx+1:])

    nearest_l = None
    nearest_r = None
    for i in range(1, len(P)):
        left = X - i
        right = X + i

        nearest_l = None
        nearest_r = None
        if left not in P and left >= 1:
            nearest_l = left
            break
        if right not in P:
            nearest_r = right
            break
    else:
        nearest_r = len(P) + 1
    if nearest_l and nearest_r:
        nearest = min(nearest_l, nearest_r)
    else:
        nearest = nearest_l or nearest_r
    return nearest

print(solution(X, N, P))

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()))
    a = list(range(10000000))
    ab = 100
    an = []
    for i in range(N):
        a.remove(P[i])
    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 = (int(x) for x in input().split())
p = [int(x) for x in input().split()]

result = 100

l = list(range(0,101))



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

        l[p[i]] = 200


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

        if l[i] != 200:

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



print(kotae)

Submission status: 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)-2
		ymax = max(max(A), X)+1
		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:
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,10**6):
        #print(p[l]+i)
        if p[l]+i in p:
            pass
        else:
            a = p[l]+i
            break

    for i in range(1, 10**6*-1, -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:
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)

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

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_:
            print(X-i)
            break
        
        elif not(X+i) in list_:
            print(X+i)
            break

Submission status: Wrong Answer

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

if Y % 2 != 0:
    print('No')
elif 2*X > Y:
    print('No')
elif 4*X < Y:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

n = X
i = 1

while 1 <= i <= 100:
    if n in p:
        if i % 2 == 0:
            n += i
        else:
            n -= i   
    else:
        print(n)
        break
    i += 1

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    a = x - 1
    b = x + 1
    if a not in p and b not in p:
        print(a)
    elif a not in p and b in p:
        print(a)
    elif a in p and b not in p:
        print(b)
    else:
        while True:
            a -= 1
            b += 1
            c = 0
            d = 0
            if a not in p:
                c = abs(a - x)
            if b not in p:
                d = abs(b - x)
            if c != 0 and d == 0:
                print(a)
                quit()
            elif c == 0 and d != 0:
                print(b)
                quit()
            elif c != 0 and d != 0:
                print(a)
                quit()

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='stable')
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())
p = list(map(int,input().split()))
ans = []
if N == 0:
    print(X)
elif X not in  p:
    print(X)
else:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],101):
        if i not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], -1, -1):
        if i not in p:
            ans.append(i)
            break
    
    ans = sorted(ans)
    ans2 = [abs(i-X) for i in ans]
    ans2 = sorted(ans2)
    print(ans[ans2.index(min(ans2))])
   # print(min(ans))

Submission status: Wrong Answer

Solution code:
a,b=map(int, input().split())
if b == 0:
  c = []
  b = False
  print(a)
else:
  c=list(map(int, input().split())) 
  b = True
while b ==True:
  k = 1
  m = a+k
  n = a-k
  if (m & n) not in c:
    print(n)
    b = False
    break
  if n not in c:
    print(n)
    b = False
    break
  if m not in c:
    print(m)
    b = False
    break
  k += 1

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(-100, 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())
if n > 0:
    P = list(map(int, input().split()))
else:
    P = []

ans, dist = 0, 1000
for i in range(101):
    if i not in P:
        if abs(i - x) < dist:
            dist = abs(i - x)
            ans = i
print(ans)

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(1, 102)]
  list_int_d = list(set(list_int) - set(P))
  list_int_d.sort()
  if X == 1 and 1 in P:
    print(0)
  else:
    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:
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,10**5):
        #print(p[l]+i)
        if p[l]+i in p:
            pass
        else:
            a = p[l]+i
            break

    for i in range(1, 10**5*-1, -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:
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<102:
            if num[x+count]==1:
                print(x+count)
                break    
        count+=1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

try:
    p = list(map(int, input().split()))
except EOFError:
    print(X)
    exit()

if p.count(X) == 1:
    for i in range(1,N + 1):
        if p.count(X - i) != 1 or p.count(X + i) != 1:
            if p.count(X - i) == 1:
                print(X + i)
                exit()
            else:
                print(X - i)
                exit()

Submission status: Wrong Answer

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

else:
    p = list(map(int, input().split()))
    abs_list = []
    re_list = []
    min = 1000
    min_index = 0

    for i in range(201):
        abs_list.append(-100+i)
    for j in p:
        abs_list.remove(j)
    for i in range(len(abs_list)):

        re_list.append(abs(abs_list[i] - X))
    for i in range(len(re_list)):
        if min > re_list[i]:
            min = re_list[i]
            min_index = i
    print(abs_list[min_index])

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
try:
  a=list(map(int,input().split()))
  
  
  a=sorted(a)

  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])+n))
    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:
XN = input().split()
X = int(XN[0])
N = int(XN[1])
if N == 0:
    print(X)
else:
    p = input().split()
    A = [None]*N
    for i in range(N):
        A[i] = abs(int(p[i])-X)
    print(A)
    if 0 not in A:
        print(X)
    else:
        j = 1
        while A.count(j) == 2:
            j += 1
        if A.count(j) == 0:
            print(X-j)
        else:
            if str(X-j) in p:
                print(X+j)
            else:
                print(X-j)

Submission status: Wrong Answer

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

l=list(map(int, input().split()))
a = x
b = x

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

Submission status: Wrong Answer

Solution code:
import sys

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

if n == 0:
  print(x)
  sys.exit()
  
if n == 1:
  print(abs(x - int(input())))
  sys.exit()

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

p.sort()
min = [100, 100]

for i in range(100):
  if i in p:
    continue
  hoge = abs(x - i)
  if min[0] > hoge:
    min[0] = hoge
    min[1] = i

print(min[1])

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(1, 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(1, 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:

X,N = map(int,input().split())
result = 1000000000000
tmp = 100000000
if N == 0:
    print(X)
    exit()
S = list(map(int,input().split()))
flag = True
m_flag = False
S.sort()
#print(S)
max_S = max(S)
min_S = min(S)
#負の整数の場合
if min_S < 0:
    min_S = abs(min_S)
    for i in range(1,min_S):
        for j in S:
            
            if -1*i == j and j < 0:
                flag = False
                break
        if flag == False:
            flag = True
            continue
        #print(i)
        if abs(X + i) <= result:
            #print("bb:"+str(abs(X + i)))
            result = abs(X + i)
            tmp = i
            m_flag = True
        
#正の整数の場合
for i in range(max_S+1):
    #含まれていないか確認
    for j in S:
        if i == j:
            flag = False
            break
    if flag == False:
        flag = True
        continue
    #print(i)
    if abs(X - i) < result:
        #print("aa:"+str(abs(X - i)))
        result = abs(X - i)
        tmp = i
        m_flag = False
#print(m_flag)
if m_flag == True:
    print(-tmp)
else:
    print(tmp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if N == 0:
    print(X)
else:
    p = set(map(int, input().split()))

    num = set(range(-102, 102))

    l = list(num.difference(p))
    l.sort()

    ans = 0
    absol = 110

    for i in l:
        a = abs(X - i)
        if a == 0:
            pass
        elif a < absol:
            absol = a
            ans = i
        else:
            pass

    print(ans)

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)

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