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())
P = [int(i) for i in input().split()]

d = float("inf")
ans = -1
for x in range(102):
    if x in P:
        continue
    if abs(x-X) < d:
        ans = x
        d = abs(x-X)

print(ans)

Submission status: Accepted

Solution code:
def solution():
    input1 = input()
    input2 = input()
    target, _ = [int(x) for x in input1.split()]
    num_list = set()
    for n in input2.split():
        num_list.add(int(n))
    diff = 0
    while True:
        candidate1 = target - diff
        candidate2 = target + diff
        if candidate1 not in num_list:
            print(candidate1)
            return
        if candidate2 not in num_list:
            print(candidate2)
            return
        diff += 1
    
solution()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n ==0:
  print(x)
  exit()
else:
  p = list(map(int, input().split()))
a = 0
b = 0
while True:
  if (x - a) not in p:
    print(x-a)
    exit()
  a += 1
  if (x + b) not in p:
    print(x+b)
    exit()
  b += 1

Submission status: Accepted

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

k = 0
while(True):
    if not x-k in a:
        print(x-k)
        quit()
    if not x+k in a:
        print(x+k)
        quit()
    k += 1

Submission status: Accepted

Solution code:
x, n = map(int, input().split(' '))
diff = x
result = 0

if n != 0:
    ls = list(map(int, input().split(' ')))
    ls_remaind = []
    for i in range(1, 102):
        if i not in ls:
            ls_remaind.append(i)
    for j in ls_remaind:
        if abs(x-j) == diff:
            result = min(result, j)
        elif abs(x-j) < diff:
            diff = abs(x-j)
            result = j
else:
    result = x

print(result)

Submission status: Accepted

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

for i in range(x+1):
    for j in [-1,+1]:
        a = x + i * j
        if a not in p:
            print(a)
            exit()

Submission status: Accepted

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

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

print(min(ans))

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
for d in range(X + 1):
  for s in [-1, +1]:
    
    a = X + s * d
    
    if p.count(a) == 0:
      print(a)
      exit(0)

Submission status: Accepted

Solution code:
def c170(x, n, plist):

    if n == 1:
        if x - n not in plist:
            return x - n
        else:
            return x + n

    for i in range(n):
        if x-i not in plist:
            return x-i
        elif x+i not in plist:
            return x+i

def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    plist = list(map(int, input().split()))
    print(c170(x, n, plist))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#from pprint import pprint
from collections import deque
#from collections import defaultdict
#from collections import Counter
#from copy import deepcopy
#from itertools
#from bisect import bisect_right #二分探索用のモジュール bisect_right(a_list,value)

#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。

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

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

# = [list(map(int,input().split())) for _ in range(XXXX)]

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

pset = set(map(int,input().split()))

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



for i in range(1,100):
    if (x-i) not in pset:
        print(x-i)
        exit()
    elif (x+i) not in pset:
        print(x+i)
        exit()

Submission status: Accepted

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

p = set(p)
for i in range(200):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans_i = 0
for i in range(N+1):
    if X-i not in p or X+i not in p:
        ans_i = i
        break

if X-ans_i not in p:
    print(X-ans_i)
elif X+i not in p:
    print(X+ans_i)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
else:
  ps= set(map(int,input().split()))
  diff = 0
  while(True):
    if x-diff not in ps:
      print(x -diff)
      break
    elif x + diff not in ps:
      print(x + diff)
      break
    diff +=1

Submission status: Accepted

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

nn = input().split()
nums = list(map(int, nn))

# print(X, LEN, nums)

# 近似値の探索
pos = X
neg = X
result = X

while True:
    if (len(nums) <= 0):
        break
    if (not neg in nums):
        result = neg
        break
    if (not pos in nums):
        result = pos
        break
    neg -= 1
    pos += 1
print(result)

Submission status: Accepted

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

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

p = [int(x) for x in input().split()]

for i in range(150):
    if x-i not in p:
        print(x-i)
        exit()
    elif x+i not in p:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans = -1
mi = 1000
for i in range(102):
    if i in P:
        continue
    if abs(i-X) < mi:
        mi = abs(i-X)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys
X,N=map(int,input().split())
if N==0:
  print(X)
  sys.exit()
else:
  P=list(map(int,input().split()))
L=[]
A=[]
A_1=[]
for i in range(-100,200):
  L.append(i)
for i in P:
  L[i+100]=200
for i in L:
  A.append(abs(X-i))
