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: Accepted

Solution code:
X, N = map(int, input().split())
if N:
  P = list(map(int, input().split()))
  distance = 10000
  ans = 0
  for cadi in range(101, -2, -1):
    if not cadi in P :
      if distance >= ( cadi - X ) * ( cadi - X ):
        distance = ( cadi - X ) * ( cadi - X )
        ans = cadi
  print(ans)
else:
  print(X)

Submission status: Accepted

Solution code:
def main():
    X, N = map(int, input().split())
    P = set(map(int, input().split()))
    M = [10**5]*201
    if len(P) == 0:
        print(X)
        return
    min_abs = 10**5
    for i in range(102):
        if X-i not in P and X+i not in P:
            if min_abs > abs(X-(X-i)):
                min_abs = min(min_abs, abs(X-(X-i)))
                M[min_abs] = min(M[min_abs], X-i)
            elif min_abs > abs(X-(X+i)):
                min_abs = min(min_abs, abs(X-(X+i)))
                M[min_abs] = min(M[min_abs], X+i)
        if X-i not in P:
            if abs(X-(X-i)) < min_abs:
                min_abs = abs(X-(X-i))
                M[min_abs] = min(M[min_abs], X-i)
        if X+i not in P:
            if abs(X-(X+i)) < min_abs:
                min_abs = abs(X-(X+i))
                M[min_abs] = min(M[min_abs], X+i)
    print(min(M))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math
import itertools
x, n = map(int, input().split())
p = list(map(int, input().split()))
if (n == 0):
    print(x)
    sys.exit()
diff = 1000
ans = 0
p.sort()
diff=1000
for i in range(-110,110):
    if (i in p):
       continue
    else:
        if (abs(x - i) < diff):
            diff = abs(x - i)
            ans = i
print(ans)

Submission status: Accepted

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

if n==0:
  print(x)
  exit(0)
if x not in p:
  print(x)
  exit(0)

ans=1
while True:
  if x-ans not in p:
    print(x-ans)
    exit(0)
  elif x+ans not in p:
    print(x+ans)
    exit(0)
  ans+=1

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
a = 102 - X
ans = 102
if N > 0:
  P = list(map(int, input().split()))
  for i in range(102):
    flag = True
    for j in P:
      if j == i:
        flag = False
    if flag == True and abs(X - i) < a:
      ans = i
      a = abs(X - i)
else:
  ans = X
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
X, N = list(map(int, input().split()))
p = list(map(int, input().split()))

# 求解処理
result = int()
a = 0
while True:
    x_minus = X - a
    if x_minus not in p:
        result = x_minus
        break
    x_plus = X + a
    if x_plus not in p:
        result = x_plus
        break

    a += 1

# 結果出力
print(result)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n ==0:
    print(x)
    exit()
p = set(list(map(int,input().split())))
s = {i for i in range(-5,102)}
kouho = s.difference(p)
sa = float('inf')
ans = float('inf')
for i in kouho:
    if sa > (abs(i-x)):
        sa = abs(i-x)
        ans = i

print(ans)

Submission status: Accepted

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

if not X in P:
    print(X)
else:
    for i in range(100):
        if not X-i in P: 
            tmp = True
            break
        elif not X+i in P: 
            tmp = False
            break
    print(X-i if tmp else X+i)

Submission status: Accepted

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

if n == 0:
    print(x)
else:
    if x not in p:
        print(x)
    else:
        left = x-1
        right = x+1
        while True:
            if not left in p:
                print(left)
                exit()
            if not right in p:
                print(right)
                exit()
            left -= 1
            right += 1

Submission status: Accepted

Solution code:
X, N = map(int, input().split())#
p = map(int, input().split())
p = list(p)
tmp = X
Y = X
tmp1 = 0
tmp2 = 0
if X not in p:
  tmp1 = X
for i in range(N):
  if X not in p:
    tmp1 = X
  else:
    X = X + 1
  if Y not in p:
    tmp2 = Y
  else:
    Y = Y - 1
