Problem:


Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Wrong Answer

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

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

p_list = [0]*100

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

# print(p_list)
dis = 100
index = -1
for i, j in enumerate(p_list):
    if j == 1:
        continue
    # print(i+1, abs(x-(i+1)))
    if dis > abs(x-(i+1)):
        dis = abs(x-(i+1))
        index = i+1
        # index=i
print(index)

Submission status: Wrong Answer

Solution code:
X, N = [int(i) for i in input().split(" ")]

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

p = {int(i) for i in input().split(" ")}

all_p = {i for i in range(max(p) + 1)}
ranges = all_p - p

diff = 1e9
for i in ranges:
    if diff > abs(i - X):
        diff = abs(i - X)

ans_1 = X + diff
ans_2 = X - diff

for i in ranges:
    if i == ans_2:
        print(ans_2)
        break
else:
    print(ans_1)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
  print(X)
  exit()
else:
  P = [int(x) for x in input().split()]
  P.sort()
  if X in P:
    a = P.index(X)
    for j in range(1,N):
      if a-j<0:
        print(X-j)
        exit()
      elif a+j>=N:
        print(X+j)
        exit()
      elif (a-j>=0 and P[a-j]==X-j) and (a+j<N and P[a+j]==X+j):
        continue
      elif a-j>=0 and P[a-j]<X-j:
        print(X-j)
        exit()
      elif a+j<N and P[a+j]>X+j:
        print(X+j)
        exit()
  else:
    print(X)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
  print(X)
else:
  P = [int(i) for i in input().split()]

  P.sort()

  if P[0] > X:
    print(X)
  elif P[-1] < X:
    print(X)
  else:
    cand = P[0]-1
    for i in range(P[0], P[-1]):
      if i not in P:
        if abs(X-cand) > abs(i-X):
          cand = i
    print(cand)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    a = list(map(int, input().split()))
    i=0
    j=0
    ans=0
    while(j!=x):
        if x-j not in a:
            print(x-j)
            break
        elif x+j not in a:
            print(x+j)
            break
        else:
            j+=1

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
  print(X)
  exit()
else:
  P = [int(x) for x in input().split()]
  P.sort()
  if X in P:
    a = P.index(X)
    for j in range(1,N):
      if a-j<0:
        print(X-j)
        exit()
      elif (a-j>=0 and P[a-j]==X-j) and (a+j<N and P[a+j]==X+j):
        continue
      elif a-j>=0 and P[a-j]<X-j:
        print(X-j)
        exit()
      elif a+j<N and P[a+j]>X+j:
        print(X+j)
        exit()
  else:
    print(X)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    a = list(map(int, input().split()))
    i=0
    j=0
    ans=0
    while(j!=n):
        if x-j not in a:
            print(x-j)
            break
        elif x+j not in a:
            print(x+j)
            break
        else:
            j+=1

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
  print(X)
else:
  P = [int(i) for i in input().split()]

  P.sort()

  if P[0] > X:
    print(X)
  elif P[-1] < X:
    print(X)
  else:
    cand = P[0]-1
    for i in range(P[-1]):
      if i not in P:
        if abs(X-cand) > abs(i-X):
          cand = i
    print(cand)

Submission status: Wrong Answer

Solution code:
X, N = [int(i) for i in input().split(" ")]

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

p = {int(i) for i in input().split(" ")}

all_p = {i for i in range(max(p) + 1)}
ranges = all_p - p

diff = 1e9
ans = []
for i in ranges:
    if diff >= abs(i - X):
        if diff != abs(i - X):
            ans = []
        diff = abs(i - X)
        ans.append(i)

print(min(ans))

Submission status: Wrong Answer

Solution code:
X, N = [int(i) for i in input().split(" ")]

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

p = {int(i) for i in input().split(" ")}

all_p = {i for i in range(max(p) + 1)}
ranges = all_p - p


diff = 1e9
ans = 0
for i in ranges:
    if diff > abs(i - X):
        diff = abs(i - X)
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
X, N = [int(i) for i in input().split(" ")]

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

p = {int(i) for i in input().split(" ")}

all_p = {i for i in range(max(p) + 1)}
ranges = all_p - p

print(ranges)

diff = 1e9
ans = 0
for i in ranges:
    if diff > abs(i - X):
        diff = abs(i - X)
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
l = set(i for i in range(101))
sa = 1000
ans = 0
for i in l-p:
    if sa > abs(x-i):
        sa = abs(x-i)
        ans = i
print(ans)

Submission status: Wrong Answer

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

