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())
l = list(map(int, input().split()))
min_abs = 51
ans = 0
for i in range(max(X, N)+2):
    if i in l:
        continue
    if abs(i - X) < min_abs:
        min_abs = abs(i - X)
        ans = i
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()))


tmp=1000
for i in range(101):
	if i in p:
		continue
	if tmp>abs(X-i):
		ans=i
		tmp=abs(X-i)
print(ans)

Submission status: Wrong Answer

Solution code:
l = [i for i in range(-100,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:
x, n = map(int,input().split())
if n != 0:
  p = list(map(int,input().split()))
  p.sort()
else:
  p = []
  print(x)

for i in range(n):
  if p.count(x - i) == 0 or p.count(x + i) == 0:
    if p.count(x - i) == 0:
      print(x - i)
    else:
      print(x + i)
    break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num, n = map(int,input().split())
givenlist = set(list(map(int,input().split())))
numlist = set([i for i in range(101)]) - givenlist
min = 1000
answer = []
for i in numlist:
    if abs(num-i) <= min:
        min = abs(num-i)

if num - min in numlist:
    print(num - min)
else:
    print(num + min)

Submission status: Wrong Answer

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

ans = 0
j = 0 
for i in range(101):
    if j != n and p[j] == i:
        j += 1
        continue
    if abs(i - x) < abs(ans - x):
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
if b == 0:
    print(a)
else:
    c = list(map(int,input().split()))
    for i in range(1,b+1):
        if (a-i not in c) or (a+i not in c):
            if a -i in c:
                print(a-i)
                break
            else:
                print(a+i)
                break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
try:
  lst = list(map(int, input().split()))
except:
  lst = []
  
if x not in lst or lst == []:
  print(x)
else:
  for _ in range(1, 101):
    mx = max(x - _, 0)    
    mn = min(x + _, 100)
    if mx not in lst:
      print(mx)
      break
    elif mn not in lst:
      print(mn)
      break

Submission status: Wrong Answer

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

anskouho = []
if p:
    val = []
    for i in range(101):
        if i not in p:
            anskouho.append(i)
    for i in anskouho:
        val.append(abs(x - i))
    if x - min(val) not in p:
        print(x - min(val))
    else:
        print(x + min(val))
else:
    print(x)

Submission status: Wrong Answer

Solution code:
lst1 = input().split()
lst2 = input().split()

first = int(lst1[0])
now = 0
plm = 1
flag = 0
while flag == 0:
    if plm == -1:
        plm = 1
    else:
        now += 1
        plm = -1
    for i in lst2:
        if first+now*plm == int(i):
            break
        flag = 1
print(first+now*plm)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split( ))
x = set(list(map(int,input().split( ))))
all_num_plus = {i for i in range(1,101)}
all_num_minus = {-i for i in range(0,101)}
all_num = all_num_plus | all_num_minus
ans = 1000
ans_num = 1000
for i in list(all_num - x):
    if abs(X - i) < ans_num:
        ans_num = abs(X-i)
        ans = i
    elif abs(X-i) == ans_num and i < ans :
        ans_num = abs(X-i)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:

X,N=map(int,input().split())
if X>=51:
    ans=101
else:
    ans=0
p=list(map(int,input().split()))
for i in range(102):
    if i in p:
        p.remove(i)
    else:
        p.append(i)
for i in range(102-N):
    if abs(X-p[i])<abs(X-ans):
        ans=p[i]
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
ps = list(map(int, input().split()))
anss = [101] * 100

for i in range(100):
  if (i+1 not in ps):
    anss[i] = abs(x - (i+1))
m = min(anss)

for i, ans in enumerate(anss):
  if ans == m:
    print(i+1)
    exit()

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 == 101):
        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:
x,n = map(int,input().split())
p = list(map(int,input().split()))
min_num = 1000
num = 1000
for i in range(101):
    if i not in p:
        if abs(x-i) == min_num:
            if i < num:
                num = i
        elif abs(x-i) < min_num:
            min_num = abs(x-i)
            num = i
print(num)

Submission status: Wrong Answer

Solution code:
import sys
X, N = map(int, input().split())
if (N==0):
    print(100)
    sys.exit()
p = list(map(int, input().split()))