A_1=sorted(A)
a=A_1[0]
for i in L:
  if i==X-a:
    print(i)
    sys.exit()
  elif i==X+a:
    print(X+a)
    break

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
P=list(map(int,input().split()))
Q=[-1,0]
for i in range(1,102):
    if i not in P:
        Q.append(i)

ans=10**9
A=[]
for i,q in enumerate(Q):
    A.append([i,abs(q-x)])
A.sort(key=lambda x:(x[1],x[0]))
print(Q[A[0][0]])

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
diff = 100000
ans = 0
for i in range(-200, 200):
  if i not in p:
    if abs(X-i) < diff:
      diff = abs(X-i)
      ans = i
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n+1):
	for x in [-1,+1]:
		y = n + x*i
		if y not in a:
			print(y)
			exit(0)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
for d in range(X + 1):
  for s in [-1, +1]: 
    a=X+s*d
    if p.count(a) == 0:
      print(a)
      exit(0)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
cnt = 0
while(1):
    key = x + (-1)**cnt*((cnt+1)//2)
    if key not in p:
        print(key)
        break
    cnt += 1

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
li = []
if n != 0:
  li = list(map(int,input().split()))
answer = 0
for i in range(0, 102):
  if (i in li):
    continue
  if abs(i-x) < abs(answer - x):
    answer = i
print(answer)

Submission status: Accepted

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

ls = [0] * 201
for i in range(0, 201):
    ls[i] = i

ls_in = [0] * n
if n > 0:
    ls_in = list(map(int, input().split(' ')))
    for i in ls_in:
        ls.remove(i)
    ls.reverse()
    for i in ls:
        min_num = min(abs(x-i), min_num)
        if abs(x-i) == min_num:
            ans = i 
    print(ans)
else:
    print(x)

Submission status: Accepted

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

else:
    p = list(map(int, input().split()))
    cnt = 0
    if x not in p:
        print(x)
    else:
        while True:
            cnt += 1
            if x - cnt not in p:
                print(x - cnt)
                break
            if x + cnt not in p:
                print(x + cnt)
                break

Submission status: Accepted

Solution code:
import numpy as np

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

all_num = list(range(0, 102, 1))
lists = [i for i in all_num if i not in num_lists]

lists_arr = np.array(lists)
diff_arr = lists_arr - x
abs_arr = np.abs(diff_arr)
index = np.where(abs_arr == abs_arr.min())
answer_list = lists_arr[index]
print(answer_list[0])

Submission status: Accepted

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


for i in range(101):
    if i == 0:
        if x not in p:
            print(x)
            exit()
        continue
    if (x - i) not in p:
        print(x-i)
        exit()
    elif (x + i) not in p:
        print(x+i)
        exit()

Submission status: Accepted

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

for d in range(X+1):
    for f in [-1,1]:
        a = X + d*f
        if p.count(a) == 0:
            print(a)
            exit()

Submission status: Accepted

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

abs_min = 101
for i in range(0, 102):
    if i in p:
        continue
    tmp = abs(i - x)
    if abs(i - x) < abs_min:
        ans = i
        abs_min = tmp
print(ans)

Submission status: Accepted

Solution code:
import sys
x, n = list(map(int,input().split()))
if n>0:
    p = list(map(int,input().split()))
else:
    print(x)
    sys.exit()
p.sort()
xmin = x
while True:
    if xmin in p:
        xmin -= 1
    else:
        break
xmax = x
while True:
    if xmax in p:
        xmax += 1
    else:
        break
# print(xmin,xmax)
print(xmin if abs(x-xmin)<=abs(x-xmax) else xmax)

Submission status: Accepted

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

# 考えたポイント
# 答えはあることを理解する
# 絶対値のうち最小
# 0, 101の扱い
# countを使う
# Xも含む
for i in range(0,X+1):
    for s in [-1,1]:
        ans = X + (i * s)
        if P.count(ans) == 0:
            print(ans)
            exit(0)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans = 1000
ans_abs = 10000
for i in reversed(range(0, 102)):
    inP = False
    for p in P:
        if p == i:
            inP = True
            break
    if not inP:
        i_abs = abs(i - X)
        if ans_abs >= i_abs:
            ans = i
            ans_abs = i_abs

print(ans)

Submission status: Accepted

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

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

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

for i in range(100):
    if x-i not in p:
        print(x-i)
        exit()
    elif x+i not in p:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
x,n = list(map(int,input().split()))
ans = 0
if n != 0:
  p_list = list(map(int,input().split()))
  for i in range(0,102):
    if i not in p_list:
      if abs(x - i) < abs(x - ans):
        ans = i
      elif abs(x - i) == abs(x - ans) and i < ans:
        ans = i
else:
  ans = x
print(ans)

Submission status: Accepted

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

x1 = x
x2 = x

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    if x not in p:
        print(x)
    else:
        while True:
            x1 -= 1
            x2 += 1
        
            if x1 not in p:
                print(x1)
                exit()
            
            if x2 not in p:
                print(x2)
                exit()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import numpy as np

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

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

m = np.array(list(range(-200,400)))
m = (m-x)**2
for i in (np.argsort(m)-200):
    if p.count(i) == 0:
        print(i)
        break

Submission status: Accepted

Solution code:
import numpy as np
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = sorted(list(map(int, input().split())))
    ok = [i for i in range(-101, 201) if i not in p]
    ix = np.argmin(list(map(lambda a: abs(X-a), ok)))
    print(ok[ix])

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
if N > 0: 
    P = list(map(int,input().split()))
    direction = -1
    i = 1
    if not X in P:
        print(X)
    else:
        while True:
            dist = i * direction
            val = dist+X
            if not (val in P):
                print(val)
                break
            if direction < 0: direction = 1
            else : 
                direction = -1
                i+=1
else: 
    print(X)

Submission status: Accepted

Solution code:
import numpy as np
def getNearestValue(Q, num):
    idx = np.abs(np.asarray(Q) - num).argmin()
    return Q[idx]

XN = list(map(int,input().split()))
X = XN[0]
N = XN[1]
if N == 0:
    print(X)
else:
    P = list(map(int,input().split()))
    Q = list(range(-100,200,1))
    for i in range(0,N):
        Q.remove(P[i])
    print(getNearestValue(Q,X))

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
else:
  p=[]
ans=0
if x in p:
  low=x
  high=x
  while True:
    low-=1
    high+=1
    if low in p:
      if high in p:
        continue
      else:
        ans=high
        break
    else:
      ans=low
      break
  print(ans)
else:
  print(x)

Submission status: Accepted

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

abs_diff = 1000
p = set(p)
for i in range(102):
    if not i in p:
        if abs(X-i)<abs_diff:
            ans = i
            abs_diff = abs(X-i)

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
p=list(map(int,input().split()))
l=list(range(0,102))
for i in p:
    l.remove(i)
ans=100
min_num=1000
for i in range(len(l)):
    if abs(l[i]-x)<min_num:
        min_num=abs(l[i]-x)
        ans=l[i]
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=list(map(int,input().split()))
a=[]
ans=100000
suu=100000

for i in range(-10,120):
  a.append(i)
for i in range(n):
  a.remove(p[i])
  
for i in range(len(a)):
  sa=abs(x-a[i])
  if sa<suu:
      suu=sa
      ans=a[i]
      
print(ans)

Submission status: Accepted

Solution code:
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
pN = [i for i in range(102) if i not in p]
pm = [abs(i - x) for i in pN]
print(pN[pm.index(min(pm))])

Submission status: Accepted

Solution code:
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
pN = [i for i in range(102) if i not in p]
pNm = [abs(i - x) for i in pN]
pmin = min(pNm)
print(pN[pNm.index(pmin)])

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans, mind = -1, 200
for i in range(102):
    if mind > abs(i - X) and i not in P:
        mind = abs(i - X)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
if N == 0:
    print(X)
    exit()
a = list(map(int,input().split()))
cnt = 0
while 1:
  b,c = X-cnt,X+cnt
  if b not in a:
    print(b)
    break
  elif c not in a:
    print(c)
    break
  else:
    cnt += 1

Submission status: Accepted

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

dis = 1000
for i in range(-100,102):
    if i not in p_list:
        sub = abs(x-i)
        dis = min(dis,sub)
            
if x-dis in p_list:
    print(x+dis)
else:
    print(x-dis)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
if M == 0:
  print(N)
else:
  c=list(map(int, input().split()))
  for i in range(N+1):
    for s in [-1,1]:
      a = N+s*i
      if c.count(a)==0:
      	print(a)
      	exit(0)

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
p = list(map(int,input().split()))
y = 0
z = 0
while y == 0:
    a = x + z
    b = x - z
    if a in p and b in p:
        z += 1
    elif a not in p and b in p:
        print(a)
        y = 4
    elif b not in p:
        print(b)
        y = 5

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n:
	p = list(map(int, input().split()))
	for i in range(n+1):
		if not x - i in p:
			print(x-i)
			break
		if 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()))
