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:
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    read = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    read = raw_input
readint = lambda: int(rr())
readlist = lambda: map(int, read().split())

####
def solve((X, N), A):
    Aset = set(A)
    ans = 1234
    for p in range(102):
        if p not in Aset:
            d = abs(p - X)
            if d < ans:
                ans = d
                ansi = p
    return ansi

print solve(readlist(), readlist())

Submission status: Accepted

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

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

best = (10 ** 18, 0)

for i in range(102):
	if i not in P:
		best = min(best, (abs(X - i), i))

print(best[1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007
INF = float('inf')

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x
    
def main():
    x,n = [int(x) for x in stdin.readline().rstrip().split()]
    
    if n == 0:
        print(x)
    else:
        table = [i - 1 for i in range(103)]

        target = INF
        p = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
        for i in range(len(p)):
            table.remove(p[i])
        for i in range(len(table)):
            target = min(target,abs(x-table[i]))
        ans_a = x-int(target)
        ans_b = x+int(target)
        if ans_a in table:
            print(ans_a)
        else:
            print(ans_b)
        
main()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
elif N == 100:
    if X <= 50:
        print(0)
    else:
        print(101)

else:
    p = list(map(int, input().split()))
    abs_list = []
    re_list = []
    min = 1000
    min_index = 0

    for i in range(250):
        abs_list.append(-100+i)
    for j in p:
        abs_list.remove(j)
    for i in range(len(abs_list)):

        re_list.append(abs(abs_list[i] - X))
    for i in range(len(re_list)):
        if min > re_list[i]:
            min = re_list[i]
            min_index = i
    if re_list[min_index] > X:
        print(0)
    else:
        print(abs_list[min_index])

Submission status: Accepted

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

Submission status: Accepted

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

diff = 1000
ans = x
for i in range(-300, 300):
    xx = x + i
    if abs(i) < diff and xx not in p:
        ans = xx
        diff = abs(i)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

P2 = []

for i in range(0, 102):
    if i in P:
        continue
    P2.append(i)
sa = 10**9
ret = -1
for p in P2:
    if abs(X-p) < sa:
        sa = abs(X-p)
        ret = p

print(ret)

Submission status: Accepted

Solution code:
tmp = list(map(int, input().split()))
x = tmp[0]
n = tmp[1]
if n == 0:
    print(x)
    exit()

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

i = 0

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

Submission status: Accepted

Solution code:
x,n,*p=map(int,open(0).read().split())
p=set(p)
l=r=x
while 1:
  if l not in p: print(l); break
  l-=1
  if r not in p: print(r); break
  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()

s = 1000000000

for i in range(-100,102):
    if i in p:
        continue
    s = min(abs(x-i),s)
    

if not x-s in p:
    print(x - s)
else:
    print(x + s)

Submission status: Accepted

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

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

f = [1]*200
sa = x
ans = 0

for i in p:
    f[i-1] = 0

for i in range(200):
    if f[i] == 1 and sa > abs(i+1-x):
        sa = abs(i+1-x)
        ans = i+1

print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
 
ans = X
for i in range(101):
    a = X + i
    b = X - i
    if a not in P:
        ans = a
        if b not in P:
            ans = b
        break
    if b not in P:
        ans = b
        break
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()))
    for i in range(1000):
        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:
X, N = map(int,input().split())
if N == 0:
    print(X)
    exit()
else:
    P = list(map(int,input().split()))
L = [i for i in range(0,102) if i not in P]

if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    if (L[n+1]-L[n] < L[n] - L[n-1]):
        ANS = L[n+1]
    else:
        ANS = L[n - 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(" ")))

    p_under = list(filter(lambda v: v<=x, p))
    p_upper = list(filter(lambda v: v>=x, p))
    p_under.sort(reverse=True)
    p_upper.sort()

    cnt = 0
    while(True):
        if x - cnt not in p_under:
            print(x - cnt)
            break
        if x + cnt not in p_upper:
            print(x + cnt)
            break
        cnt += 1

Submission status: Accepted

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