if abs(tmp1 - tmp) >= abs(tmp2 - tmp):
  print(tmp2)
else:
  print(tmp1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

p_max = max(p)
p_min = min(p)

ans_max = -1
for i in range(x + 1, p_max + 2):
    if not(i in p):
        ans_max = i
        break
    ans_max = p_max + 1

ans_min = 101
for i in range(x - 1, p_min - 2, -1):
    if not(i in p):
        ans_min = i
        break
    ans_min = p_min - 1

if abs(x - ans_max) < abs(x - ans_min):
    print(ans_max)
else:
    print(ans_min)

Submission status: Accepted

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

if x not in a:
    print(x)
else:
    a.sort()
    idx=a.index(x)
    i=max(idx-1,0)
    j=min(idx+1,n-1)
    d=1
    ans=0
    while(True):
        if(a[i]!=x-d):
            ans=x-d
            break
        else:
            i=max(i-1,0)
        if(a[j]!=x+d):
            ans=x+d
            break
        else:
            j=min(j+1,n-1)
        d+=1
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np
X, N = map(int, input().split())
P = list(map(int, input().split()))
candidate = list([x - 500 for x in range(1, 1000)])
P = sorted(set(candidate).difference(set(P)))
i = np.argmin([abs(p - X) for p in P])
print(P[i])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

ans = 100000
for i in range(102):
    if not i in p:
        if abs(i - x) < abs(ans - x):
            ans = i
            
print(ans)

Submission status: Accepted

Solution code:
# import math
# from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()
X, N = map(int,input().split())
try:
  p = list(map(int, input().split())) # 1行, 配列
  xm = X - 1
  xp = X + 1

  if X in p:
    while True:
      if xm in p:
        xm = xm - 1
      else:
        print(xm)
        break
      if(xp in p):
        xp = xp +1
      else:
        print(xp)
        break
  else:
    print(X)
except:
  print(X)

Submission status: Accepted

Solution code:
import sys

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

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

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

if not(X in p):
  print(X)
  sys.exit()

big=X+1
sma=X-1
for i in range(N):
  if big in p and sma in p:
    big+=1
    sma-=1
    continue
  elif big in p and not(sma in p):
    print(sma)
    break
  elif not(big in p) and sma in p:
    print(big)
    break
  else:
    print(sma)
    break

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
if n != 0:
  p = list(map(int,input().split()))
  p.sort()
else:
  p = []
  print(x)
a = 0
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)
    a += 1
    break

if n == 1 and a == 0:
  if p[0] == x:
    print(x - 1)
  else:
    print(x)

Submission status: Accepted

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

flag=[False for i in range(102)]

for i in P:
    flag[i]=True

d=0
while True:
    if not flag[X-d]:
        ans=X-d
        break
    elif not flag[X+d]:
        ans=X+d
        break
    d+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    add = 1
    if x not in p:
        print(x)
    else:
        while True:
            if (x - add) not in p:
                print(x - add)
                return
            elif (x + add) not in p:
                print(x + add)
                return
            else:
                add += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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,201) if _ not in P]:
    if abs_min > abs(X-p) :
        ans = p
        abs_min = abs(X-p)
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
lp=list(map(int,input().split()))
if n==0:
    result=x
a=x
b=x
while True:
    if a not in lp and b not in lp:
        result=a
        break
    elif a not in lp:
        result=a
        break
    elif b not in lp:
        result=b
        break
    a-=1
    b+=1
print(result)

Submission status: Accepted

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

while True:
  if B in P:
    B += 1
  else:
    break

while True:
  if A in P:
    A -= 1
  else:
    break
a = abs(X - A)
b = abs(X - B)
if a < b:
  print(A)
elif a > b:
  print(B)
else:
  print(min(A, B))

Submission status: Accepted

Solution code:
import sys

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

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

