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:
import sys
X, N = map(int, input().split())
p = list(map(int, input().split()))
if N == 0:
    print(X)
    sys.exit(0)

x = X
y = X
i = True
while i:
    x += 1
    i = False
    for n in range(N):
        if x == p[n]:
            i = True
i = True
while i:
    y -= 1
    i = False
    for n in range(N):
        if y == p[n]:
            i = True
p.append(X)
if len(p) == len(set(p)):
    print(X)
    sys.exit(0)
if abs(X-x) < abs(X-y):
    ans = x
else:
    ans = y
print(ans)

Submission status: Accepted

Solution code:
l = list(range(-100,205))
num1 = [int(s) for s in input().split()]
in_tmp = input()
flag = False
if in_tmp == '':
    flag = True
if flag == False:
    num2 = [int(s) for s in in_tmp.split()]

    for n in num2:
        l.remove(n)
        l_list = [int(s) for s in l]
    abs_min = 500
    num_min = 500
    for n in l_list:
        tmp = abs(num1[0] - n)
        if abs_min > tmp:
            abs_min = tmp
            num_min = n
        if abs_min == tmp:
            if num_min > n:
                num_min = n
    print(num_min)
if flag == True:
    print(num1[0])

Submission status: Accepted

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

A = [0]*101

for i in P:
    A[i] = 1

if A[X] == 0:
    print(X)
    exit()

count = 1
while(1):
    if (X - count) >= 0:
        if (X - count) < 101:
            if A[X - count] == 0:
                print(X - count)
                exit()
        else:
            print(101)
            exit()

    if count > 0:
        count = -count
    else:
        count = -count
        count += 1

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
if n == 0:
    print(x)
else:
    lst = list(map(int, input().split()))
    
    left = x
    right = x
    while left>= -1 and right <= 101:
        if left not in lst:
            print(left)
            break
        if right not in lst:
            print(right)
            break
         
        left -= 1
        right += 1

Submission status: Accepted

Solution code:
def main():
    X,N = map(int, input().split())
    P = list(map(int, input().split()))
    numup = X
    numdown = X
    a = True
    while a:
        if numdown not in P:
            a = False
            return print(numdown)
        elif numup not in P:
            a = False
            return print(numup)
        else:
            numdown -= 1
            numup += 1
main()

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
if b != 0:
    c = input()
    l = c.split()
    cc = [int(s) for s in l]
    ccc =list(cc)
    for i in range(a,102):
        if i in ccc:
            continue
        else:
            x = i
            break
    for i in reversed(range(0, a)):
        if i in ccc:
            continue
        else:
            y = i
            break
    if x-a<a-y:
        print(x)
    else:
        print(y)
else:
    d = input()
    print(a)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
if b == 0:
    print(a)
else:
    lis = list(map(int, input().split()))
    tt = [0] * 101
    for k in range(b):
        tt[lis[k]] = 1
    
    if tt[a] == 0:
        print(a)
        exit()
    for k in range(101):
        if a -k < 1:
            print(a-k)
            exit()
        if tt[a - k] == 0:
            print(a-k)
            exit()
        if a + k > 100:
            print(a+k)
            exit()
        if tt[a + k] == 0:
            print(a+k)
            exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

if( N == 0 ):
  #print("N=0")
  print(X)

else:
  P = list(map(int,input().split()))
  P_set = list(set(P))
  
  
  ans_chk = 0
  
  if ( X < P_set[0] or X > P_set[N-1] ):
    #print("X < P_set[0] or X > P_set[N-1]")
    print(X)
    ans_chk = 1
  
  if ( ans_chk==0 ):
    for i in range(N):
      if ( P_set[i] == X ):
        X_i = i
        break
      elif ( P_set[i] > X ):
        #print("P_set[i] > X")
        print(X)
        ans_chk = 1
        break
  
  if ( ans_chk==0 ):
    
    if ( X_i > N-(X_i+1) ): # 上の数が少ない → 下は1回多くする
      M = N-(X_i+1)
      temp_ans = X + N-(X_i+1) +1
      #print("temp_ans =",temp_ans)
      
      for i in range(1,M+1):
        if ( P_set[ X_i -i ] != X-i ):
          print(X-i)
          ans_chk = 1
          break
        elif ( P_set[ X_i +i ] != X+i ):
          print(X+i)
          ans_chk = 1
          break
      
      if ( ans_chk==0 ):
        if ( P_set[ X_i -(M+1) ] != X-(M+1) ):
          print( X-(M+1) )
          ans_chk = 1
  
  
    else: # 下の数が少ないor同数 → そのまま
      M = X_i
      temp_ans = X - X_i -1
      #print("temp_ans =",temp_ans)
    
      for i in range(1,M+1):
        if ( P_set[ X_i -i ] != X-i ):
          print(X-i)
          ans_chk = 1
          break
        elif ( P_set[ X_i +i ] != X+i ):
          print(X+i)
          ans_chk = 1
          break
  
  if ( ans_chk==0 ):
    print(temp_ans)

