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:
def resolve():
	X, N = map(int, input().split())
	if N == 0:
		print(X)
	else:
		A = list(map(int, input().split()))

		for i in range(100):
			Y = X-i
			if Y not in A:
				print(Y)
				break
			Y = X+i
			if Y not in A:
				print(Y)
				break
resolve()

Submission status: Accepted

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

ans = 0

max_ = 0
min_ = 0

# 増える側
for i in range(x, 102, 1) :

    # print('i+')
    # print(i)

    if i not in p_list:
        # print('確定')
        max_ = i
        break

# 減る側
for j in reversed(range(x + 1)) :

    # print('j-')
    # print(j)

    if j not in p_list:
        # print('確定')
        min_ = j
        break

# print('min')
# print(min_)
# print('max')
# print(max_)


# print(abs (x - min_))
# print(abs (x - max_))

if abs (min_ - x) <= abs(max_ - x) :
    ans = min_
else : 
    ans = max_

print(ans)

Submission status: Accepted

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

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

x = X
while x in P:
  x -= 1

minX = x

x = X
while x in P:
  x += 1
maxX = x

if abs(minX - X) <= abs(maxX - X):
  print(minX)
else:
  print(maxX)

Submission status: Accepted

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

for i in range(101):
    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())
P = list(map(int,input().split()))+[float("inf")]
P.sort()
k = 0
ans = 1000
for i in range(-100,102):
    if i == P[k]:
        k += 1
        continue
    if abs(i - X) < abs(ans - X):
        ans = i
print(ans)

Submission status: Accepted

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

arr = []

if n == 0:
    print(x)
else:
    tmp = input()
    num = tmp.split(' ')
    num_li = [int(i) for i in num]
    arr.extend(num_li)
    min = x
    max = x

    for i in range(10000):

        if min not in arr:
            print(min)
            break

        if max not in arr:
            print(max)
            break
                
        min -= 1
        max += 1

Submission status: Accepted

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

if N==0:
  print(X)

else:
  P = list(map(int,input().split()))
  if X not in P:
    print(X)
  
  else:
      a = X+1
      b = X-1
      
      while a in P:
        a+=1
      while b in P:
        b-=1
      
      if abs(X-a)<abs(X-b):
        print(a)
      else:
        print(b)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  numbers=list(range(102))
  ans=0

  for i in range(len(p)):
    numbers.remove(p[i])

  if numbers.count(X)==1:
    print(X)
  else:
    for j in range(100):
      if numbers.count(X-j)==1:
        ans=X-j
        break
      elif numbers.count(X+j)==1:
        ans=X+j
        break
    print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input(). split())
p = list()
if n > 0:
  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 = list(map(int, input().split()))
print(min([i for i in range(0, 102) if i not in p],
          key=lambda i: (abs(X - i), i)))

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n==0:
  print(x)
else:
    l1 = list(map(int,input().split()))	
    l2 = list(range(-150, 200))
    diff = set(l1) ^ set(l2)
    diff = list(diff)
    def sorting(numbers_array):
      return sorted(numbers_array, key=abs)
    sl = map(lambda a: a - x, diff)
    print(sorting(sl)[0]+x)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
minn = 10000000
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))
for i in range(1000):
    if i not in p:
        tmp = abs(x-i)  
        if minn > tmp:
            ans = i
            minn = tmp
        elif minn == tmp:
            ans = min(i, ans)
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
a = 0
ans = ''
while ans == '':
  if len(p) == 0:
    ans = x
  elif x - a not in p:
    ans = x - a
  elif x + a not in p:
    ans = x + a
  else:
    a += 1
print(ans)

Submission status: Accepted

Solution code:
import sys

(x, n) = map(int, sys.stdin.readline().strip().split())
list_input = list(map(int, input().split()))

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

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

Submission status: Accepted

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