for _ in range(300):
    if X - dif not in P:
        print(X - dif)
        exit()
    elif X + dif not in P:
        print(X + dif)
        exit()

    else:
        dif += 1

Submission status: Accepted

Solution code:
import sys
x,n = map(int, input().split())
if n == 0:
  print(x)
  sys.exit()
else:
  p = input().split()
  p1 = [int(i) for i in p]
  if x not in p1:
    print(x)
  else:
    for c in range(1,n+1):
      u = x + c
      d = x - c
      if d not in p1:
        print(d)
        sys.exit()
      elif u not in p1:
        print(u)
        sys.exit()

Submission status: Accepted

Solution code:

def nears_impl(x, dis, is_minus):
    def cal(x, dis):
        if is_minus:
            r = x - dis
            return r
        else:
            r = x + dis
            return r

    res = cal(x, dis)
    return res


def nears(start_x):
    yield start_x
    i = 1
    while True:
        yield nears_impl(start_x, i, True)
        yield nears_impl(start_x, i, False)
        i += 1


x, n = [int(x) for x in input().split(" ")]
    
if n == 0:
    print(x)
    exit()

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

for near in nears(x):
    if near not in p:
        print(near)
        break

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
if N == 0:
    print(X)
    exit()
else:
    P = list(map(int,input().split()))
L = [i for i in range(0,102) if i not in P]

if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    l = len(L) - 1


    if (0 < n < l):
        if (L[n+1]-L[n] < L[n] - L[n-1]):
            ANS = L[n+1]
        else:
            ANS = L[n - 1]
    elif (n == l):
        ANS = L[l - 1]

print(ANS)

Submission status: Accepted

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

D = 10000
res = 0
for i in range(-100,200):
  if i in P:
    continue
  X2 = abs(X-i)
  if X2 < D:
    D = X2
    res = i
#
print(res)

Submission status: Accepted

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

if X not in nums:
  print(X)
  exit(0)

diff_dict = {}
for n in nums:
  diff = abs(X - n)
  if diff in diff_dict.keys():
    diff_dict[diff].append(n)
  else:
    diff_dict[diff] = [n]

keys = list(diff_dict.keys())
keys.sort()

for i in range(1, max(keys)+2):
  if i not in keys:
    print(X - i)
    break
  else:
    targets = diff_dict[i]
    length = len(targets)
    if length > 1:
      continue
    else:
      t = targets[0]
      print(X - i if t > X else X + i)
      break

Submission status: Accepted

Solution code:
import sys
L = []
for l in sys.stdin:
    L.append(l)
X, N = map(int, L[0].split())
p_N_list = map(int, L[1].split())

def calc_sub(n):
    return n - X

sub =  map(calc_sub, p_N_list)
abs_sort = sorted(sub, key=abs)

num = 0
check = 1
while(check):
  if (- num) not in abs_sort:
    print(X - num)
    check = 0
  elif num not in abs_sort:
    print(X + num)
    check = 0
  else:
    num += 1

Submission status: Accepted

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

for i in range(0,101):
    if (X-i in p) == False: # pの中にX-iは無い場合
        print(X-i)
        break
    elif (X+i in p) == False: # pの中にX+iは無い場合
        print(X+i)
        break

Submission status: Accepted

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

if X not in p:
    print(X)
else:
    for i in range(1, 101):
        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()))
if N > 0:
    P = list(map(int, input().split()))
    l = X
    h = X
    while True:
        if l not in P:
            print(l)
            break
        if h not in P:
            print(h)
            break
        l -= 1
        h += 1
else:
    input()
    print(X)

Submission status: Accepted

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

for i in range(-10, 200):
    if i not in p:
        q.append(i)

ans = 1000000