for i in range(N+1) :
    if X not in p :
        print(int(X))
        sys.exit()
    else :
        X = X + (i+1)* ( (-1)**((i+1) ))

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = list(map(int, input().split()))
    p.sort()
    max_p = max(p)
    start = 0
    for i in range (max_p + 2):
        flg = 0
        for j in range(N):
            if i == p[j]:
                flg = 1
        if flg == 0:
            if start == 0:
                ans = i
                start = 1
            else:
                if abs(X-i) < abs(X-ans):
                    ans = i
    print(ans)

Submission status: Accepted

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

min_val = -1
for i in range(-1000, 1000):
    if i in P:
        continue
    if abs(min_val - X) > abs(X - i):
        min_val = i
if len(P) == 0:
    print(X)
else:
    print(min_val)

Submission status: Accepted

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

old = 1000
for i in range(200):
    try :
        p.index(i)
    except:
        tmp = i - X
        if abs(old) > abs(tmp):
            old = tmp
            sol = i
        if abs(old) == abs(tmp) and tmp < old:
            old = tmp
            sol = i

print(sol)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n != 0:
    l = list(map(int,input().split()))
def check(x):
    flg = 0
    for i in range(n):
        if l[i] == x:
            flg = 1
    return(flg)
cnt = 0
flg2 = 0
tmp = x
if n == 0:
    flg2 = 1
while flg2 == 0:
    if check(tmp) == 0:
        flg2 = 1
        ans = tmp
    else:
        cnt += 1
        if cnt%2 == 1:
            tmp = x-(cnt+1)/2
        else:
            tmp = x+cnt/2
print(int(tmp))

Submission status: Accepted

Solution code:
x, n, *P = map(int, open(0).read().split())
A = list(range(102))
P = set(P)
B = []
m = 10**4
for a in A:
    if a not in P:
        if abs(x-a) < m:
            m = abs(x-a)
            B.append((m, a))
B.sort()
print(min([k for v, k in B if v == B[0][0]]))

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
pp=[i for i in range(0,102)]
p=list(set(pp)-set(p))
ans=1000
z=1000
num=len(p)
for i in range(num-1,-1,-1):
    a=p[i]
    if abs(x-a)<=z:
        z=abs(x-a)
        if a<ans:
            ans=a
            if ans==x:
                break
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

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

    ll = [x]
    lu = [x]
    i = 1
    for _ in range(2*n):
        if ll[-1] not in p:
            print(ll[-1])
            break
        elif lu[-1] not in p:
            print(lu[-1])
            break
        ll.append(ll[-1]-i)
        lu.append(lu[-1]+i)
else:
    print(x)

Submission status: Accepted

Solution code:
from collections import deque

in_str = list(map(int,input().split()))
x = in_str[0]
n = in_str[1]
p = []
if n:
    p = list(map(int,input().split()))

def solve():
    i = 0
    while True:
        if x - i not in p:
            return x - i
        if x + i not in p:
            return x + i
        i += 1

print(solve())

Submission status: Accepted

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

for i in range(100):
    if (x - i in p):
        pass
    else:
        print(x - i)
        sys.exit()

    if (x + i in p):
        pass
    else:
        print(x + i)
        sys.exit()

Submission status: Accepted

Solution code:
x=list(map(int,input().split()))
y=list(map(int,input().split()))
import copy
z=copy.deepcopy(y)
for i in range(x[1]):
    z[i]=abs(y[i]-x[0])
    

def main(x,y,z):
    t=0
    if 0 not in z:
        print(x[0])
        t=1
    num=1
    while True:
        if t==1:
            break
        if z.count(num)!=2:
            if x[0]-num not in y:
                print(str(x[0]-num))
                break
            else:
                print(str(x[0]+num))
                break
        num+=1
            
            
main(x,y,z)

Submission status: Accepted

Solution code:
import math
x, n = map(int, input().split())
p = list(map(str, input().split()))
dis = {}
for i in p:
    dis[i] = True