for i in range(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 = map(int, input().split())
if N == 0:
    print(X)
    exit(0)

p = set(map(int,input().split()))
not_p = list(set(range(0,102)) - p)

minV = 101
ans = 0
for i in not_p:
    if abs(X - i) < minV:
        minV = abs(X - i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
P=set(map(int,input().split()))
d=float('inf')
ans=0
for i in range(102):
    if i in P:
        continue
    tmp=abs(x-i)
    if tmp<d:
        ans=i
        d=tmp
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
a = [int(x) for x in input().split()]
b = [i for i in range(0,102) if i not in a] 
b_tmp = list(map(lambda s:abs(s-x), b)) 
address = b_tmp.index(min(b_tmp))
print(b[address])

Submission status: Accepted

Solution code:
import sys

def saiki(l,r,lst):
  if (l - 1) not in lst:
      return (l - 1)
  
  if (r + 1) not in lst:
      return (r + 1)
  
  return saiki(l - 1, r + 1, lst)

def main():
  # Xはもっとも近い整数，Nは与えられるP
  X,N = map(int, input().split())

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

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

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

  print(saiki(X,X,arr))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

arr = []

if n == 0:
    print(x)
else:
    tmp = input()
    num = tmp.split(' ')
    num_li = [int(i) for i in num]
    arr.extend(num_li)

    for i in range(10000):

        if x - i not in arr:
            print(x - i)
            break

        if x + i not in arr:
            print(x + i)
            break

Submission status: Accepted

Solution code:
import numpy as np
X, N = list(map(int,input().split()))
if N == 0:
  print(X)
else:
  p_arr = list(map(int,input().split()))
  for i in range(101):
    if i == 0:
      if not (X in p_arr):
        print(X)
        break
    else:

      lower = (X-i in p_arr)
      upper = (X+i in p_arr)
      if not lower:
        print(X-i)
        break
      else:
        if not upper:
          print(X+i)
          break

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
 
anskouho = []
if p:
    val = []
    for i in range(-200,200):
        if i not in p:
            anskouho.append(i)
    for i in anskouho:
        val.append(abs(x - i))
    if x - min(val) not in p:
        print(x - min(val))
    else:
        print(x + min(val))
else:
    print(x)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N == 0:
    print(X)
else:
    array = list(map(int, input().split()))
    answer = -114514
    for i in range(-200,200):
        ok = True
        for v in array:
            if v == i:
                ok = False
                break
        if ok is False:
            continue
        if abs(answer-X) > abs(i-X):
            answer = i
    print(answer)

Submission status: Accepted

Solution code:
import sys
X,N=list(map(int,input().split()))
P=list(map(int,input().split()))
if not X in P:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    if not A in P:
        print(A)
        sys.exit()
    if not B in P:
        print(B)
        sys.exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
delta = 0
state_n = 0
state_p = 0
while True:
  ans_n = x - delta
  ans_p = x + delta
  for i in range(len(p)):
    if ans_n == p[i]:
      state_n = 1
    if ans_p == p[i]:
      state_p = 1
  if state_n == 0 and state_p == 0:
    ans = ans_n
    break
  if state_n == 1 and state_p == 1:
    state_n = 0
    state_p = 0
  elif state_p == 1:
    ans = ans_n
    break
  elif state_n == 1:
    ans = ans_p
    break
  delta = delta + 1

print(ans)

Submission status: Accepted

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

    min_num = sorted_p[0]
    max_num = sorted_p[-1]

    candidate_list = []
    no_flag = 0
    candidate_num = -1
    distance = 10000

    for cnt in range(0, 102):
        no_flag = 0
        for nums in range(n):
            if cnt == sorted_p[nums]:
                no_flag = 1

        if no_flag == 0:
            candidate_list.append(cnt)

    for cnt in range(len(candidate_list)):
        if abs(x - candidate_list[cnt]) < distance:
            candidate_num = candidate_list[cnt]
            distance = abs(x - candidate_num)

    print(candidate_num)

else:
    print(x)

Submission status: Accepted

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

P.sort()
ans = abs(10000000)
for i in range(-101, 102):
  if not i in P:
    ans = min(ans, abs(i-X))

if not X-ans in P:
  print(X-ans)
else:
  print(X+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(101):
    if not x-i in p:
      print(x-i)
      break
    elif not x+i in p:
      print(x+i)
      break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = list(map(int, input().split()))
if k[1] == 0:
  print(k[0])
else:
  l = list(map(int, input().split()))
  a = [i for i in range(102) if not i in l]
  m = []
  for i in a:
    m.append(abs(i - k[0]))
  print(a[m.index(min(m))])

Submission status: Accepted

Solution code:
if __name__=="__main__":
    # Problem C
    X, N = map(int, (input().split(' ')))
    if N > 0:
        P = sorted(map(int, input().split(' ')))
        P_max = max(P)
        P_min = min(P)
        if X in P:
            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
        elif X not in P:
            print(X)
    else:
        print(X)

Submission status: Accepted

Solution code:
x, n = map(int, input(). split())
p = list(map(int, input(). split()))
if x not in p:
  print(x)
else:
  d = 1
  for i in range(1, 100):
    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:
def linked_merge_sort(l): #マージソート
    if len(l) == 1:
        return
    q, r = divmod(len(l), 2)
    left = [l.pop() for _ in range(q)]
    right = [l.pop() for _ in range(q + r)]
    
    linked_merge_sort(left)
    linked_merge_sort(right)
    
    left.reverse()
    right.reverse()
    while left and right:
        if left[-1] <= right[-1]:
            l.append(left.pop())
        else:
            l.append(right.pop())
    while left:
        l.append(left.pop())
    while right:
        l.append(right.pop())
    return

x,n=map(int,input().split())
p=list(map(int,input().split()))
if x>50:
    ans = 101
else:
    ans = 0
for i in range(n):
    p[i]=p[i]-x
if n>1:
    linked_merge_sort(p)
    j=n-1
    for i in range(n):
        if p[i]>=0:
            j=i
            break
    for i in range(n):
        if j-i>=0:
            if p[j-i]!=-i:
                ans = x-i
                break
        elif j-i<0:
            ans=x+p[0]-1
            break
        if j+i<n:
            if p[j+i]!=i:
                ans = x+i
                break
        else:
            ans=x+p[n-1]+1
            break
elif n==1:
    if p[0]==0:
        ans=x-1
    else:
        ans=x
elif n==0:
    ans=x
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(N+1):
    a = X+i
    b = X-i
    if b not in p:
        ans = b
        break
    elif a not in p:
        ans = a
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
X,N = (int(i) for i in input().split())
if N !=0:
    p = list(map(int, input().split()))
elif N ==0:
    p=[-1]
p.sort()
#
ans =[]
for i in range(-1,102):
    if i not in p:
        ans.append((abs(i-X),i))
ans.sort()
print(ans[0][1])

Submission status: Accepted

Solution code:
def readInts():
 return list(map(int, input().split()))

def main():
  a = input()
  a =a.split(" ")
  x = int(a[0])
  n = int(a[1])
  if n == 0:
    print(x)
    return
    
  p = readInts()
  i= x 
  j = x + 1
  
  while i  in p:
    i -=1
    
  while j  in p:
    j += 1
 
  if abs(x-i) <= abs(x-j):
    print(i)
  else:
    print(j)
  
  
if __name__ == "__main__":
  main()

Submission status: Accepted

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

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

if x not in p:
    print(x)
    exit()
    
for i in range(len(p)):
    #print(p[i])
    if p[i] == x:
        index = i
        break

right = x + 1
for i in p[index + 1:]:
    if i != right:
        break
    right += 1

left = x - 1
for i in reversed(p[:index]):
    if i != left:
        break
    left -= 1

if x - left <= right - x:
    print(left)
else:
    print(right)

Submission status: Accepted

Solution code:
x, n = map(int, input(). split())
p = list(map(int, input(). split()))
if x not in p:
  print(x)
else:
  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())
u = 100
num_str=input().split()
s=list(map(int, num_str))
m  = list(range(-100,200)) 
for k in s:
    m.remove(k)
for l in m:
    a = l - x
    if abs(u) > abs(a):
        u = a
print(u+x)

Submission status: Accepted

Solution code:
s = {i+1 for i in range(-101,101)}
#print(s)
x, n =map(int,input().split())
 
if n == 0:
  print(x)
  exit()
  
il = list(map(int,input().split()))
 
for i in range(n):
  s.discard(il[i])
s = list(s)
s.sort()
#print(s)
 
absmin = 10000000
ans = 0
 
for i in range(len(s)):
  j = abs(x-int(s[i]))
  if j < absmin:
    ans = s[i]
    absmin = j
    if j == 0:
      break
 
print(ans)

Submission status: Accepted

Solution code:
#C
X,N = map(int,input().split())
p = list(map(int,input().split()))
r = 101
for i in range(101,-1,-1):
    if i in p:
        pass
    else:
        if abs(r-X) >= abs(i-X):
            r = i
print(r)

Submission status: Accepted

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

def create_full_array(minimum, maximum):
    full_list = []
    for i in range(minimum,maximum+1):
        full_list.append(int(i))
    return full_list

if n == 0:
    print(x)
elif x > max(p_a) + 1 or x < min(p_a):
    ans = x - 1
    print(ans)
elif x == max(p_a) + 1:
    ans = x + 1
    print(ans)
else:
    full_array = create_full_array(min(p_a), max(p_a))
    if x in p_a:
        target_list = list(set(p_a)^set(full_array))
        abs_key = {}
        if len(target_list) == 0:
            if abs(x - min(p_a)) <= abs(x - max(p_a)):
                print(min(p_a) - 1)
            else:
                print(max(p_a) + 1)
        else:
            for i in target_list:
                abs_key[i] = abs(x-i)
            minimum = min(abs_key.values())
            t_k = []
            t_v = []
            [t_k.append(k) for k, v in abs_key.items() if v == minimum]
            print(min(t_k))

    else:
        print(x)

Submission status: Accepted

Solution code:
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(x)

        value_left=x-1
        value_right=x+1

        if index!=0:
            index_left=index-1
        if index!=n-1:
            index_right=index+1
        
        if index==0:
            ans=x-1
        elif index==n-1:
            if num_list[index-1]==x-1:
                ans=x+1
            else:
                ans=x-1
        else:
            for i in range(n):
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                elif num_list[index_right]!=value_right:
                    ans=value_right
                    break
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n:
                    index_right=index_right+1
                value_left=value_left-1
                value_right=value_right+1

if n==1:
    ans=x-1

if n==100:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    else:
        p = [int(i) for i in input().split()]

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

resolve()

Submission status: Accepted

Solution code:
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
list_p = [i for i in range(-1, 102)] 
t = x
num = x

for i in p:
  list_p[i + 1] = -2

for i in range(len(list_p)):
  if(list_p[i] == -2):
    continue
  else:
    if(abs(list_p[i] - x) <= t):
      if(abs(list_p[i] - x) < t):
        t = abs(list_p[i] - x)
        num = list_p[i]
      elif(abs(list_p[i] - x) == t):
        t = abs(list_p[i] - x)
        num = min(num, list_p[i])
print(num)

Submission status: Accepted

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


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

r=0
while True:
  if X-r not in p:
    print(X-r)
    exit()
  elif X+r not in p:
    print(X+r)
    exit()
  else:
    r+=1

Submission status: Accepted

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

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	x, n = map(int, sys.stdin.readline().split())
	p = list(map(int, sys.stdin.readline().split()))
	p.sort()
	i = x - 1
	lower = 0
	while i >= 0:
		if not i+1 in p:
			lower = i+1
			break
		i -= 1
	i = x - 1
	upper = 101
	while i <= 101:
		if not i+1 in p:
			upper = i+1
			break
		i += 1
	if abs(x - lower) == abs(x - upper):
		print(lower)
	elif abs(x - lower) < abs(x - upper):
		print(lower)
	else:
		print(upper)

main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = []
sortlist = []
if n == 0:
    print(x)
else:
    p.sort()
    p1 = p[0]
    pn = p[n-1]
    new = [i for i in range(0, 102)]
    nolist = set(new) ^ set(p)
    nolist = list(nolist)

    for i in range(0, len(nolist)):
        d = abs(nolist[i] - x)
        sortlist.append(d)

        k = sortlist.index(min(sortlist))
    print(nolist[k])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(X: int, N: int, p: "List[int]"):
    ii = [i for i in range(102)]
    iii = sorted(list(set(ii) - set(p)))
    idx = np.abs(np.asarray(iii) - X).argmin()
    print(iii[idx])
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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=map(int,input().split())
p=list(map(int,input().split()))
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())
# p = list(map(int,input().split()))

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

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

for a in range(110):
    if not((x-a) in p):
        print(x-a)
        exit()
    if not((x+a) in p):
        print(x+a)
        exit()

# arr = []
# incc = []
# for i in range(101):
#     for j in range(n):
#         incc.append(p[j])
#     if i in incc:
#         continue
#     else:
#         arr.append(i)
# arr.pop(0)
# # print(arr)
        
# for i in range(1,len(arr)):
#     if n == 0:
#         print(x)
#         break
#     elif x in arr:
#         print(x)
#         break
#     elif x-i or x+i in arr:
#         if x-i in arr:
#             print(x-i)
#             break
#         elif x+i in arr:
#             print(x+i)
#             break

Submission status: Accepted

Solution code:
import sys

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

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

l = list(range(0, 102))
for p in P:
    l.pop(l.index(p))

dis_min = 1000
n = 1000
for i in l:
    dis = abs(i - X)
    if dis_min > dis:
        dis_min = dis
        n = i
    elif dis_min == dis:
        if n > i:
            n = i

print(n)

Submission status: Accepted

Solution code:
x,n,*p=map(int,open(0).read().split())
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=[int(x) for x in input().strip().split(" ")]
P=list(map(int,input().split()))
f=0
if len(P)==0:
    print(X)
else:
    for i in range(int(N/2)+2):
        if X-i not in P:
            print(X-i)
            f=1
        elif X+i not in P:
            print(X+i)
            f=1
        if f==1:
            break

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
tmp = []
for i in range(-101,102):
    tmp.append(i)

if n == 0:
    print(x)
else:
    for i in p:
        tmp.remove(i)
    
    ans = []
    for i in tmp:
        a = abs(x-i)
        ans.append(a)
 
    b = min(ans)
    
    c = x+b
    d = x-b
 
    if c and d in tmp:
        print(d)
    elif c in tmp:
        print(c)
    elif d in tmp:
        print(d)

Submission status: Accepted

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

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

Xp = Xn = X

while True:
    if Xn not in p_vals:
        print(Xn)
        break
    if Xp not in p_vals:
        print(Xp)
        break
    Xp += 1
    Xn -= 1

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

a = []
b = []

for i in range(0, 102):
    if i not in p:
        a.append((x - i)**2)
        b.append(i)
ans = min(a)
bb = a.index(ans)
print(b[bb])

Submission status: Accepted

Solution code:
X,N=[int(x) for x in input().strip().split(" ")]
P=list(map(int,input().split()))
f=0
if len(P)==0:
    print(X)
else:
    for i in range(int(N/2)+2):
        if X-i not in P:
            print(X-i)
            f=1
        elif X+i not in P:
            print(X+i)
            f=1
        if f==1:
            break

Submission status: Accepted

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

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

p = set(map(int, readline().split()))

ans = x
tmp = 300
for i in reversed(range(-1, 102)):
    if i not in p:
        if tmp >= abs(x - i):
            tmp = abs(x - i)
            ans = i
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()))
    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:
import numpy as np
 
X,N = map(int,input().split())
p = input()
 
if N != 0:
    
    p_list = [int(n) for n in p.split()]
    
    X_near = np.array(list(range(int(np.ceil(X - N/2 - 1)), int(np.floor(X + N/2)) + 2)))
 
    remain_list = []
 
    for i in X_near:
        if i not in p_list:
            remain_list.append(i)
        
 
    remain_array = np.array(remain_list)
    min_bool = np.abs(X - remain_array).min() == np.abs(X - remain_array)
    print(remain_array[min_bool].min())
    
if N == 0:
    print(X)

Submission status: Accepted

Solution code:
#ABC170 C 通せず
x, n = map(int, input().split())
seisulist = list(map(int, input().split()))
numlist = [i for i in range(0,102) if i not in seisulist]
xretu = [x]*len(numlist)
hikizan = [abs(s-t) for (s, t) in zip(numlist, xretu)]
sa = min(hikizan)
if x-sa not in seisulist:
    print(x-sa)
else:
    print(x+sa)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
 
p = list(map(int, input().split()))
p = sorted(p)
 
if n == 0:
    print(x)
    exit()
 
q = [i for i in range(0, 101+1)]
r = []
 
for i in q:
    if i not in p:
        r.append(i)

s = [abs(x-i) for i in r]
 