for a in range(x+1):
    b = x - a
    if 2 * a + 4 * b == y:
        print('Yes')
print('No')

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
min = 100
pp = list(map(lambda x: x-X, p))
i = 0
f = 0
while f == 0:
    if not i in pp:
        res = X - i
        break
    if i >= 0:
        i = -1 * (i +1)
    else:
        i = -1 * i
print(res)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
min = 100
pp = list(map(lambda x: X-x, p))
i = 0
f = 0
while f == 0:
    if not i in pp:
        res = X - i
        break
    if i >= 0:
        i = -1 * (i +1)
    else:
        i = -1 * i
print(res)

Submission status: Wrong Answer

Solution code:
X, N = [int(x) for x in input().split()]

if N > 0:
    p = [int(x) for x in input().split()]

    for i in range(N):
        if X - i not in p:
            print(X - i)
            break
        elif X + i not in p:
            print(X + i)
            break
else:
    print(X)

Submission status: Wrong Answer

Solution code:
def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))
    p.sort(key = lambda e : (abs(e - X), e))
    y, dy, ddy = X, -1, 1
    ans = X if N == 0 else p[-1] + (1 if X < p[-1] else -1)
    for i in p:
        if i != y:
            ans = y
            break
        else:
            y, dy, ddy = y + dy, -dy + ddy, -ddy
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))
    p.sort(key = lambda e : (abs(e - X), e))
    y, dy, ddy = X, -1, 1
    ans = X if N == 0 else p[-1] + (1 if X < p[-1] else -1)
    for i in p:
        if i != y:
            ans = y
        else:
            y, dy, ddy = y + dy, -dy + ddy, -ddy
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d={int(x):True for x in input().split()}

temp=n
ans=0
while(True):
    if(temp not in d):
        ans=temp
        break
    temp+=1
temp=n
while(True):
    if(temp not in d):
        if(abs(n-temp)<abs(n-ans)):
            ans=temp
        break
    temp-=1
    if(temp<0):
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d={int(x):True for x in input().split()}

temp=n
ans=0
while(True):
    if(temp not in d):
        ans=temp
        break
    temp+=1
temp=n
while(True):
    if(temp not in d):
        if(abs(n-temp)<abs(n-ans)):
            ans=temp
        break
    temp-=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d={int(x):True for x in input().split()}

temp=n
ans=0
while(True):
    if(temp not in d):
        ans=temp
        break
    temp+=1
temp=n
while(True):
    if(temp not in d):
        if(abs(n-temp)<ans):
            ans=temp
            break
    temp-=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if X not in p:
    print(X)
else:
    mn = min(p)
    mx = max(p)
    a = [x for x in range(mn, mx) if x not in p]

    if a:
        c = a.pop()
        m = abs(c - X)
        for x in a:
            if m > abs(x - X):
                c = x
                m = abs(x - X)
            elif m == abs(x - X):
                c = min(c, x)
        print(c)
    else:
        print(min(abs(mn-X), abs(mx-X)))

Submission status: Wrong Answer

Solution code:
import sys

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

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

i = 1
while True:
    if X - i > 0:
        if not X - i in L:
            print(X-i)
            break

        if not X + i in L:
            print(X+i)
            break
    else:
        if not X + i in L:
            print(X+i)
            break

        if not X - i in L:
            print(X-i)
            break

    i += 1

Submission status: Wrong Answer

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

if X not in p:
    print(X)
else:
    mn = min(p)
    mx = max(p)
    a = [x for x in range(mn, mx) if x not in p]

    if a:
        c = a.pop()
        m = abs(c - X)
        for x in a:
            if m > abs(x - X):
                c = x
                m = abs(x - X)
        print(c)
    else:
        print(min(abs(mn-X), abs(mx-X)))

Submission status: Wrong Answer

Solution code:
import sys

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

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

i = 1
while True:
    if X - i >= 0:
        if not X - i in L:
            print(X-i)
            break

        if not X + i in L:
            print(X+i)
            break
    else:
        if not X + i in L:
            print(X+i)
            break

        if not X - i in L:
            print(X-i)
            break

    i += 1

Submission status: Wrong Answer

Solution code:
X, N = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]

i = 1

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

while (True):
    a = X + i
    b = X - i
    if b in P and a not in P:
        print(a)
        break
    if a in P and b not in P:
        print(b)
        break
    if a not in P and b not in P:
        print(b)
        break
    i += 1

Submission status: Wrong Answer

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

if X not in p:
    print(X)
