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())
*P, = map(int, input().split())
cand = set(range(101)) - set(P)
cand = sorted([c for c in cand], key=lambda x: (abs(X - x), x))
print(cand[0])

Submission status: Wrong Answer

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

minimum = 9999999999999999999999999999
i = None
for x in range(0, 101):
    if x in p:
        continue

    if minimum > abs(X - x):
        minimum = abs(X - x)
        i = x

print(i)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n>0:
    p=list(map(int,input().split()))
    p=set(p)
    mini=10**10
    ans=0
    for i in range(101):
        if i not in p:
            if abs(i-x)<mini:
                mini=abs(i-x)
                ans=i
    print(ans)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
ab = min(abs(101 - x),abs(x+1))
if abs(101 - x) >= abs(x+1):
    answer = -1
else:
    answer = 101
for i in range(1,101):
    if i in p:
        continue
    else:
        if ab > abs(x - i):
            ab = abs(x - i)
            answer = i
print(answer)

Submission status: Wrong Answer

Solution code:
INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

X, N = map(int, input().split())
P = set(map(int, input().split()))

S = set([i for i in range(0, 101)])
S = S - P

ans = -1
diff = INF
for s in sorted(S):
    if abs(s - X) < diff:
        ans = s
        diff = abs(s - X)

print(ans)

Submission status: Wrong Answer

Solution code:
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input())):
x,n=map(int,input().split())
if n!=0:
	p=[int(x) for x in input().split()]
if n==0:
	print(x)
else:
	diff=500
	ans=0
	for i in range(1,101):
		if i not in p:
			if diff>abs(x-i):
				diff=abs(x-i)
				ans=i
	print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X, N = map( int, input().split() )
if N > 0:
  P = sorted( list( map( int, input().split() ) ))
  ret = -1
  dis = 10 ** 18
  for i in range( min( P ), max( P ) + 1 ):
    if i in P:
      continue
    if dis - abs( i - X ) > 0:
      ret = i
      dis = abs( i - X )
else:
  ret = X
print( ret )

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
P = [int(i) for i in input().split()]
m = float("inf")
ans = 0
l = set(range(-100, 100)) - set(P)
for p in l:
    d = abs(p-X)

    if d < m:
        m = d
        ans = p

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if x in p:
    ans = None
    for i in range(1, max(x, 100 - x)):
        for j in [-1, 1]:
            if x + i * j not in p:
                ans = x + i * j
                break
        if ans is not None:
            break
    print(ans)

else:
    print(x)

Submission status: Wrong Answer

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

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

cnt = [0] *101
ans1 = 0
ans2 = 0

for _p in p:
    cnt[_p] += 1

for i in range(x, 100):
    if cnt[i] == 0:
        ans1 = i
        break

for i in range(1, x):
    if cnt[i] == 0:
        ans2 = max(ans2, i)

if abs(ans1 - x) < abs(ans2 - x):
    print(ans1)
elif abs(ans1 - x) >= abs(ans2 - x):
    print(ans2)

Submission status: Wrong Answer

