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 == 0:
    print(x)
else:
    p = list(map(int, input().split()))

    check = [True]*10001

    for i in p:
        check[i] = False

    mini = 100000
    index = 1

    for i in range(0,1001):
        if check[i]:
            if mini > abs(x-i):
                #print(mini, abs(x-i), i)
                mini = abs(x-i)
                index = i

    #マイナス
    for i in range(1,1001):
        if mini >= abs(x+i):
            #print(mini, abs(x+i), -i)
            mini = abs(x+i)
            index = -i

    print(index)

Submission status: Accepted

Solution code:
import math
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    pn = list(map(int, input().split()))
    flag = 0
    if x not in pn:
        print(x)
    else:
        a,b = x-1, x+1
        while flag == 0:
            if a not in pn:
                print(a)
                flag = 1
            elif b not in pn:
                print(b)
                flag = 1
            else:
                a -= 1
                b += 1

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=set(map(int,input().split()))
if X not in p:
	print(X)
else:
	x=X-1
	while x in p:
		x-=1
	y=X+1
	while y in p:
		y+=1
	a,b=X-x,y-X
	if a==b:
		if x<y:
			print(x)
		else:
			print(y)
	elif a<b:
		print(x)
	else:
		print(y)

Submission status: Accepted

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

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

p.sort()
tmp = [i for i in range(-111, 111)]
for i in p:
        tmp.remove(i)

ans_num = float("Inf")
ans_i = 0
for i in range(len(tmp)):
        if abs(X - tmp[i]) < ans_num:
                ans_num = abs(X - tmp[i])
                ans_i = i


print(tmp[ans_i])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
x, n = map(int, input().split())
p = [int(s) for s in input().split()]
p_abs = [abs(s-x) for s in p]
if 0 not in p_abs:
  print(x)
  sys.exit()
for j in range(1, 101):
  ans = [i for i, x in enumerate(p_abs) if x == j]
  # print(ans)
  if len(ans)==1:
    print(x + (x - p[ans[0]]))
    sys.exit()
  if len(ans)==0:
    print(x-j)
    sys.exit()

Submission status: Accepted

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

tmp = 1000
result = []
result2 = []
for i in range(0, 102):
    if i in A:
        continue

    hoge = abs(X - i)
    if hoge <= tmp:
        tmp = hoge
        result2.append(tmp)
        result.append(i)

result3 = []
for i, v in enumerate(result2):
    if v == min(result2):
        result3.append(result[i])

print(min(result3))

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
min_num = 1000
num = x
for i in range(1000):
    if i not in p:
        if abs(x-i) < min_num:
            min_num = abs(x-i)
            num = i
print(num)

Submission status: Accepted

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

ans = 0
i = 0
flag = 1

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

Submission status: Accepted

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

Ps = list(map(int,input().split()))
A_small=0
A_big=0


for i in range(101):
    A_small=X-i
    if A_small in Ps:
        continue
    else:
        break
for i in range(101):
    A_big=X+i
    if A_big in Ps:
        continue
    else:
        break
if A_big-X >= X-A_small:
    print(A_small)
else:
    print(A_big)

Submission status: Accepted

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

Submission status: Accepted

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

# process
if N == 0:
    print(X)
else:
    P.sort()

    idx = N-1
    num = P[-1]
    for i in range(N):
        if X <= P[i]:
            idx = i
            num = P[idx]
            break

    for i in range(idx, -1, -1):
        if i == 0:
            low = P[i]-1
            break
        
        if P[i]-1 != P[i-1]:
            low = P[i]-1
            break

    for i in range(idx, N):
        if i == N-1:
            high = P[i]+1
            break
        
        if P[i]+1 != P[i+1]:
            high = P[i]+1
            break

    # output
    print(low if X-low <= high-X else high)

Submission status: Accepted

Solution code:
l=[]
for i in range(-100,201):
    l.append(i)
x,n=map(int,input().split())
p=list(map(int,input().split()))
flag=False
if p.count(x)==0:
    print(x)
    flag=True