res = -1
mins = 100
for i in range(200):
    if not dis.get(str(i)) and math.fabs(i - x) < mins:
        res = i
        mins = math.fabs(i - x)
print(res)

Submission status: Accepted

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

if n!=0:
  l=list(map(int,input().split()))
  d={}
  for i in l:
    if i not in d:
      d[i]=1
    else:
      d[i]+=1
  ct=0
  while 1:
    if x-ct not in d:
      print(x-ct)
      break
    elif x+ct not in d:
      print(x+ct)
      break
    ct+=1
    
else:
  print(x)

Submission status: Accepted

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


a = 0
b = 0
while b == 0:
    if x - a not in p:
        print(x-a)
        b = b + 1
    elif x + a not in p:
        print(x+a)
        b = b + 1
    a = a + 1

Submission status: Accepted

Solution code:
I1 = input().split()
I2 = input().split()

result = int(I1[0])
delta = 0
flag = 0
while flag == 0:
    if str(result-delta) in I2:
        if str(result+delta) in I2:
            delta += 1
        else:
            print(result + delta)
            flag = 1
    else:
        print(result - delta)
        flag = 1

Submission status: Accepted

Solution code:
X,N = map(int,input().split( ))
p = set(list(map(int,input().split( ))))
all_num_plus = {i for i in range(1,501)}
all_num_minus = {-i for i in range(0,501)}
all_num = all_num_plus | all_num_minus
ans = 1000
ans_num = 1000
for i in list(all_num - p):
    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: Accepted

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

if p == []:
    print(x)
    exit()

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

tmp1 = x
tmp2 = x

for i in range(1,500):
    tmp1 = tmp1 - 1
    tmp2 = tmp2 + 1
    if tmp1 not in p:
        print(tmp1)
        exit()
    if tmp2 not in p: 
        print(tmp2)
        exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n>0:
  p=list(map(int,input().split()))
else:
  p=[]
minx=0
absx=101
for i in range(102):
  if i in p:
    continue
  else:
    cabs=abs(x-i)
    if cabs < absx:
      absx=cabs
      minx=i
if absx==101:
  if x>51:
    minx=101
print(minx)

Submission status: Accepted

Solution code:
import sys 
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X, N = map(int, readline().split())
A = list(map(int,readline().split()))
B = [i for i in range(102)]
for a in A:
    B.remove(a)
index = bisect.bisect_left(B,X)
if (X-B[index-1]) <= (B[index]-X):
  print(B[index-1])
else:
  print(B[index])