for i in q:
    if abs(x - ans) > abs(x - i):
        ans = i
    elif abs(x - ans) == abs(x - i):
        if i < ans:
            ans = i

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
# elif x==1 and n==1:
#     lst=list(map(int,input().split()))[:n]
#     print(lst[0]-1)
# elif 
else:
    lst=list(map(int,input().split()))[:n]
    for j in range(1,100000):
        x1=abs(abs(x)+abs(j))
        x2=abs(abs(x)-abs(j))
        if x not in lst:
            print(x)
            break
        if x2 not in lst:
            print(x2)
            break
        elif x1 not in lst:
            print(x1)
            break
        else:
            continue

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P=list(map(int, input().split()))
A=[]
A.append(X)
if N==0:
   print(X)
else:
   for i in range(N+1):
      A.append(X+(1+(i//2))*(-1)**(i+1))
   for i in range(N+1):
      if A[i] not in P:
         ans=A[i]
         print(ans)
         break

Submission status: Accepted

Solution code:
[X, N] = list(map(int, input().split()))
A = []
try:
  P = list(map(int, input().split()))
  list_int = [x for x in range(0, 102)]
  list_int_d = list(set(list_int) - set(P))
  list_int_d.sort()
  for i in list_int_d:
    A.append(abs(X - i))
  if 0 in A:
    print(X)
  else:
    Index = A.index(min(A))
    print(list_int_d[Index])
except EOFError:
  print(X)

Submission status: Accepted

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

S=[i for i in range(-1,102)]

for j in range(N):
    S.remove(A[j])
    
n=1000  
x=0
for k in S:
    if abs(k - X) < n:
        n=abs(k - X)
        x=k
    elif n == abs(k - X):
        x=min(x,k)
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()))
  p.append(0)
  while True:
    if p[n]%2==1:
      s = x-((p[n]+1)/2)
      #print(s,"こ")
    else:
      s = x+(p[n]/2)
      #print(s,"ここ")
    if s not in p:
      print(int(s))
      break
    else:
      p[n]+=1

Submission status: Accepted

Solution code:
a,b= map(int,input().split())
N = list(map(int,input().split()))
S =[]
key = 0
while(1):
	if a-key in N:
		if a +key in N:
			key +=1
		else:
			print(a+key)
			break
		
	else:
		print(a-key)
		break

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
if n != 0:
  p = list(map(int,input().split()))
p_change = []
m = 0
if n == 0:
  print(x)
else:
    for i in p:
        p_change.append(abs(i-x))
 
    if x in p:
        for i in range(n+1):
            if i != 0 and p_change.count(i) != 2:
                m = i
                break
        if x-m in p:
            print(x+m)
        else:
            print(x-m)
    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()))
    m=10000
    ans=N
    for i in range(-101,101):
        if m>abs((i+1)-X) and not i+1 in p:
            m=abs((i+1)-X)
            ans=i+1
    print(ans)

Submission status: Accepted

Solution code:
import math
def main():
    x, n = map(int, input().split())
    if n==0:
        out = x
    else:
        p_l = [int(_) for _ in input().split()]

        c_l = []
        for i in range(-101, 105):
            c_l.append(i)
        
        for p in p_l:
            if p in c_l:
                c_l[c_l.index(p)]=1000
        
        abs_c_l = []
        for i in range(-101, 105):
            abs_c_l.append(i)

        for i, c in enumerate(c_l):
            abs_c_l[i] = abs(c_l[i] - x)
        
        m = min(abs_c_l)
        out = c_l[abs_c_l.index(m)]
        
    print(out)

main()

Submission status: Accepted

Solution code:
X, Y = map(int, input().split())
if Y == 0:
    answer = X
else:
    list_1 = list(map(int, input().split()))

    mylist = list(range(-100, 200))

    list_2 = list(filter(lambda x: x not in list_1, mylist))
    
    list_3 = list(map(lambda x: x - X, list_2))

    import numpy as np

    abslist = np.abs(list_3)

    min_num = min(abslist)

    answer_lisbef = [X - min_num, X + min_num]
    
    answer_lisaf = list(filter(lambda x: x not in list_1, answer_lisbef))
    
    answer = min(answer_lisaf)
print(answer)

Submission status: Accepted

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

n = X
i = 1

while 1 <= i:
    if n in p:
        if i % 2 == 0:
            n += i
        else:
            n -= i   
    else:
        print(n)
        break
    i += 1