Submission status: Accepted

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

Z = int(X)
flag = 0
count = 0

while flag != 2:

    flag = 0

    for num in datalist:
#        print('now is for Loop num = {}'.format(num))
        if int(num) == Z:
#            print('num equal Z. num = Z = {}'.format(Z))
            flag = 1
            break
#        print('here is under if . here is in for loop. break ln = 11')
#    print('here is out of for loop. ln = 12. Lets Check Flag statement')

    if flag == 0:
#        print('This is result!!')
        print(Z)
        flag = 2
#    print('flag = {}'.format(flag))

#    print('before count = {} '.format(count))

    count = abs(count) + 1
    if (count % 2) == 1:
       Z += count * (-1)
    else:
       Z += count 
    
#    print('Now End is While Loop.')
#    print('===')
#    print('Z={}'.format(Z))
#    print('after count={}'.format(count))
#    print('===')

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    #for i in range(n):
    #    p.append(input().split())
    #print(p)
    #rint(type(p[0]))
    min = 1e9
    ans = 0
    for i in range(102):
        #i = i + 1
        if i in p:
            continue
        sa = abs(x - i)
        #print(sa)
        if min > sa :
            min = sa
            ans = i
if n == 0:
    print(x)
else:
    print(ans)

Submission status: Accepted

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

array = [[0]]*200
if n == 0:
    print(x)
else:
    for i in range(200):
        array[i] = 0
    tmp = input().split(' ')
    for i in range(n):
        array[int(tmp[i])] = 1
    
    dif_tmp = 999
    ret = 999
    for i in range(200):
        if array[199-i] == 0:
            if abs(x-(199-i)) <= dif_tmp:
                ret = 199-i
                dif_tmp = abs(x-(199-i))
    for i in range(1,100):
        if abs(x+i) <= dif_tmp:
            ret = -i
            dif_tmp = abs(x+i)
    print(ret)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = []
p = list(map(int, input().split()))
i = 0
j = 0
ans = 0
check = 0
if(n == 0):
    check = 1
    print(x)
for i in range(200):
    X = x + ((-1) ** (i)) * int((i + 1) / 2)
    for j in range(n):
        if(X == p[j]):
            ans = 1
            break
        ans = 0
    if(ans == 0) and (check == 0):
        print(X)
        break

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
  quit()
lst=list(map(int,input().split()))
a=list(range(-1,102))
for i in lst:
  if i in a:
    a.remove(i)
if len(a)==0:
  print(x)
  quit()
b=[]
for j in a:
  b.append(abs(j-x))
print(a[b.index(min(b))])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
num, i = map(int, input().split())
if(i != 0):
  s = set(map(int, input().split()))
else:
  s = set()
m = set(range(102))
o = list(m-s)
o2 = list(map(lambda x: abs(x - num), o))
print(o[o2.index(min(o2))])

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 10**18
l = []
if x not in p:
  print(x)
else:
  for i in range(-1,102):
    if (abs(i - x) < abs(ans - x)) and (i not in p):
      ans = i
  print(ans)

Submission status: Accepted

Solution code:
import sys

x, n = map(int, input().split())
pn = list(map(int, sys.stdin.readline().rstrip().split()))

if x not in pn:
    print(x)
    exit(0)

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

Submission status: Accepted

Solution code:
import math

def a():
    x = list(map(int, input().split()))
    print(x.index(0) + 1)


def b():
    x, y = map(int, input().split())
    if x * 2 <= y <= x * 4 and y % 2 == 0:
        print('Yes')
    else:
        print('No')



def c():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    for i in range(100):
        temp = x - i
        if temp >= 0 and temp not in p:
            print(temp)
            break
        temp = x + i
        if temp not in p:
            print(temp)
            break



def d():
    print('')


c()

Submission status: Accepted

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