Submission status: Accepted

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 not exist[X-i]:
        print(X-i)
        exit()

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

    if not exist[X+i]:
        print(X+i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
P = [p for p in map(int,input().split())]
d = 0
while True:
    if not((X-d) in P):
        print(X-d)
        break
    if not((X+d) in P):
        print(X+d)
        break
    d+=1

Submission status: Accepted

Solution code:
x, n = map(int, input().split());
if n == 0:
    print(x);
elif n == 1:
    b = int(input());
    if b == x:
        print(x-1);
    else:
        print(x);
else:
    a = list(map(int,input().split()));
    
    for i in range(n):
        if a.count(x-i) == 0:
            ooo = 1;
            break;
        if a.count(x+i) == 0:
            ooo = 2;
            break;
        
            
    if ooo == 1:
        print(x-i);
    else:
        print(x+i);

Submission status: Accepted

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

candidates= {}
for i in range(203):
    a = x-101+i
    candidates[a] = abs(x-a)

for p in p_list:
    del candidates[p]
    
min_diff = None
ans = []
for k, v in sorted(candidates.items(), key=lambda x:x[1]):
    if min_diff is None:
        min_diff = v
        ans.append(k)
    elif min_diff == v:
        ans.append(k)
    else:
        break
print(min(ans))

Submission status: Accepted

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

if N > 0:
  p = list(map(int, input().split(" ")))
else:
  p = []

go = True
absolute = 1
plus = True

if X not in p:
  print(X)
else:
  while go:
    if plus:
      target = X - absolute
      if target not in p:
        print(target)
        go = False
      plus = False
    else:
      target = X + absolute
      if target not in p:
        print(target)
        go = False
      absolute += 1
      plus = True

Submission status: Accepted

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

for i in range(1000):
  a = X - i
  if a not in p:
    print(a)
    exit()

  a = X + i
  if a not in p:
    print(a)
    exit()

Submission status: Accepted

Solution code:

x,y=map(int,input().split())
a=set(list(map(int,input().split())))
if y==0:
    print(x)
else:
    b=[i for i in range(-5,105)]
    b=set(b)
    c=list(b-a)
    c.append(x)
    c.sort()

    r=c.index(x)
    
    p=abs(c[r]-c[r-1])
    q=abs(c[r]-c[r+1])
    if p==q:
            print(min(c[r-1],c[r+1]))
    elif p>q:
            print(c[r+1])
    else:
            print(c[r-1])

Submission status: Accepted

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################

x , n = map(int , input().split())
if n == 0:
	print(x)
	exit()
arr = list(map(int , input().split()))
ans = 10**10
m = max(arr) + 1
mi = 10**10
for i in range(-100 , 105):
	if i not in arr:
		if mi > abs(x-i):
			#print(abs(x-i),i)
			ans = i
			mi = abs(x-i)
		if mi == abs(x-i):
			ans = min(ans , i)
print(ans)

Submission status: Accepted

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

    p.sort()
    gap = 10**1000
    ans =10**1000
    for i in range(0,1000):
        if not x-i in p:
            print(x-i)
            break
        elif not x+i in p:
            print(x+i)
            break
else:
    print(x)

Submission status: Accepted

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

while 1:
    if not x-dif in p:
        print(x-dif)
        exit()
    elif not x+dif in p:
        print(x+dif)
        exit()
    dif += 1

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())))
l = [int(i) for i in range(-200, 201)]
ll = []
for idx in l:
    if idx not in p:
        ll.append(idx)
mn = 1000
if len(ll) == 0:
    print("")
else:
    mn = 1000
    for i in range(len(ll)):
        if abs(ll[i] - x) < mn:
            mn = abs(ll[i] - x)
            ans = ll[i]
    print(ans)

Submission status: Accepted

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

for i in range(100):
    if not (X - i) in Mylist:
        print(X-i)
        sys.exit()
    elif not (X + i) in Mylist:
        print(X+i) 
        sys.exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
while True:
      try:
        p=list(map(int,input().split()))
        break
      except EOFError:
        p=[]
        break
p.sort()

ans=0
i=0
while(True):
  if x-i not in p:
    ans=x-i
    break
  if x+i not in p:
    ans=x+i
    break
  i+=1

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n ==0:
    print(x)
else:
    p=list(map(int,input().split()))
    tmp=101
    min_num=101
    for i in range(102):
        if i not in p:
            if tmp > abs(x-i):
                min_num=i
                tmp=abs(x-i)
    print(min_num)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
    print(X)
    exit()
P=list(map(int,input().split()))
M=[i for i in range(102)]
for i in P:
    M[i]=0
A=101
for i in M:
    a=abs(X-i)
    if a<A:
        A=a
        Ans=i