Submission status: Accepted

Solution code:
x,n,*p=map(int,open(0).read().split())
if n==0:
    print(x)
else:
    q=[i for i in range(102) if not(i in p)]
    m=[]
    for j in q:
        m.append(abs(j-x))
    a,b=x-min(m),x+min(m)
    if a in q:
        print(a)
    else:
        print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
x, N = map(int, input().split())

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

i = 0            
while True:
    a = x - i
    b = x +i
    if not a in num_list:
        min_num = a
        break
    elif not b in num_list:
        min_num = b
        break
    else:
        i += 1
            
print(min_num)

Submission status: Accepted

Solution code:
X,N=list(map(int,input().split()))
if N>0:p=list(map(int,input().split()))
else:p=[]
memo=[False for i in range(105)]
for i in range(N):memo[p[i]]=True


riget=X+1
left=X-1
ans_r=0
ans_l=0

while(True):
    if memo[X]==False:
        ans_r=X
        break
    
    if memo[riget]==False:
        ans_r=riget
        break
    riget+=1
    
while(True):
    
    if memo[X]==False:
        ans_l=X
        break
    
    if memo[left]==False:
        ans_l=left
        break
    left-=1
    
if N==0:print(X)
elif abs(X-ans_r)>=abs(X-ans_l):print(ans_l)
else:print(ans_r)

Submission status: Accepted

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

cand = []
for i in range(102):
    if i in p:
        continue
    else:
        cand.append(abs(i-x))
q = min(cand)
print(x-q if x-q not in p else x+q)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
try:
  list_  = list(map(int, input().split()))
except:
  print(X)

else:
    for i in range(0, 101):
        if not (X-i) in list_:
            print(X-i)
            break
        
        elif not(X+i) in list_:
            print(X+i)
            break

Submission status: Accepted

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

dl=[abs(x-i) for i in p]


for i in range(101):
    c=dl.count(i)

    if i==0:
        if c==1:
            continue
        else:
            print(x)
            exit()

    if c==0:
        print(x-i)
        exit()
    elif c>=2:
        continue
    else:
        b=dl.index(i)
        print(x-(p[b]-x))
        exit()

Submission status: Accepted

Solution code:
s = input().split()
intX = int(s[0])
intN = int(s[1])
inList = list(map(int,input().split()))

iCnt = 101
minDiv = 101
rCnt = -2
div = 0
while iCnt > -2 :
    if (inList.count(iCnt) == 0) : 
        div = abs(intX - iCnt)
        if (minDiv >= div) :   
            minDiv = div
            rCnt = iCnt
    iCnt -= 1
print(rCnt)

Submission status: Accepted

Solution code:
import os
import sys
from io import BytesIO, IOBase
import math
def inputIntArray():
    return list(map(int, input().rstrip().split()))


def inputArray():
    return input().rstrip().split()


def inputVars():
    return map(int, input().rstrip().split())


def inputNum():
    return int(input())


def main():
    x, n = inputVars()
    if n == 0:
        print(x)
        return
    arr = inputIntArray()
    minRes = x
    if x not in arr:
        print(x)
        return
    minRes = float('inf')
    # arr.sort()
    for num in range(-1, 110):
        if num not in arr:
            minRes = num if abs(num - x) < abs(x - minRes) else minRes
    print(minRes)


#.........................................FAST INPUT OUTPUT.......................................
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#....................................END OF FAST I/O............................................

if __name__ == "__main__":
    main()

Submission status: Accepted

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

    target_abs = [0]*100

    for i in range(n):
        if abs(p[i]-x) >= 100:
            continue
        elif p[i]-x > 0:
            target_abs[abs(p[i]-x)] += 1
        else:
            target_abs[abs(p[i]-x)] += 2

    ans = 1000000
    for i in range(100):
        if i == 0:
            if target_abs[i] == 0:
                ans = x
        elif ans == 1000000:
            if target_abs[i] == 0:
                ans = x - i
            elif target_abs[i] == 1:
                ans = x - i
            elif target_abs[i] == 2:
                ans = x + i
    print(ans)

