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

candidates = list(map(lambda elm: (abs(x - elm), elm), range(101)))
for p_i in p:
    candidates[p_i] = (10000, p_i)

sorted_candidates = sorted(candidates, key=lambda elm: elm[0])
print(sorted_candidates[0][1])

Submission status: Wrong Answer

Solution code:
XN = list(map(int, input().split()))

if (XN[1] == 0):
    print(XN[0])
    exit()

P = list(map(int, input().split()))
bucket = [0] * 100
for i in range(XN[1]):
    bucket[P[i] - 1] = 1

#正方向
pcounter = 0
for i in range(XN[0], 101):
    if (i == 100):
        break
    if (bucket[i - 1] == 0):
        break
    pcounter += 1

#負方向
mcounter = 0
for i in range(XN[0], -2, -1):
    if (i == -1):
        break
    if (bucket[i - 1] == 0):
        break
    mcounter += 1


if (pcounter >= mcounter):
    print(XN[0] - mcounter)
else:
    print(XN[0] + pcounter)

Submission status: Wrong Answer

Solution code:
# fall 7, stand 8...
# !/ankit_SM/bin/env python

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def main():
    tinn=1; #tinn=int(input())
    for tin in range(tinn):
        x,n=map(int,input().split())
        a=list(map(int,input().split()))
        dic={}
        for _ in range(-101,101):
            dic[_]=0;
        for _ in range(n):
            dic[a[_]]=1;
        mn=100000; val=0;
        for _ in range(-101,101):
            if(dic[_]==0):
                if(mn>abs(x-_)):
                    mn=abs(x-_)
                    val=_
        print(val)


# region fastio
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")
def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

flag = 0
if N == 0:
    print("")
else:
    X1 = X
    X2 = X
    ans = []
    while flag ==0:
        
        if not(X1 in p):
            ans.append(X1)
            flag = 1
        if not(X2 in p):
            ans.append(X2)
            flag = 1
        if flag == 1:
            print(min(ans))
            
        else:
            X1-= 1
            X2+= 1

Submission status: Wrong Answer

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

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

  for i in range(1,100):
  #  print("-i:",p.count(x-i))
  #  print("+i:",p.count(x+i))
    if p.count(x-i) == 0:
      print(x-i)
      break
    elif p. count(x+i) == 0:
      print(x+i)
      break
else:
  print(x)

Submission status: Wrong Answer

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

arr = [0] * 1000
for i in p:
    arr[i] = 1

ans1 = 0
for i in range(x, 0, -1):
    if arr[i] == 0:
        ans1 = i
        break

#print(arr)

ans2 = 0
for i in range(x, 102):
    if arr[i] == 0:
        ans2 = i
        break

if ans1 == 0:
    print(ans2)
else:
    if abs(ans1-x) <= abs(x-ans2):
        print(ans1)
    else:
        print(ans2)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
ans = 100000000
l = 1000000
for i in range(1,101):
    if P.count(i) == 0:
        #print(i)
        if abs(i-X) < l:
            l = abs(i-X)
            ans = min(i,ans)
            #print(ans,i,l)
print(ans)

Submission status: Wrong Answer

Solution code:
l = [i for i in range(1,101)]
x,n = list(map(int,input().split()))
p = list(map(int,input().split()))