else:
    mn = min(p)
    mx = max(p)
    a = [x for x in range(mn, mx) if x not in p]

    if a:
        c = a.pop()
        m = abs(c - X)
        for x in a:
            if m > abs(x - X):
                c = x
        print(c)
    else:
        print(min(abs(mn-X), abs(mx-X)))

Submission status: Wrong Answer

Solution code:
X, N = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]

i = 1

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

while (True):
    a = X + i
    b = X - i
    if b in P and a not in P:
        print(a)
        break
    if a in P and b not in P:
        print(b)
        break
    if a not in P and b not in P:
        print(b)
        break
    i += 1

Submission status: Wrong Answer

Solution code:
import sys

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

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

i = 1
while True:
    if not X - i in L:
        X = X - i
        break

    if not X + i in L:
        X = X + i
        break

    i += 1

print(X)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    X, N = rl()
    if N == 0:
        print (0)
        return
    P = rl()
    S = set(P)
    i = 0
    while 1:
        if X - i not in S:
            print (X - i)
            return
        elif X + i not in S:
            print (X + i)
            return
        i += 1






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()

Submission status: Wrong Answer

Solution code:
line = input().split()

num = int(line[0])
arrn = int(line[1])

if arrn==0:
  print(num)
  
else:
  arr = input().split()
  i = 1;
  
  while True:
    #小さい側
    left = num - i
    if str(left) in arr:
      print("",end="")
    else:
      print(left)
      break

    #大きい側
    right = num + i
    if str(right) in arr:
      print("",end="")
    else:
      print(right)
      break

    i += 1

Submission status: Wrong Answer

Solution code:
line = input().split()

num = int(line[0])
arrn = int(line[1])

if arrn==0:
  print(num)
  
else:
  arr = input().split()
  i = 1;
  
  while True:
    #小さい側
    left = num - i
    if left != 0:
      if str(left) in arr:
        print("",end="")
      else:
        print(left)
        break

    #大きい側
    right = num + i
    if str(right) in arr:
      print("",end="")
    else:
      print(right)
      break

    i += 1

Submission status: Wrong Answer

Solution code:
line = input().split()

num = int(line[0])
arrn = int(line[1])

if arrn==0:
  print(num)
  
else:
  arr = input().split()
  i = 1;
  
  while True:
    #小さい側
    left = num - i
    if left > 0:
      if str(left) in arr:
        print("",end="")
      else:
        print(left)
        break

    #大きい側
    right = num + i
    if str(right) in arr:
      print("",end="")
    else:
      print(right)
      break

    i += 1

Submission status: Wrong Answer

Solution code:
import math
def main():
    x,n = map(int, input().split())
    if n == 0:
        print(x)
        return
    arr = list(map(int, input().split()))
    d = max(arr)
    ans = -1
    for i in range(102):
        if i not in arr:
            if abs(x - i) < d:
                d = abs(x - i)
                ans = i
    print(ans)





main()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
a = set(map(int, input().split()))
print(min(abs(i-x) for i in range(102) if i not in a))

Submission status: Wrong Answer

Solution code:
import math
def main():
    x,n = map(int, input().split())
    if n == 0:
        print(x)
        return
    arr = list(map(int, input().split()))
    d = max(arr)
    ans = -1
    for i in range(max(arr) + 2):
        if i not in arr:
            if abs(x - i) < d:
                d = abs(x - i)
                ans = i
    print(ans)





main()

Submission status: Wrong Answer

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

import sys

if n==0:
  print(x)
  sys.exit()
elif n==100:
  print()
  sys.exit()
  
P = list(map(int, input().split()))
P.sort()
notP = [i for i in range(1, 101) if i not in P]

ans = notP[0]
min_delta = abs(x - ans)

for p in notP:
  delta = abs(x - p)
  if delta<min_delta:
    ans = p
    min_delta = abs(x - ans)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))
NL = [ i for i in range(0, 102) if i == X or i not in P ]

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

print(NL)
idx = NL.index(X)
if NL[idx + 1] - X >= X - NL[idx-1]:
    print(NL[idx-1])
else:
    print(NL[idx+1])

Submission status: Wrong Answer

Solution code:
x, n = list(map(int, input().split()))
if not n:
  print(x) 
else:
  l = list(map(int, input().split()))
  dic = {} 
  for ll in l: dic[ll] = 1
  i = 1
  while True:
    if not dic.get(x-i,0):
      print(x-i)
      break
    elif not dic.get(x+i, 0):
      print(x+i) 
      break
    i+=1