Solution code:
def resolve():
    X, N = [int(i) for i in input().split()]
    if N == 0:
        print(X)
        return
    P = sorted([int(i) for i in input().split()])
    if X not in P:
        print(X)
    for i in range(N // 2 + 1):
        if (X - i) not in P:
            print(X - i)
            return
        if (X + i) not in P:
            print(X + i)
            return


resolve()

Submission status: Wrong Answer

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

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

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

ans = 0
for i in range(101):
    if i in a:
        continue
    if abs(x-ans) > abs(x-i):
        ans = i
        
if ans != 0:
    print(ans)
else:
    print(0 if x <= 50 else 100)

Submission status: Wrong Answer

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

min_p = float('inf')
for i in range(1,101):
    if not (i in p):
        min_p = min(min_p, abs(i-x))

if not (x-min_p in p):
    print(x-min_p)
else:
    print(x+min_p)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
it = lambda: list(map(int, input().strip().split()))
INF = float('inf')

def solve():
    X, N = it()
    arr = it()
    res = [False] * 101
    for i in range(N):
        res[arr[i]] = True
    
    i = X
    j = X
    while i >= 0 and j <= 100:
        if not res[i]:
            return i
        elif not res[j]:
            return j
        i -= 1
        j += 1
    if i == -1:
        return 0
    elif j == 101:
        return 101

if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
x, n  = map(int, input().split())
p  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

li = []
for i in range(1, 1001):
    if not i in p:
        li.append(i)

ans = 1000
min_ = 1000
for i, l in enumerate(li[::-1]):
    if min_ >= abs(x - l):
        min_ = abs(x - l)
        ans = l

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  lst=sorted(map(int,input().split()))
  dis=200
  ans=100
  for i in range(100):
    temp=abs(x-i)
    if temp<dis and i not in lst:
      dis=temp
      ans=i
  print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
lst = list(map(int, input().split()))
num = []
for i in range(101):
  num.append(-i)
for i in range(101):
  if not i in lst:
    num.append(i)

dis = 10000
ans = num[0]
for p in num:
  if abs(p-x) < dis:
    dis = abs(p-x)
    ans = p
  elif abs(p-x) == dis and p < ans:
    ans = p
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    X, N = map(int, readline().split())
    P = list(map(int, readline().split()))
    A = 0
    B = 0
    for a in range(X,102):
        if not a in P:
            A = a
            break

    for b in range(X,-1,-1):
        if not b in P:
            B = b
            break

    if abs(X-A)<=abs(X-B):
        print(A)
    else:
        print(B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
a=[]
for i in range(-100,101):
    if not i in p:
        a.append(i)

for i in range(101):
    if (x-i) in a:
        ans=x-i
        break
    elif (x+i) in a:
        ans=x+i
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

x,n = na()
p = na()
q = [i for i in range(100) if i not in p]
r = []

for i in range(len(q)):
    r.append(abs(q[i]-x))

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

k = min(r)
if x-k in q:
    print(x-k)
else:
    print(x+k)

Submission status: Wrong Answer

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

p_list_raw = input()
if p_list_raw == "":
    print(X)
else:
    p_list = [int(_c) for _c in p_list_raw.split(" ")]

    ans = -1
    for i in range(101):
        target = X - i
        if target > 0 and target < 100:
            if target not in p_list:
                ans = target
                break
        target = X + i
        if target > 0 and target < 100:
            if target not in p_list:
                ans = target
                break

    print(ans)

Submission status: Wrong Answer

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

pinv=[True for i in range(101)]

for i in p:
    pinv[i]=False

ab=100
ans=0
for i in range(-100,101):
    if (i<0 or pinv[i]) and abs(x-i)<ab:
        ab=abs(x-i)
        ans=i

print(ans)

Submission status: Wrong Answer

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

li = []
for i in range(1, 101):
    if i not in P:
        li.append(i)

ans = -1
minimum_num = 100

for n in li:
    num = abs(n - X)
    if num < minimum_num:
        minimum_num = num
        ans = n

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
A=set(map(int,input().split()))
for i in range(100):
  if x+i not in A:
    a=x+i
    break
for i in range(100):
  if x-i not in A:
    b=x-i
    break

if abs(a-x)>abs(x-b):
  print(b)
else:
  print(a)

Submission status: Wrong Answer

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

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

    mi = 200
    for i in range(102):
        if not i in p:
            d1 = abs(x-i)
            if d1<mi and d1!=0:
                ans = i
                mi = min(d1,mi)
    print(ans)

Submission status: Wrong Answer

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

for i in range(1,201):
    if not i in p:
        if abs(x-i)<s:
            # print(i,abs(x-i))
            s = abs(x-i)
            t=i
print(t)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def solve(x, n, p):
    p = set(p)
    best = None
    best_diff = float("inf")
    for item in range(1, 101):
        if item in p:
            continue
        if abs(item - x) < best_diff:
            best_diff = abs(item - x)
            best = item
    return best


if __name__ == "__main__":
    x, n = arr_in()
    if n == 0:
        out(x)
        exit()
    p = arr_in()
    out(solve(x, n, p))

Submission status: Wrong Answer

Solution code:
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())


# for _ in range(ii()):
    
x,n=mi()
if n==0:
    print(x)
    exit(0)
a=li()
y=[]
for i in range(x,0,-1):
    if i not in a:
        y.append(i)
        break
for i in range(x,102):
    if i not in a:
        y.append(i)
        break
if len(y)==1:
    print(y[0])
else:
    if abs(y[0]-x)<abs(y[1]-x):
        print(y[0])
    elif(abs(y[0]-x)==abs(y[1]-x)):
        print(min(y))
    else:
        print(y[1])

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=sorted(p)
c=0
z=0
a=[]
for i in range(n):
    a.append(p[i]-x)
for i in range(50):
    if a.count(-i)==0:
        z=-c
        break
    elif a.count(i)==0:
        z=c
        break
    else:
        c+=1
print(x+z)

Submission status: Wrong Answer

Solution code:
def main(X, N, P):
    st = set(P)
    if N == 0:
        print(X)
    else:
        for n in range(N):
            if X - n not in st:
                print(X - n)
                exit()
            elif X + n not in st:
                print(X + n)
                exit()

if __name__ == '__main__':
    X, N = list(map(int, input().split()))
    P = list(map(int, input().split()))
    main(X, N, P)

Submission status: Wrong Answer

Solution code:
import sys

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

if(len(arr) == 0):
    print(x)
    sys.exit()

i = 1
while True:
    if(not (x - i in arr)):
        print(x - i)
        sys.exit()
    
    if(not (x + i in arr)):
        print(x + i)
        sys.exit()
    i += 1

Submission status: Wrong Answer

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

a = [i for i in range(1, 1000)]
b = [-i for i in range(1, 1000)]
c = []
for idx in range(len(a)):
    c.append(a[idx])
    c.append(b[idx])
c.append(0)
tmp = []
for i in c:
    if not i in p:
        tmp.append([abs(X-i), i])
tmp2 = [10000000000, -1]
for i in tmp:
    if tmp2[0] > i[0]:
        tmp2[0] = i[0]
        tmp2[1] = i[1]

print(tmp2[1])

Submission status: Wrong Answer

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

ans=-1
sa=1000
for i in range(-1,101):
    if p.count(i)>=1:
        continue
    else:
        if abs(i-x)<sa:
            ans=i
            sa=abs(i-x)

print(ans)

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()))
    li = [i for i in range(1, 101) if i not in p]
    li.sort(reverse = True)

    tmp1 = float('inf')
    ans = float('inf')

    for i in li:
        if abs(i - x) <= tmp1:
            if i < ans:
                ans = i
                tmp1 = abs(i - x)

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
x,n = map(int,input().split())
ls = list(map(int,input().split()))
p = float("inf")
s = 0
if n == 0:
    print(x)
    sys.exit()