l = set(l)
p = set(p)
dif = list(l-p)
dif.sort(reverse=True)
ans_min=1000000
ans = 0
for i in dif:
    if ans_min>=abs(x-i):
        ans_min=abs(x-i)
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    X,N = map(int, input().split())
    if N==0:
        print(X)
        return 
    A = list(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    
    A.sort()
    a=A

    i=bisect_left(A,X)
    
    if i==len(A):
        print(X)
        return 
    if A[i]!=X:
        print(X)
        return
    
    j=i-1
    cur=X
    amin=0
    while j>=0:
        if abs(a[j]-cur)<2:
            cur=a[j]
            j-=1
            continue
        else:
            amin=cur-1
            break
    j=i+1
    amax=max(A)+1
    cur=X
    while j<=len(A)-1:

        if abs(a[j]-cur)<2:
            cur=a[j]
            j+=1
            continue
        else:
            amax=cur+1
            break
    
    if abs(amin-X)<=abs(amax-X):
        print(amin)
    else:
        print(amax)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
X, N = (int(s) for s in input().rstrip().split())
if N == 0:
  nums = []
else:
  nums = [int(s) for s in input().rstrip().split()]

def find(nums, X):
  if not nums:
    return X
  for i in range(1, X + 1):
    X_plus = X + i
    X_minus = X - i
    
    if X_minus not in nums:
      return X_minus
    if X_plus not in nums:
      return X_plus

print(find(nums, X))

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( 100, -100, -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())
p = list(map(int, input().split()))
ans = 101
for i in range(101):
    if not i in p:
        if abs(i-X) < abs(ans-X):
            ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
for i in range(1000):
    if n==0:
        print(x)
        break
    if x-i-1 in p:
        pass
    else:
        print(x-i-1)
        break
    if x+i+1 in p:
        pass
    else:
        print(x+i+1)
        break

Submission status: Wrong Answer

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

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

p = list(map(int, input().split(" ")))
for i in range(1, 100):
    if x - i not in p:
        print(x-i)
        break
    if x + i not in p:
        print(x+i)
        break

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = set()
if N != 0:
    p = set(map(int, input().split()))
pp = sorted(list({i for i in range(1, 101)} - p))
ans = -100
for i in pp:
    if abs(X - ans) > abs(X - i):
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
try:
  p=list(map(int,input().split()))
except:
  
  print(x)
  exit()
ans=float('inf')
for i in range(1,101):
  if i not in p:
    ans=min(ans,abs(x-i))
    
    
if x-ans in p:
  print(x+ans)
else:
  print(x-ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
if N==0:print(X); exit()
diff = float('inf')
ans = X
A = [0]*101
for p in P:
    A[p] += 1
for i in range(X,101):
    if A[i]==0:
        ans = i
        diff = i-X
        break
for i in range(X,-1,-1):
    if A[i]==0:
        if abs(X-i)<=diff:
            ans = i
            diff = abs(X-i)
        break
if abs(X+1)<= diff:
    ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
#p = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
dif = 1000
ans = 1000
for i in range(1, 101):
    if not(i in p):
        if abs(i-x) < dif:
            dif = abs(i-x)
            ans = i
        elif abs(i-x) == dif:
            if ans > i:
                ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = list(map(int,input().split()))
    K = 0
    L =0
    for i in range(X+1,100):
        if i in p:
            continue
        else:
            K = i-X
            L = i
            break
    for i in range(X-K,X):
        if i in p:
            continue
        else:
            L = i
    print(L)

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

small = x - 1
large = x + 1
while 0 < small and large < 100:
    if small not in p:
        print(small)
        break
    elif large not in p:
        print(large)
        break
    else:
        small -= 1
        large += 1

Submission status: Wrong Answer

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

ans = 0

for i in range(n):
    tmp1 = x - i
    tmp2 = x + i
    if not tmp1 in p:
        ans = tmp1
        break
    if not tmp2 in p:
        ans = tmp2
        break

print(ans)

Submission status: Wrong Answer

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

if n != 0:
  p = list(map(int, input().split()))
  lists = []
  for i in range(0, 101):
    if i in p:
      continue
    lists.append(i)

  ans = lists[0]
  mins = abs(lists[0] - x)
  for i in range(1, len(lists)):
    dist = abs(lists[i]-x)
    if mins > dist:
      ans = lists[i]
      mins = dist
      
  print(ans)
else:
  print(x)

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    ps = list(map(int, input().split()))
    anti_ps = [i for i in range(101) if i not in ps]
    anti_ps_abs = [abs(i-x) for i in range(101) if i not in ps]
    ans = anti_ps[anti_ps_abs.index(min(anti_ps_abs))]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    p.sort()
    trgt = x
    roop_flg = True
    a = 1
    while roop_flg:
        if trgt not in p:
            break
        else:
            if a > 0:
                trgt = trgt -a
                a = -(a+1)
            else:
                trgt = trgt -a
                a = -(a+1)


    print(trgt)

Submission status: Wrong Answer

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

for i in range(1,102):
    if not i in p:
        p2.append(i)

p3 = p2[::-1]
Ans = X
sa = 1000
for j in range(len(p3)):
    if abs(p3[j]-X) <= sa:
        sa = abs(p3[j]-X)
        Ans = p3[j]

print(Ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import numpy as np

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]



X,N = map(int, input().split())
if N==0:
    print(X)
    quit()
PList=list(map(int, input().split()))
#Xに近い物
List=[]
for k in range(101):
    List.append(k)
#print(List)

i=0
while i<N:
    if PList[i] in List:
        List[List.index(PList[i])]=100000
    i+=1

#print(List)

print(getNearestValue(List,X))

Submission status: Wrong Answer

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

ans = x

min_num = x
for i in range(-200,301):
    if p.count(i) == 0:
        if min_num > abs(x-i):
            min_num = abs(x-i)
            ans = i

print(ans)

Submission status: Wrong Answer

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

listP.sort()

minD = 100
val = -1
bef = None
for p in listP:
    if bef == None:
        bef = p
    else:
        if p-1 == bef:
            pass
        else:
            if bef < x < p:
                val = x
            elif x <= bef:
                if abs(bef+1-x) < minD:
                    minD = abs(bef+1-x)
                    val = bef+1
            else:
                if abs(p-1-x) < minD:
                    minD = abs(p-1-x)
                    val = p-1
        bef = p
if not x in listP:
    val = x
elif val == -1:
    if abs(0-x) > abs(101-x):
        val = 101
    else:
        val = 0

print(val)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

#S = input()
#N = int(input())
#n = [list(map(int,input().split())) for i in range(N)]
#n, y = map(int, input().split())

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

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

r = 999
for _p in range(101):
    if _p in p:
        continue
#    print(_p)
    if (abs(_p - X) < abs(r-X)):
        r = _p


print(r)

Submission status: Wrong Answer

Solution code:
import itertools
import decimal
import math
import collections
import sys
input = sys.stdin.readline

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

if(N==0):
    ans=X
else:
    ListP=list(map(int,input().split()))

    min = 999999
    for i in range(-101,101):
        if(min > abs(X-i)):
            if(i not in ListP):
                min=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()))