for i in range(n):
    if p[i]!=x:
        l.remove(p[i])
a=l.index(x)
if not flag:
    if abs(x-l[a-1])<=abs(x-l[a+1]):
        print(l[a-1])
    else:
        print(l[a+1])

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = [int(x) for x in input().split()]
all = list(range(102))
p_set = set(p)
p_all = set(all)
p_nokori = p_all - p_set
nokori = list(p_nokori)
import bisect
n = bisect.bisect_left(nokori,x)

left = x - nokori[n-1]
right = nokori[n] -x

if left <= right:
    print(nokori[n-1])
else:
    print(nokori[n])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	x,n = map(int,input().split())
	p = [int(a) for a in input().split()]
	p.sort()
	if x in p:
		m = 100
		ans = 0
		for i in range(-10,200):
			if not i in p:
				v = abs(i-x)
				if m > v:
					m = v
					ans = i
		print(ans)
	else:
		print(x)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n==0: exit(print(x))
p = list(map(int,input().split()))
p.sort()
if x not in p: exit(print(x))
h=101
l=0
for i in range(x,101):
    if i not in p:
        h = i
        break
for i in range(x,0,-1):
    if i not in p:
        l = i
        break
if abs(x-h)>=abs(x-l): print(l)
if abs(x-l)>abs(x-h): print(h)

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()))
p.sort()
if p[n-1]<x or x<p[0]:
  print(x)
  sys.exit()
lst=[]
for i in range(n-1):
  if p[i+1]-p[i]>1:
    for j in range(p[i+1]-p[i]-1):
      lst.append(p[i]+j+1)
if len(lst)==0:
  if abs(p[0]-1-x)<=abs(p[n-1]+1-x):
    print(p[0]-1)
    sys.exit()
  else:
    print(p[n-1]+1)
    sys.exit()
if abs(p[0]-1-x)<=abs(p[n-1]+1-x):
  d=abs(p[0]-1-x)
  idx=-2
else:
  d=abs(p[n-1]+1-x)
  idx=-1
for i in range(len(lst)):
  if d>abs(lst[i]-x):
    d=abs(lst[i]-x)
    idx=i
  elif d==abs(lst[i]-x):
    if idx==-1:
      idx=i
if idx==-2:
  print(p[0]-1)
if idx==-1:
  print(p[n-1]+1)
else:
  print(lst[idx])

Submission status: Accepted

Solution code:
import numpy as np

def getNearestValue(list, num):
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
  print(x)
else:
  l = list(range(102))
  for i in p:
    l.remove(i)
  print(getNearestValue(l, x))

Submission status: Accepted

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

if N == 0:
    print(X)
else:
    for i in range(100):
        # 左からと右からを交互に計算
        left = X - i
        right = X + i

        if left not in p:
            print(left)
            break
        if right not in p:
            print(right)
            break

Submission status: Accepted

Solution code:
intX, length = map(int, input().split())
intList = input().split()
intList = [int(x) for x in intList]

for i in range(intX + 1):
    if intX - i not in intList:
        print(intX - i)
        break
    elif intX + i not in intList:
        print(intX + i)
        break

Submission status: Accepted

Solution code:
def solve():
    X, N = [int(x) for x in input().split()]
    if N > 0:
        pn = [int(x) for x in input().split()]
    else:
        pn = []
    pn = set(pn)
    ans = X
    if N == 0 or X not in pn:
        return ans
    left = 0
    right = 0
    while True:
        left += 1
        if (X - left) not in pn:
            return X - left
        right += 1
        if (X + right) not in pn:
            return X + right


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

Submission status: Accepted

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

for i in range(200):
    ans1 = x - i
    ans2 = x + i
    if ans1 not in p:
        print(ans1)
        break
    if ans2 not in p:
        print(ans2)
        break

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = sorted(map(int, input().split()))
    nums = [num for num in range(102) if not num in p]
    A = [abs(num - X) for num in nums]
    print(nums[A.index(min(A))])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, N = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    P = [int(i) for i in input().split()]
    ans = 0
    for i in range(100):
        if X - i < 1 or X - i not in P:
            ans = X - i
            break
        elif X + i > 100 or X + i not in P:
            ans = X + i
            break
    print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