for i in range(n):
  if X-i not in p:
    print(X-i)
    break
  elif X+i not in p:
    print(X+i)
    break
  else:
    continue

Submission status: Accepted

Solution code:
str1 = input()
str2 = input()

A = str1.split(" ")
B = str2

res = 0
#print(A[1])
if A[1] == "0":
    res = A[0]
else:
#    print("A[1]!=0")
    B = B.split(" ")
    intB = []
    for i in B:
        intB.append(int(i))
    intB.sort(reverse=True)

    X = int(A[0])
    N = int(A[1])

    res = 0
    diff = 999999

    # 1~100の配列を作る
    l = list(range(-101, 102))

    # 入力内容を削る
    for i in range(0, N):
        l.pop(intB[i]+101)

 #   print(l)
    for i in l:
        if 0 == abs(X - int(i)):
            diff = 0
            res = i
            break
        elif diff > abs(X - int(i)):
            diff = abs(X - int(i))
            res = i
#            print(diff, res)


print(res)

Submission status: Accepted

Solution code:
from sys import stdin
X, N = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
if N == 0 or X not in P:
    ans = X
else:
    i = True
    k = True
    a = X
    b = X
    while i:
        a += 1
        i = a in P
    while k:
        b -= 1
        k = b in P
    if abs(X - a) == abs(X - b):
        if a > b:
            ans = b
        else:
            ans = a
    else:
        if  abs(X - a) > abs(X - b):
            ans = b
        else:
            ans = a
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

if N == 0:
    print(X)
else:
    A = [i for i in range(1,210)]

    for i in P:
        A.remove(i)

    a = (np.array(A) - X)**2
    j = np.argmin(a)
    if (A[j] - X)**2 >= X**2:
        print(0)
    else:
        print(A[j])

Submission status: Accepted

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

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

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

for i in range(N):
    if X-i not in P:
        ans = X-i
        break
    elif X+i not in P:
        ans = X+i
        break

print(ans)

Submission status: Accepted

Solution code:
xn=input()
x,n=xn.split()
if n=='0':
  print(int(x))
else:
  p=input()
  p={int(i) for i in p.split()}
  s={i for i in range(-150,150)}
  s_p=list(s-p)
  d=[abs(i-int(x)) for i in s_p]
  print(s_p[d.index(min(d))])

Submission status: Accepted

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

P_ori=list(map(int,input().split()))
if P_ori.count(X)==0:
    print(X)
    exit()


P1=sorted(P_ori)
N=list(range(0,102))
PZ=[]
for i in range(len(N)):
    if P1.count(N[i])==0:
        PZ.append(N[i])

PZ.append(X)
P2=sorted(PZ)
t=P2.index(X)
if P2[t]==P2[0]:
    print(P2[1])
    exit()
elif P2[t]==P2[-1]:
    print(P2[-2])
    exit()
else:
    dist1=abs(P2[t-1]-P2[t])
    dist2=abs(P2[t]-P2[t+1])
    if dist1<=dist2:
        print(P2[t-1])
        exit()
    else:
        print(P2[t+1])
        exit()
print(0)

Submission status: Accepted

Solution code:
import sys
import bisect

def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())


def main():
  X,N = LI()[:]
  if N > 0:
    P = LI()
    P.sort()
  else:
    print(X)
    exit()
  
  #print(X,N)
  #print(P)
  
  index = bisect.bisect_left(P, X)
  #print("index=",index)
  if index >= N :
    print(X)
    exit()
    
  l = index
  r = index
  for i in range(0,200):
    up = X + i
    down = X - i
    
    #print("l=",l,"r=",r)
     
    # Left優先
    if l < 0 or P[l] != down:
      print(down)
      break

    if r >= N or P[r] != up:
      print(up)
      break
    
    l -= 1
    r += 1
    
if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

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

allList=[]

for i in range(-201,301):
    allList.append(i)

diff = set(allList) ^ set(p)



diff = list(diff)
diff.append(x)
diff = sorted(diff)

# print(diff)

ind = diff.index(x)
# print(ind)

# if x == 100:
    

a = diff[ind-1]
b = diff[ind+1]
# print(a,b)

ax = abs(x-a)
bx = abs(x-b)

# print(ax,bx)

if ax==bx:
    if a < b:
        print(a)
        exit()
    else:
        print(b)
        exit()

if ax > bx:
    print(b)
else:
    print(a)

Submission status: Accepted

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

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