Submission status: Accepted

Solution code:
from sys import stdin, stdout
import sys
INF=1e9
import bisect
def get_int(): return int(stdin.readline().strip())
def get_ints(): return map(int,stdin.readline().strip().split()) 
def get_array(): return list(map(int,stdin.readline().strip().split()))
def get_string(): return stdin.readline().strip()
def op(c): return stdout.write(c)
#from collections import defaultdict 
#for _ in range(int(stdin.readline())):
x,n=get_ints()
p=get_array()
if n==0:
    print(x)
else:
    diff1=INF
    ans=0
    for i in range(-101,102):
        if i not in p:
            diff=abs(i-x)
            if diff<diff1:
                diff1=diff
                ans=i
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

p.sort()

minimum = p[0]
maximum = p[len(p) - 1]

if X < minimum or maximum < X:
    print(X)
    exit()

diff_min = abs(X - minimum - 1)
diff_max = abs(X - maximum + 1)
if diff_min == diff_max:
    answer = min(minimum - 1, maximum + 1)
else:
    answer = minimum - 1 if diff_min < diff_max else maximum + 1

for candidate in range(0, 100 + 2):
    if candidate in p : continue

    diff_candidate = abs(X - candidate)
    diff_answer = abs(X - answer)

    if diff_candidate == diff_answer:
        answer = min(candidate, answer)
    elif diff_candidate < diff_answer:
        answer = candidate

print(answer)

Submission status: Accepted

Solution code:
import numpy as np
X, N = list(map(int, input().split()))
try:
	p = np.array(list(map(int, input().split())))
except EOFError:
    print(X)
    exit()
I = np.arange(0, 102)
indices = np.argsort(np.abs(I - X), kind='stable')
for idx in indices:
    if I[idx] not in p:
        print(I[idx])
        break

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
Pli = set(sorted(P))
X1 = X
X2 = X
while True:
    if X1 not in Pli:
        print(X1)
        break
    elif X2 not in Pli:
        print(X2)
        break
    else:
        X1 -= 1
        X2 += 1

Submission status: Accepted

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

if (int(n)>0):
  add = 1
  count = 3
  p = list(map(int,input().split()))

  if (int(x) not in p):
    print(int(x))
    count=1


  while (count==3):
    count = 0
    for i in range(int(n)):
      if (abs(int(p[i])-int(x)) == add):
        count = count+1
    if (count==2):
        add = add+1
        count=3
    if (count==1):
      if (int(x)-add in p):
        print(int(x)+add)
      else:
        print(int(x)-add)
    if (count==0):
      print(int(x)-add)
else:
  print(int(x))

Submission status: Accepted

Solution code:
def main():
    import copy

    num, quantity = map(int, input().split())
    nums = list(map(int, input().split()))
    nums.sort()
    
    if quantity == 0:
        print(num)
        return
    
    i = 0

    minus_num = copy.copy(num)
    plus_num = copy.copy(num)

    while i < len(nums):
        if num not in nums:
            print(num)
            return
        
        if minus_num not in nums:
            print(minus_num)
            return
        
        if plus_num not in nums:
            print(plus_num)
            return
        
        minus_num = minus_num - 1
        plus_num = plus_num + 1

main()

Submission status: Accepted

Solution code:
x, n = [int(i) for i in input().split()]
arr = [int(j) for j in input().split()]
if x not in arr:
	print(x)
else:
	xl = x
	xr = x
	count = 0
	while True:
		if count % 2 == 0:
			xl -= 1
			if xl not in arr:
				print(xl)
				break
		else:
			xr += 1
			if xr not in arr:
				print(xr)
				break
		count += 1

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    l = [k for k in range(102)]
    for p in input().split():
        p = int(p)
        l[p] = 1000
    l_d = [x-k for k in l]
    l_sorted = sorted(l_d,key= lambda x: (-x+0.1, x)[x > 0])
    print(x-l_sorted[0])

Submission status: Accepted