r = 10**9 + 7

primeset = list(range(-1, 2*x))
trial = list(range(-1, 2*x))
for i in range(len(trial)):
    if trial[i] in p:
        trial[i] = r
    else:
        trial[i] = abs(x - trial[i])

ans = r + 100
trynow = r
for i in range(len(trial)):
    if trial[i] < trynow:
        trynow = trial[i]
        ans = primeset[i]

print(ans)

Submission status: Accepted

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

p.sort()

if p.count(X) == 0:
    print(X)
    exit()

array = [0]*100
for i in range(N):
    array[p[i]-1] = 1

ans_smaller_x = 0
ans_bigger_x = 101

for i in range(X-2,-1,-1):
    if array[i] == 0:
        ans_smaller_x = i+1
        break

for i in range(X,100,1):
    if array[i] == 0:
        ans_bigger_x = i+1
        break

if abs(X - ans_smaller_x) == abs(X - ans_bigger_x):
    print(ans_smaller_x)
else:
    if abs(X - ans_smaller_x) > abs(X - ans_bigger_x):
        print(ans_bigger_x)
    else:
        print(ans_smaller_x)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
hako=set(P)
#print(hako)
ans=[]
P.sort()
kari=[]
for i in range(102):
    if i not in hako:
        kari.append(i)
for i in range(len(kari)):
    ans.append([abs(X-kari[i]),kari[i]])
ans.sort()
print(ans[0][1])

Submission status: Accepted

Solution code:
from typing import List


def main(x: int, n: int, p: List[int]):
    if x not in p:
        print(x)
        return

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

        if (x + i) not in p:
            print(x + i)
            return


if __name__ == "__main__":
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    main(x, n, p)

Submission status: Accepted

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

if N == 0:
  print(X)
else:
  p = list(map(int,input().split()))
  for i in range(100):
    a = X + i
    b = X - i
    if b not in p:
      print(b)
      break
    if a not in p:
      print(a)
      break

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
plis = list(map(int, input().split()))
lis = [i for i in range(102)]
for p in plis:
    lis.remove(p)
ans = float('inf')
for i in lis:
    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)
else:
	line = list(map(int, input().split()))

	for i in range(0, 101):
		a = x-i
		b = x+i
		if a not in line:
			print(a)
			exit()
		if b not in line:
			print(b)
			exit()

Submission status: Accepted

Solution code:
inpt = input()
x = int(inpt.split()[0])
n = int(inpt.split()[1])
all = set(range(-1, 102))
ipt = set()
inpt = input().split()
for i in inpt:
    ipt.add(int(i))

sub = all - ipt
if len(sub) > 0:
    sub = list(sub)
    sub.sort()
now = int(100)
for i in sub:
    if (abs(x-i) < now):
        now = min(abs(x-i), now)
        ans = i


print(ans)

Submission status: Accepted

Solution code:
from collections import deque

X, N = [int(i) for i in input().split()]

nums = [int(i) for i in input().split()]

candidates = deque([X])
output = []

while True:
    c1 = candidates[0]
    c2 = candidates[-1]
    for c in [c1,c2]:
        if c not in nums:
            output.append(c)
    if len(output) > 0:
        break
    candidates.appendleft(candidates[0]-1)
    candidates.append(candidates[-1]+1)
    
print(min(output))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

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

P = read_ints()
for i in range(101):
    b = X + i
    a = X - i
    if a not in P:
        print(a)
        exit()
    if b not in P:
        print(b)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))  
else:
  print(x)
  exit()
if x not in p:
  print(x)
  exit()
for i in range(1,100000000000):
  p_=x-i
  q=x+i
  if p_ not in p:
    print(p_)
    exit()
  if q not in p:
    print(q)
    exit()