arr = [-1, 1]
for i in range(x+1):
    for pm in arr:
        cnt = x + i * pm
        if p.count(cnt) == 0:
            print(cnt)
            exit(0)

Submission status: Accepted

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

X,N = MI()

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

P = LI()

_min = 10**9
ans = []
for p in range(X+1):
    for i in [-1,1]:
        a = X + (i * p)
        if a not in P:
            print(a)
            exit()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
x,n = map(int,input().split())
if n==0:
    print(x)
else: 
    nums = list(map(int,input().split()))
    flag = 0
    i = 0
    while flag==0:
        if not x-i in nums:
            print(x-i)
            flag = 1
            break
        if not x+i in nums:
            print(x+i)
            flag = 1
        i += 1

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p = list(map(int,input().split()))
#print(p)
ans = 300
for i in range(-200,200):
    #print(i)
    if i not in p:
        #print("False")
        if abs(ans-X) > abs(X-i):
            ans = i
        elif abs(ans-X) == abs(X-i):
            ans
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    A = list(map(int, input().split()))
    P = list(set(range(-100, +200)) - set(A))
    P = sorted(P)
    print(min(P, key=lambda p: abs(p - X)))

Submission status: Accepted

Solution code:
def solve(string):
    x, _, *p = map(int, string.split())
    for i in range(101):
        if x - i not in p:
            return str(x - i)
        if x + i not in p:
            return str(x + i)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p_l = list(map(int, input().split()))
    p_x_l = [ x-i for i in p_l ]
    for i in range(101):
        if i not in p_x_l:
            print(x-i)
            break
        if -i not in p_x_l:
            print(x+i)
            break