abs_n = 0
ans = 0

if n == 0:
    print(x)
else:
    #r = max(p)
    #l = min(p)

    for i in range(-100,201):
    
        # 配列に含まれていると
        if i in p:
            continue
            
        tmp = abs(x-i)
        #print(i, tmp)

        if i == -100:
            abs_n = tmp
            ans = i
        
        if tmp < abs_n:
            abs_n = tmp
            ans = i
        
    print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n:
    p = {int(i) for i in input().split()}
if n == 0:
    print(x)
else:
    if x not in p:
        print(x)
    else:
        flag = True
        abs_diff = 1
        while flag:
            for i in range(1, 3):
                ans = x + (-1)**i * abs_diff
                if ans not in p:
                    flag = False
                    print(ans)
                    break
            abs_diff += 1

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
d = list(a*0 for a in range(n))

if n==0:
    print(x)
else:
    for i in range(n+1):
        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())
if N != 0:
  A = list(map(int, input().split()))
else:
  A =[]
B =[]
for i in range(N):
  B.append(A[i]-X)
  B = sorted(B)
for i in range(100):
  if -i not in B:
    print(X-i)
    break
  elif i not in B:
    print(X+i)
    break

Submission status: Accepted

Solution code:
def read_int():
    return int(input())


def read_ints():
    return map(int, input().split(' '))


x, n = read_ints()
p = []
if n > 0:
    p = list(read_ints())
ans = -1
delta = 1000
for i in range(-1, 102):
    ok = True
    for j in p:
        if j == i:
            ok = False
            break
    if ok:
        d = abs(x - i)
        if d < delta:
            ans = i
            delta = d
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def check(n,p):
    for j in range(0,len(p)):
        if(n==p[j]):
            return False
    return True

def check_main(X,N,p):
    for i in range(0,51):
        if (check(X-i,p)):
            return X-i
        elif(check(X+i,p)):
            return X+i


if __name__ == "__main__":
    X,N = input().split()
    numbers = list(map(int,input().split()))
    X = int(X)
    N = int(N)
    numbers.sort()
    print(check_main(X,N,numbers))

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-

import sys

def main():
    numbers=[]
    x,n = map(int,input().split())
    numbers=list(map(int,input().split()))
    if n==0:
        print(x)
        sys.exit()
    dp_list=list(range(-1000, 1000))
    dp_list=set(dp_list)-set(numbers)

    for i in range(101):
        if abs(x-i) in dp_list:
            print(x-i)
            break
        elif abs(x+i) in dp_list:
            print(x+i)
            break

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 0
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) not in number_list and str(num2) not in number_list:
        print(num2)
        break
      if str(num) in number_list:
        print(num2)
      else:
        print(num)
      break
    n += 1

Submission status: Accepted

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