Submission status: Accepted

Solution code:
abs, N = map(int,input().split())
if N:
    s = list(map(int,input().split()))
    flag = 1
else:
    flag = 0
cnt = 0
while flag:
    if not(abs - cnt) in s:
        result = abs - cnt
        break
    if not(abs + cnt) in s:
        result = abs + cnt
        break
    cnt += 1
if flag:
    print(result)
else:
    print(abs)

Submission status: Accepted

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(0, 102)))

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

Solution code:
import sys
from bisect import bisect_left

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

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

    P.sort()

    ind=bisect_left(P,X)

    if (P[ind]!=X):
        print(X)
    else:
        left=ind-1
        right=ind+1
        leftX=X-1
        rightX=X+1

        flag=0
        while left>=0 or right<=N-1:
            if left>=0:
                if P[left]!=leftX:
                    print(leftX)
                    flag=1
                    break
            if right<=N-1:
                if P[right]!=rightX:
                    print(rightX)
                    flag=1
                    break

            left-=1
            right+=1
            leftX-=1
            rightX+=1

        if flag==0:
            left=ind+1
            right=(N-1)-ind+1
            if left<=right:
                print(X-left)
            else:
                print(X+right)


if __name__=="__main__":
    main()

Submission status: Accepted

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

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

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 = False
x1 = x
while a == False:
    if x1 not in p:
        a = True
        break
    elif x1 in p:
        x1 -= 1

b = False
x2 = x
while b == False:
    if x2 not in p:
        a = True
        break
    elif x2 in p:
        x2 += 1

if abs(x - x1) > abs(x - x2):
    print(x2)
elif abs(x - x1) < abs(x - x2):
    print(x1)
elif abs(x - x1) == abs(x - x2):
    print(x1)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p =list(map(int, input().split()))
m = 10**10
ans = 10**10
if n == 0:
    print(x)
    exit()
for i in range(1000):
    if i in p:
        continue
    if m > abs(i-x):
        m = abs(i-x)
        ans = i
    elif m==abs(i-x):
        ans = min(ans,i)
print(ans)

Submission status: Accepted

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:
        if abs(x - answer) > abs(i - x):
            answer = i
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import sys
x,n = map(int,input().split())
if n==0:
    print(x)
    sys.exit()
l = list(map(int,input().split()))
l.sort()
index = bisect.bisect_left(l,x)
lis=[]
if l[index]==x:
    for i in l:
        lis.append(abs(i-x))
    lis.sort()
    key=0
    for i in range(1,100):
        a=lis.count(i)
        if a!=2:
            key=i
            break
    ans=x-key
    if ans not in l:
        print(ans)
        sys.exit()
    else:
        print(x+key)
        sys.exit()
else:
    print(x)

Submission status: Accepted

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


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')


def main():
	x,n=MI()
	p=[]
	if n!=0:
		p=LI()
	p.sort()

	diff=105
	ans=105

	for i in range(105,-1,-1):
		if i in p:
			continue
		else:
			if abs(i-x)<=diff:
				ans=i
				diff=abs(i-x)

	print(ans)













if __name__ == "__main__":
	main()

Submission status: Accepted

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

nums = [i for i in range(102)]

for i in p:
    nums.remove(i)

ans = []
for i in reversed(nums):
    if i <= x:
        sx = x - i
        ans.append(i)
        break

for i in nums:
    if i >= x:
        lx = i - x
        ans.append(i)
        break

if sx <= lx:
    print(ans[0])
else:
    print(ans[1])

Submission status: Accepted

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

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

p = set(p)
now = 0
diff = 101
indx = 0

while True:
    if now not in p:
        now_diff = abs(now - x)
        if diff > now_diff:
            diff = now_diff
            indx = now
        else:
            break
    now += 1

print(indx)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
P = set(map(int,input().split()))
Z = {_ for _ in range(-1,102)}
Z = Z-P
d = 101
ans = 101
for s in Z:
    y = abs(x-s)
    if y<d:
        d = y
        ans = s