ans = 0
m = float("inf")
for i in range(101):
    if i not in p:
        if abs(i-x) < m:
            ans = i
            m = abs(i-x)

print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N ==0:
  print(X)
else:
  List = list(map(int, input().split()))
  res = 0
  for i in range(1,101):
    med_p = X+i
    med_n = X-i
    Flag_p = False
    Flag_n = False
    for j in range(N):
      if List[j] == med_p:
        Flag_p = True
      elif List[j] == med_n:
        Flag_n = True
      else:
        pass
    if Flag_p and Flag_n:
      pass
    elif not Flag_p and Flag_n:
      res = med_p
      break
    elif Flag_p and not Flag_n:
      res = med_n
      break
    else:
      res = med_n
      break
  print(res)

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(101):
        if item not in p and abs(item - x) < best_diff:
            best_diff = abs(item - x)
            best = item
        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:
X, N = map(int, input().split())

exist = [False] * 101
p = list(map(int, input().split()))

for i in range(N):
    exist[p[i]] = True

for i in range(200):
    if X - i <= 0:
        print(X-i)
        exit()

    if X + i > 100:
        print(X+i)
        exit()

    if not exist[max(1, X-i)]:
        print(X-i)
        exit()

    if not exist[min(X+i, 100)]:
        print(X+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()))
  i=-1
  for j in range(101):
    if abs(X-j)<abs(X-i) and not(j in p):
      i=j
  print(i)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

X, N = list(map(int, input().split(' ')))
ps = input()
if len(ps)!=0:
    ps = list(map(int, ps.split(' ')))

ps_sort = list(sorted(ps))
not_in_ps = np.array([[abs(i-X), i] for i in range(101) if i not in ps_sort])
print(not_in_ps[np.argmin(not_in_ps[:,0], 0), 1])

Submission status: Wrong Answer

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

X, N = MAP()
p = LIST()

ans = 0
min_num = float("INF")
for i in range(1, 102):
    if i in p:
        continue
    
    if min_num > abs(X-i):
        min_num = abs(X-i)
        ans = i


print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P=sorted(list(map(int,input().split())))
t=0
for i in range(1,101):
    if i not in P:
        if abs(X-t)>abs(X-i):
            t=i
print(t)

Submission status: Wrong Answer

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

min_p = 100
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:
X,N = map(int,input().split())
P = list(map(int,input().split()))
ans = 100000000
l = 1000000
for i in range(1,101):
    if P.count(i) == 0:
        #print(i)
        if abs(i-X) < l:
            l = abs(i-X)
            ans = i
            #print(ans,i,l)
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
l = []
if len(p) == 0:
    print(X)
    exit()