n_ans = 1
sa = 100
for k in range(1,100,1):
    if (k in p):
        continue
    if(abs(k-X) < sa):
        n_ans = k
        sa = abs(k-X)
    else:
        break
print(n_ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
tip = 0
for i in range(N):
    s = X - i
    t = X + i
    s_a = s not in p
    t_a = t not in p
    if tip == 0:
        if s_a:
            ans = s
            tip = 1
        elif t_a:
            ans = t
            tip = 1
if tip == 0:
    ans = X
print(ans)

Submission status: Wrong Answer

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

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

for i in range(1, 200):
    if (x - i) not in p:
        print(x - i)
        exit()
    if (x + i) not in p:
        print(x + i)
        exit()

Submission status: Wrong Answer

Solution code:
import numpy as np

X, N = list(map(int, input().split()))
p_list = set(sorted(list(map(int, input().split()))))

if N == 0:
  print(X)
  exit()
  
i = list(set(range(X-N, X+1)) - p_list)[-1]
j = list(set(range(X, X+N+1)) - p_list)[0]

if X-i <= j-X:
  print(i)
else:
  print(j)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    Ps = {}
    print(X)
    exit()
else:
    Ps = set(list(map(int, input().split())))

all_numbers = set(list(range(1, 101)))

search_numbers = list(all_numbers - Ps)

absolute_value = 1000
out = X
for i in search_numbers:
    if abs(i - X) < absolute_value:
        absolute_value = abs(i - X)
        out = i

print(out)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
ans=0
m=100
for i in range(100):
    if m>(i+1)-X and (not i+1 in p):
        ans=i+1
        m=abs((i+1)-X)
print(ans)

Submission status: Wrong Answer

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

listP.sort()

minD = 200
val = 0
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 == 0:
    if abs(0-x) > abs(101-x):
        val = 101
    else:
        val = 0

print(val)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    x, n = map(int, readline().split())
    p = list(map(int, readline().split()))
    p.sort()
    check = float('inf')
    ans = 0
    for i in range(101):
        if i not in p:
            if check > abs(x - i):
                ans = i
                check = abs(x - i)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

abs_min=10**10
ans = ''
for p in [_ for _ in range(-101,101) if _ not in P]:
    if abs_min > abs(X-p) :
        ans = p
        abs_min = abs(X-p)
print(ans)

Submission status: Wrong Answer

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

mindif = 1000
candidate = 0
for i in range(101):
    if abs(i - X) < mindif and i not in p:
        mindif = abs(i - X)
        candidate = i

print(candidate)

Submission status: Wrong Answer

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

diff = 1000
for i in range(-10, 101):
    if i in p:
        continue
    if abs(i - x) < diff:
        diff = abs(i - x)
        ans = i

print(ans)

Submission status: Wrong Answer

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

pss = [0] * 101
for p in ps:
    pss[p] = 1

#print(pss)
for i in range(101):
    if x - i > -1 and pss[x - i] == 0:
        print(x - i)
        break
    if x + i < 101 and pss[x + i] == 0:
        print(x + i)
        break

Submission status: Wrong Answer

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

not_ls = set()
for i in range(1, 101):
  not_ls.add(i)

ls_set = set(ls)
not_ls = not_ls - ls_set

num = 999
ans = -1
not_ls = list(not_ls)
not_ls.sort(reverse=True)

for i in not_ls:
  if (abs(X - i) <= num):
    num = abs(X - i)
    ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    X, N = MAP()
    if N == 0:
        print(X)
        exit()

    p = LIST()
    ans = []
    for i in range(1, 200):
        if not X-i in p:
            print(X-i)
            exit()
        if not X+i in p:
            print(X+i)
            exit()
        

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()
  q=list(range(1,max(p)+1))

  for i in p:
    q.remove(i)

  Z=1000
  ans=-1
  for i in q:
    if( abs(X-i)<Z):
      Z=abs(X-i)
      ans=i
  
  print(ans)

Submission status: Wrong Answer

Solution code:
#! env/bin/local python3
import sys

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

sorted_p = sorted(p)
except_p = [i for i in range(-101, 101) if i not in sorted_p]

memory_min = 1000
memory_index = None

for k, ep in enumerate(except_p):
    if abs(ep - x) < memory_min:
        memory_min = abs(ep - x)
        memory_index = k

print(except_p[memory_index])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
q=list(range(-1,101))
for i in range(n):
    q.remove(p[i])
ans=-100
for i in q:
    if abs(x-i)==abs(x-ans):
        ans=min(i,ans)
    elif abs(x-i)<abs(x-ans):
        ans=i
print(ans)

Submission status: Wrong Answer

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

ab = 100
num = []
for i in range(101):
    if p.count(i):
        continue
    if abs(i-x) < ab:
        ab = abs(i-x)
        num = [i]
    elif abs(i-x) == ab:
        num += [i]

print(min(num))

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(1,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 sys
N , M = (map(int , input().split()))
if M == 0:
    print(N)
    sys.exit()
A = list(map(int , input().split()))
aa = [i for i in range(-100,101)]
ans_list = {}
for i in aa:
    if i not in A:
        ans_list.update({i:abs(N-i)})
for i in ans_list:
    if ans_list[i] == min(list(ans_list.values())):
        print(i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
ans=10**18
a=[]
for i in range(101):
  if i in p:continue
  d=abs(x-i)
  if d<ans:
    ans=d
    a.append([d,i])

# print(a)
a.sort(key=lambda x: x[0])
# print(a)
mnv=a[0][0]
mnidx=a[0][1]
for ai in a:
  v,idx=ai
  if mnv==v:
    if idx<mnidx:
      mnidx=idx
  else:
    break
print(mnidx)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
P=list(map(int,input().split()))
nP=[]
min=10**15
for i in range(-100,101):
  if i not in P:
    nP.append(i)
anlist=[]
for i in nP:
  if min>abs(i-X):
    min=abs(i-X)
    anlist.append(i)
print(anlist[-1])

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,103):
    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:
a,b = map(int,input().split())
if b == 0:
    print(a)
else:
    c = list(map(int,input().split()))
    for i in range(1,b+1):
        if (a-i not in c) or (a+i not in c):
            if a +i in c:
                print(a+i)
                break
            else:
                print(a-i)
                break

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

p.sort()
q = [i for i in range(-100, 101) if i not in p]

diff = [0] * len(q)
for i in range(len(q)):
      diff[i] = abs(q[i] - x)

index = diff.index(min(diff))
print(q[index])

Submission status: Wrong Answer

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

a = -1e12
if len(P) > 0:
    for p in range(1, 101):
        if abs(X - p) < abs(X - a) and (p not in P):
            a = p
else:
    a = X

print(a)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split(" "))
p = input()
if p == "":
    print(x)
    exit(0)
p = list(map(int, p.split(" ")))
answer = 0
for i in range(1, 102):
    if i not in p and i != x:
        if abs(x - answer) > abs(i - x):
            answer = i
print(answer)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  plist=list(map(int,input().split()))
  for i in range(100000):
    if x-i-1 not in plist:
      print(x-i-1)
      break
    elif x+i+1 not in plist and x-i-1 in plist:
      print(x+i+1)
      break

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
l=list(map(int,input().split()))
tmp1=X
tmp2=X
if N==0:
    print(X)
else:
    while True:
        if not tmp1-1 in l:
            print(tmp1-1)
            exit()
        else :
            tmp1-=1
        if not tmp2+1 in l:
            print(tmp2+1)
            exit()
        else:
            tmp2+=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()))