print(ans)

Submission status: Accepted

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(x-i)
        exit()
    elif x+i not in a:
        print(x+i)
        exit()
print(x-(n//2)-1)

Submission status: Accepted

Solution code:
from heapq import heapify, heappush, heappop

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

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

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

nums = []

heapify(nums)

for i in range(0, 102):
    if i not in P:
        heappush(nums, (abs(i - X), i))

print(heappop(nums)[1])

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
q = [i for i in range(-110, 210)]
if n != 0:
  p = list(map(int, input().split()))
  for i in p:
    q[i+110] = -500

if x in q:
  print(x)
  exit()

l = []

for i in range(100):
  if x+i in q:
    l.append(x+i)
    break
for j in range(100):
  if x-j in q:
    l.append(x-j)
    break

if abs(l[0]-x) < abs(l[1]-x):
  print(l[0])
elif abs(l[0]-x) > abs(l[1]-x):
  print(l[1])
else:
  print(l[1])

Submission status: Accepted

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

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

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

def check(num):
  if num not in p:
    print(num)
    exit()

for i in range(101):
  check(x-i)
  check(x+i)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

#渡されたxとlistに対して、listに存在しない最も近い整数を返す関数
def foo(x, list):
    i = 1
    if list.count(str(x)) == 0:
        return (x)
    while True:
        if list.count(str(x-i)) == 0:
            return (x-i)
        if list.count(str(x+i)) == 0:
            return (x+i)
        i = i+1
        
#標準出力からの読み込み
x, n = input().split(" ")
if int(n) != 0:
    p = input().split(" ")
    print(foo(int(x), p))
else:
    print(x)

Submission status: Accepted

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

if x not in p:
    print(x)
else:
    for num in p:
        ll.remove(num)
    l2 = []
    ans = float('inf')
    for i in ll:
        if abs(i-x) < abs(x-ans):
            ans = i
        if abs(i-x) == abs(ans-x):
            ans = min(i, ans)

    print(ans)

Submission status: Accepted

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

p.sort()
if X not in p or p == []:
    print(X)
else:
    idx = p.index(X)
    for i in range(1,idx+2):
        if i == idx+1:
            before = p[0] - 1
            break
        if p[idx - i +1] - p[idx - i] == 1:
            continue
        else:
            before = p[idx-i+1] -1
            break
    for i in range(1,N-idx+1):
        if i == N-idx:
            after = p[-1] + 1
            break
        if p[idx + i] - p[idx + i -1] == 1:
            continue
        else:
            after = p[idx + i - 1] +1
            break
    if X-before > after-X:
        print(after)
    else:
        print(before)

Submission status: Accepted

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

    if n > 0:
        p = list(map(int, input().split()))
        q = [i for i in range(min(p)-1, max(p)+2)]
        for item in p:
            if item in q:
                q.remove(item)

        ans = []
        current_min = float('inf')
        for item in q:
            diff = abs(x-item)
            if diff < current_min:
                current_min = diff
                ans.clear()
                ans.append(item)
            elif diff == current_min:
                ans.append(item)

        print(min(ans))
    else:
        print(x)


if 'unittest' not in globals():
    resolve()

Submission status: Accepted

Solution code:
[x,n] = list(map(int, input().split()))
pList = list(map(int, input().split()))
pSet = set(pList)
step = 0
small = False
big = False
while True:
    if x - step not in pSet:
        small = True
        break
    if x + step not in pSet:
        big = True
        break
    step += 1
if small:
    print(x-step)
else:
    print(x+step)

Submission status: Accepted

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

if N == 0:
    print(X)
    exit()
if X not in pp:
    print(X)
    exit()

ans = X
diff = 0
while True:
    diff += 1
    ans = X - diff
    if ans not in pp:
        print(ans)
        break
    ans = X + diff
    if ans not in pp:
        print(ans)
        break

# left, right = 0, 0
# for i in range(N):
#     if i == N - 1:
#         left, right = , -1
#     if pp[i] == X:
#         cur = i
#         break
#     if pp[i] > X:
#         if i == 0:
#             left, right = -1, pp[i]
#         else:
#             left, right = pp[i - 1], pp[i]

#         break

Submission status: Accepted

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

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

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

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

for i in range(x, 1000):
    if not i in p:
        ans1 = i
        break

for i in range(x-1, -1000, -1):
    if not i in p:
        ans2 = i
        break

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

Submission status: Accepted

Solution code:
import sys


def main():
    x, n = map(int, input().split())
    P = list(map(int, input().split()))

    if not (x in P):
        print(x)
        sys.exit()

    for i in range(101):
        x1 = max(0, x - (i + 1))
        x2 = min(101, x + (i + 1))

        if x1 == 0:
            print(0)
            sys.exit()
            
        if not (x1 in P):
            print(x1)
            sys.exit()

        if x2 == 101:
            print(101)
            sys.exit()
            
        if not (x2 in P):
            print(x2)
            sys.exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
p = list(map(int,input().split()))
kazu = [i for i in range(-100,201)]
sa = [0]*301
for i in range(301):
    if kazu[i] in p:
        kazu[i] = 10000
for i in range(301):
    sa[i] = abs(X-kazu[i])
print(kazu[sa.index(min(sa))])

Submission status: Accepted

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

nota = list()

for i in range(-1000, 1001):
    if i in a:
        continue
    nota.append(i)

nota.sort()
ans = 1000
minabs = 1000
for i in nota:
    if minabs > abs(i-x):
        minabs = abs(i-x)
        ans = i

print(ans)

Submission status: Accepted

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

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

min_diff_val = X + 100
min_val = -100
for y in range(-100, 200):
    if not (y in p):
        if min_diff_val > abs(y - X):
            min_val = y
            min_diff_val = abs(y - X)
print(min_val)

Submission status: Accepted

Solution code:
R = lambda: map(int, input().split())
x, n = R()
print(min((abs(x - y), y) for y in set(range(102)) - set(R()))[1])

Submission status: Accepted

Solution code:
import sys

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

if n == 0:
    print(x)
    sys.exit()
elif not(x in p_list):
    print(x)
    sys.exit()
elif len(p_list) == 100 and x <= 50:
    print(0)
    sys.exit()
elif len(p_list) == 100 and x > 50:
    print(101)
    sys.exit()

list.sort(p_list, reverse=True)
dis_list = list(range(102))
for p in p_list:
    dis_list.pop(p)

min_dis = 102
ans = 0
for index in dis_list:
    dis = abs(index - x)
    if dis < min_dis:
        min_dis = dis
        ans = index
print(ans)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
if a[1] == 0:
    print(a[0])
else:
    l = list(map(int, input().split()))

    for i in range(100):
        if a[0]-i not in l:
            print(a[0]-i)
            break
        elif a[0]+i not in l:
            print(a[0]+i)
            break

Submission status: Accepted

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

ans1, ans2 = 999, 999
for i in range(x, x + 200, 1):
  if not i in p_list:
    ans1 = i
    delta1 = abs(i - x)
    break
  
for j in range(x, x - 200, -1):
  if not j in p_list:
    ans2 = j
    delta2 = abs(j - x)
    break 

if delta1 > delta2:
  print(ans2)
elif delta1 < delta2:
  print(ans1)
else:
  print(min(ans1, ans2))

Submission status: Accepted

Solution code:
def main():
    x,n = map(int,input().split())
    if n>0:
        p = list(map(int,input().split()))
    else:
        p = []
    d = [i for i in range(0,102)]
    for i in range(len(d)):
        if d[i] in p:
            d[i] = -1
    d = sorted(d)
    m = 10000
    ans = 0
    for i in range(len(d)):
        if d[i]==-1:
            continue
        if m>abs(d[i]-x):
            m = abs(d[i]-x)
            ans = d[i]
    print(ans)

if __name__ == "__main__":
    main()