Solution code:
x, n = [int(i) for i in input().split()]
if n > 0:
  p = [int(i) for i in input().split()]
  x1 = x
  while True:
    if x1 not in p:
      a = x1
      break
    else:
      x1 -= 1
  x1 = x
  while True:
    if x1 not in p:
      b = x1
      break
    else:
      x1 += 1
  if abs(x-b) < abs(x-a):
    print(b)
  elif abs(x-a) < abs(x-b):
    print(a)
  else:
    print(a) if a<b else print(b)
else:
  print(x)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())))

if p.count(x) == 0:
    print(x)
else:
    ans_large = x
    ans_small = x
    cycle = 1
    while ans_large == x and ans_small == x:
        # 負の方向
        if p.count(x - cycle) == 0:
            ans_small -= cycle
            break
        # 正の方向
        if p.count(x + cycle) == 0:
            ans_large += cycle
            ans_small = 101 # smallを範囲から外す
        cycle += 1
    print(min(ans_large, ans_small))

Submission status: Accepted

Solution code:
import numpy as np
X,N = map(int, input().split())
p = list(map(int, input().split()))
p = sorted(p)
lista = list(range(-100,200))
for i in p:
    if i in lista:
        lista.remove(i)
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    print(list[idx])
if N == 0:
    print(X)
else:
    getNearestValue(lista, 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)
    sys.exit()

comp = 101
for i in range(102):
    x = abs(X - i)
    if comp > x and i not in p:
        comp = x
        result = i

print(result)

Submission status: Accepted

Solution code:
def main():
    X, N = map(int, input().split())
    pList = list(map(int, input().split()))

    minusX = X
    plusX = X

    while True:

        if(minusX not in pList):
            print(minusX)
            return

        if(plusX not in pList):
            print(plusX)
            return
        
        minusX = minusX - 1
        plusX = plusX + 1
        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
X, N=map(int,input().split())
if N==0:
  print(X)
  exit()
  
else:
  P=sorted(map(int, input().split()))
  
if P.count(X)==0:
  print(X)
  exit()
  
for n in range(N+30):
  if P.count(X-n)==0:
    print(X-n)
    exit()
  elif P.count(X+n)==0:
    print(X+n)
    exit()

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
if a[1] == 0:
  print(a[0])
else:
  b = list(map(int,input().split()))
  min_num = a[0]
  min_p = a[0]
  m = 1
  ans = a[0]
  # そーとする
  # abs(a[0]-p1)がabs(a[0]-p2)より小さいならp1を保持。大きいならp2に更新。
  for i in set(b):
    if min_num >= abs(a[0]-i):
      min_p = i
      min_num = abs(a[0] - min_p)
  # 全て繰り返すとまずbのなかで一番近い値が出てくる。
      #下記をm回繰り返す
  # pn - mがset(b)にあるか確認
      #なければbreak,pn-1がans
  # pn + mがset(b)にあるか確認
      #なければbreak,pn+1がans
  while True:
    if (min_p - m) not in set(b):
      ans = min_p - m
      break
    elif (min_p + m) not in set(b):
      ans = min_p + m
      break
    m += 1
  print(ans)

Submission status: Accepted

Solution code:
def search_prev(X, P):
    while X >= min(P):
        if not P.__contains__(X):
            return X
        else:
            X -= 1
    return X


def search_next(X, P):
    while X <= max(P):
        if not P.__contains__(X):
            return X
        else:
            X += 1
    return X


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

    if N == 0:
        print(X)
        return

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

    xp = search_prev(X, P)
    dxp = X - xp
    xn = search_next(X, P)
    dxn = xn - X

    if dxp <= dxn:
        print(xp)
    else:
        print(xn)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def nearest(x,ar):
  i=0;t=x
  while t in ar:
    t-=1
  v=t
  t=x
  while (t in ar):
    t+=1
  if x-v>t-x:return t
  else: return v
  

def main():
  x,n=map(int,input().split())
  if n==0:
    print(x)
  else:
    ar=list(map(int,input().split()))
    print(nearest(x,ar))
main()