q = [i for i in range(1,101)]
li = list(set(p) ^ set(q))
li.sort()
minabs = 10**9
ans = 0
for i in li:
    if minabs>abs(X-i):
        minabs = 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 n == 0:
    print(x)
    exit()

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

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

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

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

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

Submission status: Wrong Answer

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

if x not in p:
    print(x)
    exit()

# p.sort()
min_dist = 102
min = 0
for i in range(101):
    if i not in p:
        if min_dist > abs(x-i):
            min_dist = abs(x-i)
            min = i

print(min)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split(" "))
minimum = 0
if N!=0:
  P = list(map(int,input().split(" ")))
  for i in range(100):
    if (abs(X-minimum)>abs(X-i)) and (i not in P):
      minimum = i
print(minimum)

Submission status: Wrong Answer

Solution code:
import sys

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 
## input
 
# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
X,N=map(int, input().split())
if N==0:
    print(X)
    sys.exit()

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

P.sort()

tmp1 = 0
tmp2 = 0

for i in range(X,101):
    if P.count(i)==0:
        tmp1 = i
        break

j = X
while j >= 0:
    if P.count(j)==0:
        tmp2 = j
        break    
    j -= 1

tmp3 = abs(X - tmp1)
tmp4 = abs(X - tmp2)

if tmp3 >= tmp4:
    print(tmp2)