Submission status: Wrong Answer

Solution code:
#abc170
x, n = map(int, input().split())
ln = []
if n == 0:
  pass
else:
  ln = list(map(int, input().split()))
i = 0

while i < 5:
    
    
    if (x-i in ln) == False:
        print(x-i)
        break
    elif (x+i in ln) == False:
        print(x+i)
        break  
    else:
        i +=1

Submission status: Wrong Answer

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

def solve(x, n, seq):
    if n == 0:
        print(x)
        return

    lower = x - 1
    higher = x + 1

    seq_set = set()

    for i in range(n):
        current = seq[i]
        seq_set.add(current)
    
    while lower in seq_set and lower > 0:
        lower -= 1
    
    while higher in seq_set and higher <= 100:
        higher += 1
    
    lower_diff = abs(lower - x)
    higher_diff = abs(higher - x)

    if lower_diff <= higher_diff:
        print(lower)
    elif higher not in seq_set:
        print(higher)
    else:
        print(x)
    

solve(x,n,seq)

Submission status: Wrong Answer

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

def solve(x, n, seq):
    if n == 0:
        print(x)
        return

    lower = x - 1
    higher = x + 1

    seq_set = set()

    for i in range(n):
        current = seq[i]
        seq_set.add(current)
    
    while lower in seq_set and lower > 0:
        lower -= 1
    
    while higher in seq_set and higher <= 100:
        higher += 1
    
    lower_diff = abs(lower - x)
    higher_diff = abs(higher - x)

    if lower_diff <= higher_diff:
        print(lower)
    elif higher:
        print(higher)
    else:
        print(x)
    

solve(x,n,seq)

Submission status: Wrong Answer

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

def solve(x, n, seq):
    if n == 0:
        print(x)
        return

    lower = x - 1
    higher = x + 1

    seq_set = set()

    for i in range(n):
        current = seq[i]
        seq_set.add(current)
    
    while lower in seq_set and lower > 0:
        lower -= 1
    
    while higher in seq_set and higher < 100:
        higher += 1
    
    lower_diff = abs(lower - x)
    higher_diff = abs(higher - x)

    if lower_diff <= higher_diff and lower not in seq_set:
        print(lower)
    elif higher not in seq_set:
        print(higher)
    else:
        print(x)
    

solve(x,n,seq)

Submission status: Wrong Answer

Solution code:
import math
a,b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
l=[]
max=10**3
for i in range(0,101):
    if( i in c):
        pass
    else:
        if(abs(i-a) <max):
            max=(abs(i-a))
            l.append(i)
        
print(l[len(l)-1])

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
r=[i-x for i in map(int,input().split())]
for i in range(1,n+1):
  if not -(i) in r:
    print(x-i)
    break
  elif not i in r:
    print(x+i)
    break

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
r=[i-x for i in map(int,input().split())]
for i in range(1,n+1):
  if not -(i+1) in r:
    print(x-i-1)
    break
  elif not i+1 in r:
    print(x+i+1)
    break

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
r=[i-x for i in map(int,input().split())]
for i in range(100):
  if not -i in r:
    print(x-i)
  elif not i in r:
    print(x+i)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
r=[i-x for i in map(int,input().split())]
i=1
while True:
  if not -i in r:
    print(x-i)
    break
  elif not i in r:
    print(x+i)
  else:
    i+=1

Submission status: Wrong Answer

Solution code:
import sys
x,n = map(int,input().split())
check = [i for i in range(0,102)]
if n != 0:
	n = list(map(int,input().split()))
else:
    print(0)
    sys.exit()
judge = float("inf")
for j in n:
    if j in check:
        check.remove(j)
for k in check:
    judge = min(judge,abs(k-x))
pre_ans = x-judge
if pre_ans in check:
    print(pre_ans)
else:
    print(x+judge)

Submission status: Wrong Answer

Solution code:
import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))
NL = [i for i in range(-1000,1000) if i == X or i not in P]

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

idx = NL.index(X)
if abs(NL[idx + 1] - X) >= abs(NL[idx - 1] - X ):
    print(NL[idx - 1])
else:
    print(NL[idx + 1])

Submission status: Wrong Answer

Solution code:
import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))
NL = [i for i in range(-100, 1000) if i == X or i not in P]

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

idx = NL.index(X)
if abs(NL[idx + 1] - X) >= abs(NL[idx - 1] - X ):
    print(NL[idx - 1])
else:
    print(NL[idx + 1])

Submission status: Wrong Answer