for i in range(max(ls)+1):
    if i in ls:
        continue
    k = abs(x-i)
    if k < p:
        p = k
        s = i
print(s)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
a=[int(i) for i in input().split()]
ans=float("inf")
anss=0
for i in range(1,101):
    if i not in a:
        if abs(x-i)<ans:
            ans=abs(x-i)
            anss=i
print(anss)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
if y==0:
    print(x)
    exit(0)
s=list(map(int,input().split()))
res=100
mn=110
for n in range(1,110):
    if n not in s:
        v=abs(x-n)
        if v<res:
            res=v
            mn=n

print(mn)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
a = [i for i in range(1, 101)]
for P in p:
    a.remove(P)

ans = 101
d = 10000
for A in a:
    if d > abs(A-X):
        ans = A
        d = abs(A-X)


print(ans)

Submission status: Wrong Answer

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

ans = 300

for i in range(-100, 101):
    if i not in p:
        if abs(ans - x) > abs(i - x):
            ans = i

print(ans)

Submission status: Wrong Answer

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

p_s.sort()
ans = 0
tmp_diff = float('inf')

for num in range(1,200):
    if(num not in p_s):
        diff = abs(X - num)
        if (diff < tmp_diff):
            ans = num
            tmp_diff = diff
            
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    P.sort()
    if not (X in P):
        print(X)
        exit() 
    ans = 101
    value = -1
    for i in range(-101,101):
        if i in P:
            continue
        if ans > abs(X - i):
            ans = abs(X-i)
            value = i

    print(value)
            




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
6 5
4 7 10 6 5
'''

def solve(l,x,n):
	n = len(l)
	diff,ans = maxsize,0
	for i in range(101):
		if(i not in l and abs(i-x) < diff):
			diff = abs(i-x)
			ans = i
	return ans
	

X,N = map(int, input().split())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l,X,N)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = float("inf")
for i in range(-101, 101):
    if ans > abs(i - x) and not (i in p):
        ans = abs(i - x)
        a = i
print(a)

Submission status: Wrong Answer

Solution code:
import bisect
x,n = map(int, input().split())
if (n==0):
    print(x)
    exit()
p = list(map(int, input().split()))
a = []
for i in range(101):
    if (i in p):
        continue
    a.append(i)
#print(a)


z = bisect.bisect_left(a,x)
if (z==0):
    print(a[0])
    exit()
elif (z==len(a)):
    print(a[-1])
    exit()
a1 = a[z]
a2 = a[z-1]
if (abs(a1-x) < abs(a2-x)):
    print(a1)
else:
    print(a2)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

not_inc = []

for i in range(100):
  if i not in P:
    not_inc.append(i)

not_inc_gap = [abs(not_inc[i] - X) for i in range(len(not_inc))]

index = np.argmin(not_inc_gap)

if len(P) == 0:
  print(X)
else:
  print(not_inc[index])

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
List=list(map(int,input().split()))
num=list(range(1,101))
min_num=0
for i in range(len(List)):
    if num.count(List[i])>=1:
        num.remove(List[i])
for i in range(len(num)):
    if abs(num[i]-x)<abs(min_num-x):
        min_num=num[i]
print(min_num)

Submission status: Wrong Answer

Solution code:
def LI():return list(map(int,input().split()))
def MI():return map(int,open(0).read().split())
def I():return int(input())
def yes():print("Yes")
def no():print("No")

from collections import deque, Counter
from heapq import heappop, heappush
INF=float("inf")
# import math
# pi=math.pi

# import numpy as np
x,n=LI()
if n==0:
    print(x)
    exit()
p=LI()
p.sort()

# print(p)

ans=-1
tmp=INF
for i in range(0,100+2):
    if i in p:continue
    k=abs(i-x)
    if k<tmp:
        tmp=k
        ans=i

Submission status: Wrong Answer

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

ans = 10000
idx = 0
for i in range(1, 101):
    if(abs(X-i) < ans):
        if(i not in pp):
            ans = X-i
            idx = i
print(idx)

Submission status: Wrong Answer

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

i = 1
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())

if n == 0:
    print(100)
    exit()
    
else:
    p = list(map(int, input().split()))
    li = [i for i in range(1, 101) if i not in p]
    li.sort(reverse = True)

    tmp1 = float('inf')
    ans = float('inf')

    for i in li:
        if abs(i - x) <= tmp1:
            if i < ans:
                ans = i
                tmp1 = abs(i - x)

    print(ans)

Submission status: Wrong Answer

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

p_all = set(range(1, 101)) - set(p)
# print(p_all)

mi = float('inf')
ans = 0
for i in p_all:
    if abs(x - i) < mi:
        mi = abs(x - i)
        ans = i

print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

x,N = IL()
a = IL()
a.sort()

ans = [MAX_INT, 0]

for i in range(-200, 101):
  if i not in a:
    if ans[0] > abs(i - x):
      ans = [abs(i - x), i]

print(ans[1])

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

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

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

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

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

if N == 100:
    if 0 <= X <= 50:
        print(0)
    elif 51 <= X <= 100:
        print(101)
    else:
        print(X)
    exit()


DIFF = 101
ans = 101

for p in range(1,101):
    if p in P:
        continue

    d = abs(X - p)

    if d == DIFF:
        ans = min(p, ans)
    elif d < DIFF:
        DIFF = d
        ans = p

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=input().split()
x=int(x)
n=int(n)
p=list(map(int,input().split()))
if(n==0):
    print(x)
    exit()
i=1
while(True):
    x_r=x+i
    x_l=x-i

    if(x_l not in p):
        a=x_l
        break
    if(x_r not in p):
        a=x_r
        break

    i+=1


print(a)

Submission status: Wrong Answer

Solution code:
INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

X, N = map(int, input().split())
P = set(map(int, input().split()))

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

ans = -1
diff = INF
for s in sorted(S):
    if abs(s - X) < diff:
        ans = s
        diff = abs(s - X)

print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
P = [int(i) for i in input().split()]
m = float("inf")
ans = 0
l = set(range(1, 100)) - set(P)
for p in l:
    d = abs(p-X)

    if d < m:
        m = d
        ans = p

print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
p = list(map(int,input().split()))
t = list(range(1,101))
u = set(t)-set(p)
u = list(u)
dif = 2**60
ans = 0
if not u:
    print(0)
else:
    for a in u:
        if dif > abs(a-x):
            dif = abs(a-x)
            ans = a
        elif dif == abs(a-x):
            if ans > a:
                ans = a
    print(ans)

Submission status: Wrong Answer

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

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

if n != 0:
    P = list(map(int, input().split()))

bl = False
i = 1
while not bl:
    if (x - i) not in P:
        print(x - i)
        exit()
    if (x + i) not in P:
        print(x + i)
        exit()
    i += 1

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
  print(X)
  exit()
p = list(map(int, input().split()))
ans = -float('inf')
d = float('inf')
for i in range(-10, 101):
  if i not in p:
    if abs(X-i) < d:
      d = abs(X-i)
      ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
x, n  = map(int, input().split())
p  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

li = []
for i in range(1, 101):
    if not i in p:
        li.append(i)

ans = 1000
min_ = 1000
for i, l in enumerate(li[::-1]):
    if min_ >= abs(x - l):
        min_ = abs(x - l)
        ans = l

print(ans)

Submission status: Wrong Answer

Solution code:
###################################################
#                                                 #
#   author: raghav_0901 (Raghav Dalmia)           #
#   updated on: Sunday, 14-06-2020, 17:41:34 pm   #
#                                                 #
###################################################

from math import *


def _in():
    return [int(x) for x in input().split(' ')]


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

    diff = 1
    while(True):
        l = x - diff
        if not(l in arr):
            print(l)
            return
        r = x + diff
        if not(r in arr):
            print(r)
            return
        diff = diff + 1


if __name__ == "__main__":
    tt = 1
    # tt = int(input())
    for _ in range(tt):
        main()

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
X,N = map(int,input().split())
if N == 0:
    print(X)
else:

    d = defaultdict(int)
    p = list(map(int,input().split()))
    for i in range(N):
        d[p[i]] += 1
    mmin = 0
    Mmin = 0
    for i in range(X):
        if d[i] == 0:
            mmin = i
    for i in range(X,103):
        if d[i] == 0:
            Mmin = i
            break
    a = X-mmin
    b = Mmin-X
    if a == b:
        print(mmin)
    else:
        print(Mmin)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    X, N = map(int, input().split())
    p = set(list(map(int, input().split())))
    table = set()
    for i in range(1, 101):
        table.add(i)
    table = table - p
    lis = list(table)
    ans = -1
    diff = 10 ** 9
    for i, a in enumerate(lis):
        if abs(a-X) < diff:
            diff = abs(a-X)
            ans = a
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

diff = 10**10
ans = -1
for p in range(1,101):
    if p in P:
        continue
    if abs(X-p) < diff:
        diff = abs(X-p)
        ans = p
print (ans)

Submission status: Wrong Answer

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

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	x, n = map(int, sys.stdin.readline().split())
	p = list(map(int, sys.stdin.readline().split()))
	p.sort()
	a = [0]*100
	if n == 0:
		print(x)
		exit()
	for i in range(n):
		a[p[i]-1] = 1
	i = x - 1
	log.print(p, i)
	while i >= 0:
		log.print(i, a[i])
		if i < p[0]:
			break
		if a[i] == 0:
			print(i+1)
			exit()
		i -= 1
	i = x - 1
	while i < 100:
		log.print(i, a[i])
		if i > p[-1]:
			break
		if a[i] == 0:
			print(i+1)
			exit()
		i += 1


main()

Submission status: Wrong Answer

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

sa = float("inf")
ans = 0
for i in range(100, 0, -1):
    if sa >= abs(x - i) and (i not in p):
        ans = i
        sa = abs(x - i)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    P.sort()
    if not (X in P):
        print(X)
        exit() 
    ans = 101
    value = -1
    for i in range(-101,101):
        if i in P:
            continue
        print(i, abs(X-i))
        if ans > abs(X - i):
            ans = abs(X-i)
            value = i

    print(value)
            




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

is_exit = [False] * 101

for p in P:
    is_exit[p] = True

if not is_exit[X]:
    print(X)
else:
    l = X - 1
    r = X + 1
    while 1 <= l and r <= 100:
        if not is_exit[l]:
            print(l)
            exit()
        if not is_exit[r]:
            print(r)
            exit()
        l -= 1
        r += 1

Submission status: Wrong Answer

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

A=set(map(int,input().split()))
for i in range(100):
  if x+i not in A:
    a=x+i
    break
for i in range(100):
  if x-i not in A:
    b=x-i
    break

if abs(a-x)>abs(x-b):
  print(b)
else:
  print(a)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
s=sorted(list(map(int, input().split())))
a=x
b=x
if n==0:
    print(x)
    exit()
for i in range(n):
    if not (a in s):
        print(a)
        exit()
    if not (b in s):
        print(b)
        exit()
    a-=1
    b+=1