else:
    print(tmp1)

Submission status: Wrong Answer

Solution code:
import sys
#sys.exit()
#sorted( ,reverse=True)
#N = int(input())
X, N = map(int, input().split())
P = list(map(int, input().split()))


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

for i in range(1,N//2+1):
    #print(X-i,X+i)
    if (X -i) not in P:
        print(X-i)
        sys.exit()
    elif (X+i) not in P:
        print(X+i)
        sys.exit()
        

#A = [int(input()) for _ in range(N)]

#cnt = 0
#cnt += 1



#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')
#print(cnt)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
  c=[0]*100
  for i in p:
    c[i-1]+=1
  ans=0
  while True:
    if 0<=x-ans-1<=99:
      if c[x-ans-1]==0:
        ans=x-ans
        break
      elif 0<=x+ans-1<=99:
        if c[x+ans-1]==0:
          ans=x+ans
          break
        else:
          ans+=1
    elif 0<=x+ans-1<=99:
      if c[x+ans-1]==0:
        ans=x+ans
        break
      else:
        ans+=1
    else:
      ans=x-ans
      break
  print(ans)
else:
  print(x)

Submission status: Wrong Answer

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

ABS = 10 ** 9
ans = 0
for i in range(102):
    if i in p:continue

    temp = abs(i - x)
    if ABS > temp:
        ABS = temp
        ans = i
    else:
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
import random
from decimal import Decimal


X, N = [int(x) for x in stdin.readline().rstrip().split()]
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

ans = 10**9
ans1 = 0
for i in range(-100, 100):
    if i not in p:

        if ans > abs(X-i):
            ans = X-i
            if ans1 < i:
                ans1 = i
                # print(i)
print(ans1)

Submission status: Wrong Answer

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

min_p = 200
for i in range(-100,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()))
b = [1]*101
for a in p:
    b[a]=0

wk = 999
idx = 0
for i in range(101):
    if wk > abs(x - b[i]*i):
        wk1 = abs(x - b[i]*i)
        idx = i
    wk = wk1

print(idx)

Submission status: Wrong Answer

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


tmp=1000
for i in range(100):
	if i in p:
		continue
	if tmp>abs(X-i):
		ans=i
		tmp=abs(X-i)
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()))

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

print(ans)

Submission status: Wrong Answer

Solution code:
li = []
for i in range(200):
    li.append(i-99)
lis = set(li)
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
lia = list(map(int,input().split()))
lias = set(lia)
seta = lis - lias
li = list(seta)
li.reverse()
a = 1000
b = 0
for i in range(200-n):
    if abs(li[i]-x) <= a:
        a = abs(li[i]-x)
        b = li[i]
print(b)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = [int(i) for i in input().split()]
ans = -1
for i in range(1,101):
    if i in P:
        pass
    else:
        if abs(X-ans) > abs(X-i):
            ans = i
print(ans) if N != 0 else print(X)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
ans = 0
if n == 0: print(x)
else:
    p_i = list(map(int, input().split()))
    for val in range(n):
        minv = x - val
        maxv = x + val
        if minv not in p_i:
            print(minv)
            break
        elif maxv not in p_i:
            print(maxv)
            break
        else: 
            ans += 1

Submission status: Wrong Answer

Solution code:
'''
Author : Shubhanshu Jain;
'''

import math
import random;
from collections import defaultdict 
mod =1000000007
r1 = lambda : int(input());
rm = lambda : map(int,input().split());
rms = lambda : map(str,input().split());
rls = lambda : list(rm())