print(Ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n != 0:
    p = [int(i) for i in input().split()]
    # print(p)
    # print(4 in p)
    diff = 0
    while True:
        # print(x - diff)
        if x - diff in p and x + diff in p:
            # print('inp')
            diff += 1
            continue
        else:
            if x - diff not in p:
                print(x - diff)
            else:
                print(x + diff)
            break

else:
    print(x)

Submission status: Accepted

Solution code:
import numpy as np

def resolve():
    import sys
    input = sys.stdin.readline
    xn = [int(x) for x in input().rstrip().split()]
    x = xn[0]
    n = xn[1]
	
    if n == 0:
      print(x)
      exit()
    
    p = [int(x) for x in input().rstrip().split()]
    num_list = [i for i in range(0, 102) if not i in p]

    idx = np.abs(np.asarray(num_list) - x).argmin()
    print(num_list[idx])



# x = list(map(int, input().split()))

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

D=[[]for i in range(201)]


for i in range(-99,102):
    D[i].append(i)
    D[i].append(abs(X-i))
#print(D)
    
T=sorted(D,key=lambda x:x[1])
#for i in range(N):
for i in range(201):
    if T[i][0] not in S:
        print(T[i][0])
        exit()

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N!=0:
    p=list(map(int,input().split()))
    p.sort()
    for i in range(X,102):
        if i not in p:
            min_=i
            dif_min=i-X
            break;
    for i in range(X,-1,-1):
        if i not in p:
            max_=i
            dif_max=X-i
            break;
    if dif_max<=dif_min:
          print(max_)
    else:
          print(min_)
else:
    print(X)

Submission status: Accepted

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(True):
        if f not in ls:
            print(f)
            break;
        if end not in ls:
            print(end);
            break;
        f-=1;
        end+=1;
            
        





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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
q=list(range(-1,200))
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: Accepted

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

if n == 0:
    print(x)
elif not (x in p):
    print(x)
else:
    r = 1
    while True:
        if not (x-r in p):
            print(x-r)
            break
        elif not (x+r in p):
            print(x+r)
            break
        else:
            r += 1

Submission status: Accepted

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

Submission status: Accepted

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+1):
    if p.count(X-i)==0:
        print(X-i)
        exit()
    if p.count(X+i)==0:
        print(X+i)
        exit()

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = sorted([abs(i-X) for i in P])

if 0 not in ans:
    print(X)
    exit()
c = Counter(ans[1:])

for i in range(1,201):
    if c[i] != 2:
        if X - i not in P:
            print(X-i)
            exit()
        else:
            print(X+i)
            exit()

Submission status: Accepted

Solution code:
X, N = (map(int, input().split()))
p = list(sorted(map(int, input().split())))
lmin = 10000
if(X not in p):
    print(X)
    exit()
for i in range(1, 200):
    if(X+i in p and X-i in p):
        continue
    if((X-i not in p) and (X+i in p)):
        print(X-i)
        exit()
    elif((X-i in p) and (X+i not in p)):
        print(X+i)
        exit()
    elif((X-i not in p) and (X+i not in p)):
        print(X-i)
        exit()

Submission status: Accepted

Solution code:
X,N=map(int, input().split())
lis = list(map(int, input().split()))
p=list(range(102))
# print(p)
for i in lis:
    p.remove(i)
# print(p)
d=10000
m=10000
for i in p:
    if d > abs(X-i):
        d = abs(X-i)
        m = i
print(m)

Submission status: Accepted

Solution code:
import bisect

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

p = [0 for _ in range(n)]

if not (n == 0):
    p = [int(s) for s in input().split()]
    p_s = set(p)
    mn = x
    mx = x
    ans = 0
    while True:
        if not (mn in p_s):
            ans = mn
            break
    
        if not (mx in p_s):
            ans = mx
            break
        
        mn -= 1
        mx += 1
    
    print(ans)
else:
    print(x)

Submission status: Accepted

Solution code:
import sys
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    try:
        _ = p.index(x)
    except ValueError:
        print(x)
    else:
        for i in range(1, 101):
            if x - i not in p:
                print(x - i)
                sys.exit()
            if x + i not in p:
                print(x + i)
                sys.exit()

Submission status: Accepted

Solution code:
# C

import bisect

x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p_list = {int(x) for x in input().split()}
    q_list = {int(x) for x in range(102)}
    q_list = list(q_list - p_list)

    p = bisect.bisect_left(q_list, x)
    if p == 0:
        print(q_list[p])
    elif p == len(q_list):
        print(q_list[p-1])
    else:
        if abs(q_list[p-1] - x) <= abs(q_list[p] - x):
            print(q_list[p-1])
        else:
            print(q_list[p])