print(r[s.index(min(s))])

Submission status: Accepted

Solution code:
import numpy as np
x,n =map(int,input().split())

if  n==0:
 print(x)
else:
 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:

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

d = 100
pa = 0
px = range(102)
py = list(set(px) - set(p))

for i in py:

    if d > abs(i - x):
        pa = i
        d = abs(i - x)
    elif d == abs(i - x):
        if i < pa:
            pa = i

print(pa)

Submission status: Accepted

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

if N==0:
  print(X)

else:
  P = list(map(int,input().split()))
  if X not in P:
    print(X)
  
  else:
      a = X+1
      b = X-1
      
      while a in P:
        a+=1
      while b in P:
        b-=1
      
      if abs(X-a)<abs(X-b):
        print(a)
      else:
        print(b)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
 
ans = X
for i in range(N+1):
    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)
if n > 0:
    P = list(map(int, input().split()))
    for i in range(0,102):
        if x-i not in P or x+i not in P:
            if x-i not in P:
                print(x-i)
                exit(0)
            if x+i not in P:
                print(x+i)
                exit(0)

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
P = list(map(int,input().split()))
P.sort()
diff = 10**10
for p in range(102):
    if p in P:
        continue
    if abs(X-p) < diff:
        diff = abs(X-p)
        ans = p
print (ans)