def solve():
    x,n = rm();
    ls = rls();
    ar = [0]*101;
    for i in ls:
        ar[i]= 1;
    f = x;end = x;
    # ar[x]=1
    while(f>=1 or end<=100):
        if(f<0):
            print(f);
            break;
        if(f>=0 and ar[f]==0):
            print(f);
            break;
        if(end<=100 and ar[end]==0):
            print(end);
            break;
        f-=1;
        end+=1;
            
        





def def_value(): 
	return "nan"
	
solve();

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n!=0:
    lst = [i for i in range(101)]
    a = list(map(int, input().split()))

    for i in range(n):
        lst.remove(a[i])
    
    if x in lst:
        print(x)
    else:
        b=x
        c=x
        for i in range(100):
            b-=1
            c+=1
            if b in lst:
                print(b)
                break
            elif c in lst:
                print(c)
                break
    
else:
    print(x)

Submission status: Wrong Answer

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

if N==0:
  print(X)
else:
  P = list(map(int,input().split()))
  Q = [n for n in range(-101,101) if n not in P]
  a = 10000
  d1 = 10000
  
  for q in Q:
    d2 = abs(q-X)
    if d2<d1:
      d1 = d2
      a = q
  
  print(a)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    x, n = map(int, input().split())
    if n >0:
        a = [int(i) for i in input().split()]
        listN = [i for i in range(100)]
        diffList = list(set(listN) -set(a) )
        ans = 0
        diff = 100
        for i in diffList:
            now = abs(i-x)
            if diff > now:
                diff=now
                ans =i
        print(ans)
    else:
        print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
import math
import itertools
import collections

X , N = map(int,input().split())
if N != 0:
    P = list(map(int,input().split()))
else:
    print(X)
    sys.exit()

s = set(P)

m = 1000
ans = None
for i in range(-1,101):
    if i not in s:
        if m > abs(X-i):
            ans = i
            m = abs(X-i)

print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
plist = list(map(int,input().split()))
for j in range(x):
    if x-j not in plist:
        print(x-j)
        break
    if x+j not in plist:
        print(x+j)
        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(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:
a,b=map(int,input().split())
if(b!=0):
    l=list(map(int,input().split()))
    st=1
else:
    l=[0]
    st=0
for i in range(st,101):
    if((a-i) not in l):
        print(a-i)
        break
    elif((a+i) not in l):
        print(a+i)
        break

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N > 0:
    P = list(map(int, input().split()))
    res = float('Inf')
    maxv = max(P)
    A = [0]*maxv
    for n in range(N):
        A[P[n]-1] += 1
    cnt = 1
    man = 0
    for a in A:
        if a == 0:
            total = abs(cnt - X)
            if res > total:
                res = total
                man = cnt
        cnt += 1
    print(man)
else:
    print(X)

Submission status: Wrong Answer

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

if N == 0:
    print(X)
else:
    a = [int(i) for i in range(-101, 101) if not i in p]
    m = 100
    val = 0
    for i in a:
        if abs(i-X) < m:
            m = abs(i-X)
            val = i
    print(val)

Submission status: Wrong Answer

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

for i in range(X):
    if not (X - i) in Mylist:
        print(X-i)
    elif not (X + i) in Mylist:
        print(X+i)

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)
                if trgt ==0:
                    trgt = trgt -a
                    break
            else:
                trgt = trgt -a
                a = -(a+1)


    print(trgt)

Submission status: Wrong Answer

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

length = 101
ans = 101
for i in range(-100,101):
    if not i in P:
        if abs(x-i)<length:
            length = abs(x-i)
            ans = i

print(ans)

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:
import sys

input = sys.stdin.readline

def main():
  x, n = map(int, input().rstrip().split())
  if n == 0:
    print(x)
    sys.exit()
  else:
    p = list(map(int, input().rstrip().split()))

    p_x = set(range(max(p)+1))
    p_temp = set(p)
    p_diff = p_x - p_temp
    p_temp = list(p_diff)
    p_dir = []

    for i in range(len(p_temp)):
      p_dir.append(abs(p_temp[i] - x))
    print(p_temp[p_dir.index(min(p_dir))])
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

for i in range(-100,101):
    if i not in p:
        if abs(x-i) < abs(close-x):
            close = i
        elif abs(x-i) == abs(close-x):
            close = min(close, i)

print(close)