Solution code:
import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))
NL = [i for i in range(0, 102) if i == X or i not in P]

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

idx = NL.index(X)
if abs(NL[idx + 1] - X) >= abs(NL[idx - 1] - X ):
    print(NL[idx - 1])
else:
    print(NL[idx + 1])

Submission status: Wrong Answer

Solution code:
import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))
NL = [i for i in range(0, 102) if i == X or i not in P]

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

idx = NL.index(X)
if abs(NL[idx + 1] - X) >= abs(X - NL[idx - 1]):
    print(NL[idx - 1])
else:
    print(NL[idx + 1])

Submission status: Wrong Answer

Solution code:
import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))
NL = [i for i in range(0, 102) if i == X or i not in P]

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

idx = NL.index(X)
if NL[idx + 1] - X >= X - NL[idx - 1]:
    print(NL[idx - 1])
else:
    print(NL[idx + 1])

Submission status: Wrong Answer

Solution code:
from sys import stdin
 
input_num = stdin.readline().strip().split(" ")

X = int(input_num[0])
N = int(input_num[1])
num_list = []
if N != 0:
    num_list = [int(x) for x in stdin.readline().strip().split(" ")]


dec_num = X
inc_num = X
if N == 0:
    print(X)
elif X not in num_list:
    print(X)
else:
    while True:
        dec_num += -1
        inc_num += 1
        if inc_num not in num_list:
            print(inc_num)
            break
        if dec_num not in num_list:
            print(dec_num)
            break

Submission status: Wrong Answer

Solution code:
from sys import stdin
 
input_num = stdin.readline().strip().split(" ")

X = int(input_num[0])
N = int(input_num[1])
num_list = []
if N != 0:
    num_list = [int(x) for x in stdin.readline().strip().split(" ")]

dec_num = X
inc_num = X
if N == 0:
    print(X)
elif X not in num_list:
    print(X)
else:
    while True:
        dec_num += -1
        inc_num += 1
        if dec_num not in num_list:
            print(dec_num)
            break
        if inc_num not in num_list:
            print(dec_num)
            break

Submission status: Wrong Answer

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

for i in range(101):
  if i in p:
    continue
  else:
    S.append(abs(i-X))

print(min(S))

Submission status: Wrong Answer

Solution code:
import sys
x,n = map(int,input().split())
check = [i for i in range(0,101)]
if n != 0:
	n = list(map(int,input().split()))
else:
    print(0)
    sys.exit()
judge = float("inf")
for j in n:
    if j in check:
        check.remove(j)
for k in check:
    judge = min(judge,abs(k-x))
pre_ans = x-judge
if pre_ans in check:
    print(pre_ans)
else:
    print(x+judge)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
 
if N == 0:
    print(X)
    exit()
 
P = list(map(int,input().split()))
    
s = sorted(P)
 
ss = []
for i in range(s[0],s[N-1]+2):
    ss.append(i)
  
result = list(set(ss) - set(s))

 
ans = []
for i in range(len(result)):
    ans.append(abs(X - result[i]))