for i in range(-100, max(p)):
    if not i in p:
        l.append(i)

ans_n = 100
ans = 0
for i in range(len(l)):
    if ans_n > abs(X-l[i]):
        ans_n = abs(X-l[i])
        ans = l[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd, cos, radians, floor
from functools import lru_cache, reduce
from decimal import Decimal
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
x, n = map(int, input().split())
y = [0 for i in range(100)]
p = list(map(int, input().split()))
# print("y =", y)
for i in p:
    y[i - 1] = 1
# print("y =", y)
ans = 0
gap = x
for i in range(100):
    if y[i] == 1:
        continue
    # if i == 7:
        # print(abs(x - i - 1))
    if abs(x - i - 1) < gap:
        ans = i + 1
        gap = abs(x - i - 1)
        # print(gap)
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
q = set(range(-100, 100))
r = list(q - set(p))
r.sort()
max = 1000
ans = X

if N == 0:
    print(X)
else:
    for i in r:
        if abs(X - i) < max:
            max = abs(X - i)
            ans = i

    print(ans)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
a=0
s=0
if y/x>=2:
    for i in range(x+1):
        for k in range(x-i+1):
            a=4*i+2*k

            if a==y:
                s+=1
else:pass

if s>=1:
    print("Yes")

else:
    print("No")

Submission status: Wrong Answer

Solution code:
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    x,n = invr()
    a = inlt()
    a.sort()
    if x not in a:
        print(x)
        return
    q = []
    for i in range(len(a)):
        q.append(abs(x - a[i]))
    q.sort()
    w = counter(q)
    qw = -1
    for i in range(1,len(a)):
        if q[i] - q[i - 1] > 1:
            qw = q[i - 1] + 1
            break
        if w[q[i]] == 1:
            qw = q[i]
            break
    if qw != -1:
        if x + qw in a:
            print(x - qw)
        else:
            print(x + qw)
    else:
        print(x + max(q) + 1)
            
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * (max(a) + 1)
    for i in range(len(a)):
        q[a[i]] = q[a[i]] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

def power_two(n):
    if n == 1:
        return(True)
    sttr = str(n)
    len_str = len(sttr)
    sttr = list(sttr)
    num = 0
    if (len_str == 1 and sttr[len_str - 1] == '1'): 
        return(False)
    while (len_str != 1 or sttr[len_str - 1] != '1'):
        if ((ord(sttr[len_str - 1]) - ord('0')) % 2 == 1):
            return(False)
        j = 0; 
        for i in range(len_str):  
            num = num * 10 + (ord(sttr[i]) - ord('0')); 
            if (num < 2): 
                if (i != 0):  
                    sttr[j] = '0'
                    j += 1
                continue
  
            sttr[j] = chr((num // 2) + ord('0'))
            j += 1; 
            num = (num) - (num // 2) * 2
        len_str = j
    return(True)

def getLeftmostBit(n): 
    m = 0
    while (n > 1) : 
        n = n >> 1
        m += 1
    return(m)
def getNextLeftmostBit(n, m) : 
    temp = 1 << m 
    while (n < temp) : 
        temp = temp >> 1
        m -= 1
    return m
def bitcounter(n) :
    m = getLeftmostBit(n) 
    return _countSetBits(n, m) 
def _countSetBits(n, m) :
    if (n == 0) : 
        return 0
    m = getNextLeftmostBit(n, m)
    if (n == (1 << (m + 1)) - 1) : 
        return ((m + 1) * (1 << m))
    n = n - (1 << m)
    return (n + 1) + bitcounter(n) + m * (1 << (m - 1)) 

def log_two(n): 
    return(math.log(n) / math.log(2))

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

num=[i for i in range(1,101)]
for i in p:
    num[i-1]=0

num.sort()
# print(num)
min=1000
for i in num:
    if min>abs(x-i):
        min=abs(x-i)
        ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
XN = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
tmp=100
tmp_i=0
for i in range(101):
  if not i in p:
    if abs(XN[0]-i)<tmp:
      tmp=abs(XN[0]-i)
      tmp_i=i
print(tmp_i)

"""
10 5
4 7 10 6 5
"""

Submission status: Wrong Answer

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

    c=0
    for i in range(N):
        if X-c not in A:
            print(X-c)
            break
        if X+c not in A:
            print(X+c)
            break
        c += 1
else:
    print(X)