if n!=0:
    p_list = list(map(int, input().split()))
    kouho = list(range((x-n//2-1),(x+n//2+1)))    
    kouho2 = list(set(kouho) - set(p_list))
    ans = [j for i, j in enumerate(kouho2) if abs(j-x) == min(abs(np.array(kouho2) - x))]
    ans = min(ans)

else:
    ans = x

print(ans)

Submission status: Accepted

Solution code:
num = list(map(int,input().split()))
if num[1] ==0:
  print(num[0])
else:  
  num_list = list(map(int,input().split()))
  flg = True
  ans = num[0]
  distance = 0

  while flg:
    ch_1 = ans-distance
    ch_2 = ans+distance
    if ch_1 not in num_list:
      print(ch_1)
      flg = False
    elif ch_2 not in num_list:
      print(ch_2)
      flg = False
    else:
      distance +=1

Submission status: Accepted

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

def main():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
        exit()
    p = set(map(int,input().split()))
    if N == 100:
        print(0 if X<=50 else 101)
        exit()
    lst = [0] + list(set(range(1,101)) - p) + [101]
    lst2 = [abs(lst[i] - X) for i in range(len(lst))]
    min_ = min(lst2)
    print(lst[lst2.index(min_)])    



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
if n == 0:
    print(x)
else:
    pls = list(map(int,input().split()))
    i = 0
    while 0 < 1:
        if x + i not in pls:
            if x - i not in pls:
                print(x - i)
                break
            else:
                print(x + i)
                break
        elif x - i not in pls:
            print(x - i)
            break
        else:
            i += 1

Submission status: Accepted

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

# 0,1~100,101
data_list = [i for i in range(V_RANGE)]
# 取得リスト
get_list = list(map(int, input().split()))

# (data_list-in_value)のリストを作る
sub_list = set(data_list) - set(get_list)

# 絶対値が最小のものを取得
g_abs = 10**4
abs_value = 0
for i in sub_list:
	t_abs = abs(X - i)

	if(g_abs > t_abs):
		g_abs = t_abs
		abs_value = i

print(abs_value)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if not N:
    print(X)
    exit()
p = list(map(int, input().split()))
if X not in p:
    print(X)
    exit()
    
p_low = sorted([X - i for i in p if i < X])
p_high = sorted([i - X for i in p if i > X])

if len(p_low) > len(p_high):
    lng = len(p_low)
else:
    lng = len(p_high)

for i in range(1, lng + 2):
    if i not in p_low:
        print(X - i)
        exit()
    elif i not in p_high:
        print(X + i)
        exit()

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N > 0:
  p = list(map(int,input().split()))
a = 102
ans = 0
for i in range(-1,200):
  if N == 0:
    ans = X
    break
  if p.count(i) == 0 and a > abs(X - i):
    a = abs(X - i)
    ans = i
print(ans)

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:
a=input().split(" ")
b=input().split(" ")
c=0
d=0
e=0
f=int(a[0])
g=int(a[0])
if int(a[1])!=0:
	for i in range(int(a[1])):
		if int(a[0])==int(b[i]):
			c=c+1
elif int(a[1])==0:
	print(a[0])

 
if c>=1:
	while str(f) in b:
		f=f+1
		d=d+1
	while str(g) in b:
		g=g-1
		e=e+1
	if d>e:
		print(g)
	elif e>d:
		print(f)
	elif e==d:
		print(g)
if c==0 and int(a[1])!=0:
	print(a[0])

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
def intlist(x):
    y = []
    for i in range(len(x)):
        y.append(int(x[i]))
    return y

P = intlist(input().split())

if X not in P:
    print(X)
else:

    for i in range(N):
        if X-i-1 not in P:
            print(X-i-1)
            break
        if X+i+1 not in P:
            print(X+i+1)
            break

Submission status: Accepted

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

k=100
for i in range(0,150):
    d=abs(X-i)
    if d<k and(i not in list1):
        k=d
        A=i
print(A)

Submission status: Accepted

Solution code:
import sys
x, y = map(int,input().split())
n = list(map(int, input().split()))
if y == 0:
    print(x)
    sys.exit()
for i in range(100):
    a = [x-i, x+i]
    if set(a)<=set(n):
        pass
    elif x-i not in n:
        print(x-i)
        sys.exit()
    else:
        print(x+i)
        sys.exit()

Submission status: Accepted

Solution code:
import math 
X, N = map(int,input().split())
d = int(999)
d1 = int()
ans = int(999)
if 0 < N:
    P = list(map(int,input().split()))
    for i in range(999):
        if P.count(i) == 0:
            d1 = abs(X-i)
            if d1 < d and 0 <= d1:
                d = d1
                ans = i
    print(ans)
else:
    print(X)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
l = {i for i in range(-100, 200)}

s = list(l - p)
min_diff = 1000
ans = 1000

for j in range(len(s)):
    diff = abs(s[j] - x)
    if min_diff > diff:
        min_diff = diff
        ans = s[j]

print(ans)

Submission status: Accepted

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

    if not p:
        return X
    a = max(p) + 1
    b = max(p) + 1
    for i in range(max(p) + 1, min(p) - 2, -1):
        if i in p:
            continue
        if abs(X - i) <= a:
            a = abs(X - i)
            b = min(b, i)
    return b


print(main())

Submission status: Accepted

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

if n == 0:
    print(x)

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

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
ans_y = None
if n == 0:
  print(x)
elif n == 1:
  p = list(map(int, input().split()))
  if x == p[0]:
    print(x-1)
  else:
    print(x)
else:
  p = list(map(int, input().split()))
  p.sort()
  m = float("inf")
  if x<p[0] or p[n-1]<x:
    print(x)
  else:
    for y in [y for y in range(p[0]-1,p[n-1]+2) if not y in p]:
      if abs(x-y)<m:
        m = abs(x-y)
        ans_y = y
  if ans_y != None:
    print(ans_y)

Submission status: Accepted

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

    difX = [[0]*2]*N

    for i in range(N):
        difX[i] = [abs(X-p[i]),i]

    min_dif_p = p[min(difX)[1]]

    pluslist = [min_dif_p]
    minuslist = [min_dif_p]

    for i in range(100):
        pluslist.append(pluslist[-1]+1)
        if pluslist[-1] not in p:
            break

    for i in range(100):
        minuslist.append(minuslist[-1]-1)
        if minuslist[-1] not in p:
            break

    ans1 = pluslist[-1]
    ans2 = minuslist[-1]

    if abs(ans1-X) < abs(ans2-X):
      print(ans1)
    else:
      print(ans2)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n>0:
    
    a=list(map(int,input().split()))
        
    z=x+1
    y=x-1
    if x not in a:
        print(x)
    else:
        while True:
            if y not in a:
                print(y)
                break
            elif z not in a:
                print(z)
                break
        
            z+=1
            y-=1
        
else:
    print(x)

Submission status: Accepted

Solution code:
import sys
x = input().split()
y = input().split()

if len(y) == 0:
    print(x[0])
    sys.exit()
a=[]
b=[]
for n in range(-1,102):
    b.append(n)
   
for nn in range(len(y)):
    
    b.remove(int(y[nn]))
for m in range(len(b)):  
    d = b[m] - int(x[0])
    if d < 0:
        c = d*(-1)
    if d >= 0:
        c = d
    a.append(c)
mm = min(a)
if str((int(x[0]) - mm)) in y:
    print(int(x[0]) + mm)
else:
    print(int(x[0]) - mm)

Submission status: Accepted

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

for n in range(1, N + 1):    
    if not (X - n) in P:
        print(X - n)
        exit()
    if not (X + n) in P:
        print(X + n)
        exit()
print(min(P) - 1)

Submission status: Accepted

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

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

def serch(X,N,P):
    dif = []
    
    for i in range(N):
        dif.append(abs(P[i]-X))
    
    dif.sort()
    
    difcount = {}
    for i in dif:
        if i in difcount:
            difcount[i] += 1
        else:
            difcount[i] = 1

    for i in range(1,101):
        if i not in difcount:
            return X-i
        
        if difcount[i] == 1:
            if X - i in P:
                return X+i
            else:
                return X-i
                
if X not in P:
    print(X)
else:
    print(serch(X,N,P))

Submission status: Accepted

Solution code:

able = list()
for i in range(103):
    able.insert(i, i-1)

X,N = map(int,input().split())
p = list(map(int,input().split()))
for i in range(len(p)):
    able.remove(p[i])

target = 1000
ans = 1000
for i in range(len(able)):
    
    if (target > abs(X - able[i])):
        # if (target == abs(X - able[i])): 
        #     ans = min(target, able[i])
        # else:
        target = abs(X - able[i])
        ans = able[i]
    
    # print(able[i], abs(X - able[i]), ans)

print(ans)

Submission status: Accepted

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

diff = 1000
ans = None
for i in range(X - 51, X + 51, 1):
    isInPs = False
    index = 0
    for j in ps:
        if ps[index] == i:
            isInPs = True
            break
        index += 1
    if isInPs == False:
        testDiff = abs(X - i)
        if testDiff < diff:
            diff = testDiff
            ans = i
print(ans)

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    _near = -1
    for i in range(-1, 102):
        if i in p:
            continue
        if abs(_near - x) > abs(i - x):
                _near = i
    print(_near)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
X, N = map(int, input().split())
p_list = set([int(i) for i in input().split()])
set_all = set(np.arange(-201, 201))
ex_list = set_all-p_list
ex_list = list(ex_list)
diff_list = [np.abs(i-X) for i in ex_list]
min_index = np.argmin(diff_list)
print(ex_list[min_index])

Submission status: Accepted

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

a = 100
num = 0

for i in range(202):
    if (i-100) not in p:
        b = (i-100)-X
        if abs(b) < a:
            a = abs(b)
            num = (i-100)

print(num)

Submission status: Accepted

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

    p.sort()
    y = 0

    for i in range(n):
        if p[i] <= x:
            y = i
            if i != n-1 and x < p[i+1]:
                break 

    i = 0
    while 1 == 1:
        if y - i < 0:
            print(p[0] - 1)
            break
        elif x - i != p[y - i]:
            print(x - i)
            break
        if n <= y + i:
            print(p[n - 1] + 1)
            break
        elif x + i != p[y + i]:
            print(x + i)
            break
        i = i + 1