print(result[ans.index(min(ans))])

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
for i in range(N // 2 + 3):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break
if N == 0:
    print(X)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
for i in range(N // 2 + 2):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break
if N == 0:
    print(X)

Submission status: Wrong Answer

Solution code:
import numpy as np
X,N = map(int, input().split())
if N != 0:
  p = list(map(int, input().split()))
  min_val = 0
  max_val = 102
  not_p = [i for i in range(min_val,max_val,1)]
  
  for i in range(N):
    not_p.remove(p[i])
  not_p.sort()
    
  min_val = 999
  out_num = 101
  for i in range(len(not_p)):
    if abs(X-not_p[i]) < min_val:
      min_val = abs(X-not_p[i])
      out_num = not_p[i]
  print(out_num)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
for i in range((N + 1) // 2):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break
if N == 0:
    print(X)

Submission status: Wrong Answer

Solution code:
x,n = list(map(int,input().split()))
if n >0 :
  p = list(map(int,input().split()))
y = 101
#ans = x
if n == 0:
  print(x)
else:
  for i in range(-100,102):
    if i != x:
      if p.count(i) == 0:
        #print('i=',i,abs(x-i))
        if abs(x-i) < y:
          ans = i
          y = abs(x-i)
          #print('i=',i,'abs=',abs(x-i),'ans=',ans)
  print(ans)

Submission status: Wrong Answer

Solution code:
x,n = list(map(int,input().split()))
if n >0 :
  p = list(map(int,input().split()))
y = 101
#ans = x
if n == 0:
  print(x)
else:
  for i in range(0,101):
    #if i != x:
      if p.count(i) == 0:
        #print('i=',i,abs(x-i))
        if abs(x-i) < y:
          ans = i
          y = abs(x-i)
          #print('i=',i,'abs=',abs(x-i),'ans=',ans)
  print(ans)

Submission status: Wrong Answer

Solution code:
x,n = list(map(int,input().split()))
if n >0 :
  p = list(map(int,input().split()))
y = 101
#ans = x
if n == 0:
  print(x)
else:
  for i in range(0,101):
    #if i != x:
      if p.count(i) == 0:
        print('i=',i,abs(x-i))
        if abs(x-i) < y:
          ans = i
          y = abs(x-i)
          print('i=',i,'abs=',abs(x-i),'ans=',ans)
  print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    x,n = map(int, input().split())
    p = list(map(int, input().split()))
    l = [abs(i-x) if i not in p else 102 for i in range(101)]

    ans = l.index(min(l))
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

abs_min = int(1e5)
ans = -1
for i in range(0, 102):
    if abs(x - i) < abs_min:
        abs_min = abs(x - i)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))
NL = [ i for i in range(0, 102) if i == X or i not in P ]

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

idx = NL.index(X)
if NL[idx + 1] - X >= X - NL[idx-1]:
    print(NL[idx-1])
else:
    print(NL[idx+1])

Submission status: Wrong Answer

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

min=0
dev=200

for i in range(1,102):
  if i in p or abs(x-i)>=dev:
    continue
  dev=abs(x-i)
  min=i
print(min)

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
p = [int(_) for _ in input().split()]
p.sort()
ab = 101
if not n:print(x);exit()
for i in range(n - 1):
    diff = p[i + 1] - p[i] - 1
    if diff:
        for num in range(p[i] + 1, p[i] + diff+1):
            ab = min(ab, abs(num - x))
        if p[i] <= x:
            ab *= -1
print(x+ab)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
  p2=map(lambda s:s-x,p)
a=0
i=0
if n==0:
  print(x)
else:
  while a==0:
    if i in p2:
      if i==0:
        i=-1
      elif i>0:
        i=-1*(i+1)
      else:
        i=-1*i
    else:
      print(x+i)
      a=1
      break

Submission status: Wrong Answer

Solution code:
lst = []
l = []
str = input()
l = str.split(' ')
n = int(l[0])
no = int(l[1])
if no==0:
  print(n)
 

else:  
  str1 = input()
  lst = str1.split(' ')
  for i in range(0,no):
    lst[i] = int(lst[i])
  i=1
  while True:
    if n-i not in lst:
      print(n-i)
      break
    if n+i not in lst:
      print(n+i)
      break
    i+=1

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 1000
applied = 1000
for i in range(-100,101):
    if i in p:
        pass
    else:
        dif = abs(x-i)
        if dif < ans:
            ans = dif
            applied = i
        else:
            pass
print(applied)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 1000
applied = 1000
for i in range(-100,101):
    if i in p:
        pass
    else:
        dif = abs(x-i)
        if dif < ans:
            ans = dif
            applied = i
        elif dif == ans:
            applied = min(i, applied)
        else:
            pass
print(applied)

Submission status: Wrong Answer

Solution code:
def test(X, N, p):
    list_abs = [abs(n) for n in p]
    list_abs.sort()
    list_b = [int(n) for n in range(-1*list_abs[-1], list_abs[-1])]
    list_all = list(set(p) ^ set(list_b))
    list_all = [abs(n-X) for n in list_all]
    list_all.sort()
    return X+list_all[0]


if __name__ == '__main__':
    X, N = map(int, input().split())
    if N == 0:
        print(N)
    else:
        p = [int(n) for n in input().split()]
        print(test(X, N, p))

Submission status: Wrong Answer

Solution code:
a,b = map(int, input().split())
if b>0:
	p = list(map(int, input().split()))
else:
	print(a)
	exit()

n = a
m = a

for i in range(b+1):
	"""
	print(n)
	print(m)
	print("")
	"""
	if n in p:	
		n = n-1
			
	else:
		if n > 0:
			print(n)
			exit()


	if m in p:		
		m = m+1
	else:
		print(m)
		exit()

Submission status: Wrong Answer

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

p = set(map(int, input().split()))
for i in range(101):
    if x - i not in p:
        print(x - i)
        break
    elif x + i not in p:
        print(x + i)
        break