Submission status: Accepted

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

ret = 0
i = 0
if n==0:
    ret = x
else:
    ret=x
    if( ret in l):
        while True:
            i+=1
            ret = x-i
            if( not ret in l):
                break
            ret = x+i
            if( not ret in l):
                break
print(ret)

Submission status: Accepted

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

dif =102

for i in range(102):
  if i in p:
    continue
  else:
    now = abs(X-i)
    if dif > now:
      dif = now
      ans =i

print(ans)

Submission status: Accepted

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

ans = -200
for i in range(-100, 200):
    if p.count(i):
        continue
    if(abs(i - X) < abs(ans - X)):
        ans = i
print(ans)

Submission status: Accepted

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

li = sorted(map(int, input().split()))
i = 0
while True:
    if X - i not in li:
        print(X - i)
        exit()

    if X + i not in li:
        print(X + i)
        exit()

    i += 1

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
input=sys.stdin.readline

def main():
  x, n = map(int, input().split(' '))
  if(n):
    p = list(map(int, input().split(' ')))
  else:
    p = []
    input()
  i = 0
  while(True):
    if not x-i in p:
      ans = x-i
      break
    elif not x+i in p:
      ans = x+i
      break
    else:
      i +=1
  print(ans)
  

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
import sys

x,n = map(int,input().split())
if n != 0 :
  p = list(map(int,input().split()))
else :
  print(x)
  sys.exit()
    
for i in range(200) :
  ans1 = x-i
  ans2 = x+i
  if not ans1 in p :
    ans = ans1
    break
  if not ans2 in p :
    ans = ans2
    break
    
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
X,N=map(int,input().split())
p=np.array(list(map(int,input().split())))
ans=np.array([X,X])
while True:
  for x in ans:
    if x not in p:
      print(x)
      exit()
  ans+=[-1,1]

Submission status: Accepted

Solution code:
import numpy as np
X,N=map(int,input().split())
p=np.array(list(map(int,input().split())))
ans=np.array([X,X])
while True:
  if ans[0] not in p:
    print(ans[0])
    exit()
  if ans[1] not in p:
    print(ans[1])
    exit()
  ans+=[-1,1]

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    cand = []
    for i in range(102):
        cand.append(i)
    for i in range(len(cand)):
        for j in range(n):
            if cand[i] == p[j]:
                cand[i] = 100000
    mini = 100
    for i, c in enumerate(cand):
        if mini > abs(c-x):
            ans = i
            mini = abs(c-x)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin, stdout
read = stdin.readline
write = stdout.write
flush = stdout.flush
xr = xrange

def main():
	x,n = map(int,read().split())
	a = list(map(int,read().split()))
	if x not in a:
		ans = x
	else:
		for i in xr(1,100):
			if x - i not in a:
				ans = x - i
				break
			elif x + i not in a:
				ans = x + i
				break
	print ans

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    mp = set(range(-1,102))
    p = set(list(map(int,input().split())))
    lp = list(mp-p)
    sub_lp = [abs(i-x) for i in lp]
    print(lp[sub_lp.index(min(sub_lp))])

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
q = list(map(int, input().split()))
p = []
for i in range(102):
    if not i in q:
        p.append(i)
l = []
for i in p:
    l.append(abs(i - x))
print(p[l.index(min(l))])

Submission status: Accepted

Solution code:
def main():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        exit()
    P = set(map(int, input().split()))
    min = 1000
    ans = None
    for v in range(-100, 201):
        if v in P:
            continue
        if abs(v - X) < min:
            min = abs(v - X)
            ans = v
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(200):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
A = set(i for i in range(102))
P = set(map(int,input().split()))
B=A-P

min_ = float('inf')
ans = X
for b in B:
    if abs(X-b) < min_:
        min_ = abs(X-b)
        ans = b

print(ans)

Submission status: Accepted

Solution code:

def q3():
    x, N = [int(i) for i in input().split(" ")]
    if N != 0:
        P = set([int(i) for i in input().split(" ")])
    else:
        P = set()

    if x not in P:
        print(x)
        return

    xm = x
    xp = x

    while True:
        xm = xm - 1
        if xm not in P:
            print(xm)
            return
        xp = xp + 1
        if xp not in P:
            print(xp)
            return


q3()

Submission status: Accepted

Solution code:

def q3():
    x, N = [int(i) for i in input().split(" ")]
    if N != 0:
        P = [int(i) for i in input().split(" ")]
    else:
        P = []

    if x not in P:
        print(x)
        return

    xm = x
    xp = x

    while True:
        xm = xm - 1
        if xm not in P:
            print(xm)
            return
        xp = xp + 1
        if xp not in P:
            print(xp)
            return


q3()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():

    import numpy as np

    X, N = map(int, input().split())
    p = np.array([int(x) for x in input().split()])
    #並び替えて差分の絶対値をとった後に並び替え
    p_sorted = np.sort(p)
    p_X_index = np.argsort(abs(p_sorted - X))
    p_sorted = p_sorted[p_X_index]

    i = 0
    while True :
        if np.count_nonzero(p_sorted == X - i) == 0:
            print(X - i)
            break
        elif np.count_nonzero(p_sorted == X + i) == 0:
            print(X + i)
            break
        i += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

temp = [0] * n

for i in range(n):
    temp[i] = a[i] - x

temp.sort()

abs = 0
ans = 0

while (True):
    if temp.count(abs*-1) == 0:
        ans = x - abs
        break
    elif temp.count(abs) == 0:
        ans = x + abs
        break
    else:
        abs += 1
    #print(ans)


print(ans)

Submission status: Accepted

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

ans = ''
i = 0
while ans == '':
  if x-i not in li:
    ans = x-i
  elif x+i not in li:
    ans = x+i
  else:
    i += 1
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left
x,n = (map(int,input().split()))
if n == 0:
    p = input()
    print(x)
else:
    p = sorted(list(map(int,input().split())))
    zn,zp = x,x
    zn_point,zp_point = bisect_left(p,x),bisect_left(p,x)
    while zn_point>=0 and zn==p[zn_point]:
        zn-=1
        zn_point -=1 
    while zp_point<len(p) and zp==p[zp_point]:
        zp+=1
        zp_point +=1 
    if abs(zn-x)<=abs(zp-x):
        print(zn)
    else:
        print(zp)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 1000
jugh = 1000
for i in range(0, 150):
    if abs(x-i) < jugh and i not in p:
        jugh = abs(x-i)
        ans = i
    # print(ans)
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    x,n = LI()
    p = LI()
    s = set(p)

    for i in range(101):
        if x - i not in s:
            return x - i
        if x + i not in s:
            return x + i

    return -1


print(main())

Submission status: Accepted

Solution code:
import math

if __name__ == "__main__":
    x, n = map(int, input().split())
    a = set(map(int, input().split()))
    p = q = x
    while True:
        if p not in a and q not in a:
            print(min(p, q))
            quit(0)
        if p not in a:
            print(p)
            quit(0)
        elif q not in a:
            print(q)
            quit(0)
        else:
            p -= 1
            q += 1

Submission status: Accepted

Solution code:
a=input("").split(" ")
x=int(a[0])
n=int(a[1])
if(n!=0):
    p=input("").split(" ")
    listp=[]
    c=0
    for i in range(n):
        listp+=[int(p[i])]
    for i in range(100):
        if not(x-i in listp):
            c=x-i
            break
        elif(not (x+i in listp)):
            c=x+i
            break
else:
    c=x


print(c)