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
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

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

abs_ = 200
answers = []

# 答えは0 から 101の値をとる
for i in range(102):
    if i in P:
        continue

    tmp_abs = abs(X - i)
    if tmp_abs == abs_:
        answers.append(i)
    if tmp_abs < abs_:
        answers = [i]
        abs_ = tmp_abs
ans = min(answers)
print(ans)

Submission status: Accepted

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

while 1:
    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()))
p.sort()
ans=0
ans1=X
for i in range(1,102):
    if i in p:
        a=p.pop(0)
        continue
    A=abs(X-i)
    if ans1>A:
        ans1=A
        ans=i
    elif ans1==A:
        ans=min(ans,i)
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import fractions

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

    ans = INF
    array = set(range(x-n-1,x+n+1))
    array = array - set(P)
    array = list(array)
    for i in range(len(array)):
        ans = min(ans, abs(array[i]-x))
    if (x-ans) in P:
        print(x+ans)
    else:
        print(x-ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

ans = 1000
count = 0

if len(a) == 0:
    print(X)
    sys.exit()
else:
    m = max(a)*200
    for i in range(-m, m+1):
        if i in a:
            pass
        else:
            kyori = abs(X-i)
            if ans > kyori:
                ans = kyori
                count = i
            elif ans == kyori:
                count = min(count, i)
            else:
                pass

print(count)

Submission status: Accepted

Solution code:
import numpy as np
x,n=map(int,input().split())
p=np.array(list(map(int,input().split())))
p_abs=sorted(list(map(lambda k:abs(k-x),p)))
#print(p_abs)

if(len(p_abs)==0 or p_abs[0]!=0):
    print(x)
else:
    i=1
    while(True):
        if(2*i>=len(p)):
            if(x-i not in p):
                print(x-i)
            else:
                print(x+i)
            break
        elif(p_abs[2*i-1]!=i or p_abs[2*i]!=i):
            if(x-i not in p):
                print(x-i)
            else:
                print(x+i)
            break
        else:
            i+=1

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
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())
INF = 1000000000000

x,n = LI()
p = LI()

val = INF
ret = INF
tmp = 0
for i in range(-100,200):
    flg = False
    for y in p:
        if(i == y):
            flg = True
    if(not flg):
        tmp =  abs(x - i)
        if(val > tmp):
            val = tmp
            ret = i

print(ret)

Submission status: Accepted

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

    ans = float('inf')
    ans2 = 0

    for i in range(0, 102):
        isin = False
        for j in range(len(p)):
            if i == p[j]:
                isin = True
        
        if isin:
            continue

        if ans > abs(x - i):
            ans = abs(x - i)
            ans2 = i

        
    print(ans2)

Submission status: Accepted

Solution code:
def main1():
    X,N=map(int,input().split())
    p=list(map(int,input().split()))
    ans=-1
    for i in range(X,1000):
        if not (i in p):
            ans=i
            break
    for i in range(X,-1,-1):
        if not (i in p):
            ans2=i
            break
    if abs(ans-X) >= abs(ans2-X):
        print(ans2)
    else:
        print(ans)

main1()

Submission status: Accepted

Solution code:
import sys
X, N = map(int,input().split())
if N == 0:
  PN = []
else:
  PN = list(map(int,input().split()))
nums = [i for i in range(-10,110)]

for P in PN:
  nums.remove(P)

dist = abs(nums[0]-X)
target = nums[0]
for num in nums[1:]:
  tmp = abs(num-X)
  if tmp >= dist:
    print(target)
    sys.exit()
  else:
    dist = tmp
    target = num

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
num = list(map(int, input().split()))
a = X
b = X
while a in num and b in num:
  a+=1
  b-=1
if b not in num: print(b)
elif a not in num: print(a)

Submission status: Accepted

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

if n!= 0:
	ps= input().split(' ')
else:
	ps=[]

def in_ps(x):
	for p in ps:
		if x==int(p):
			return True
	return False
d=1

while 1:
	if in_ps(x):
		x+= d*(-1)**d
		d+=1
	else:
		print(x)
		break

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 10**9
a = 10**9

for i in range(-100,102):
    if not(i in p):
        sa = abs(x-i)
        if sa < a:
            ans = i
            a = sa
        elif sa == a:
            ans = min(ans,i)

print(ans)

Submission status: Accepted

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

if x not in p:
  ans = x
else:
  i = x - 1
  j = x + 1
  while 1:
    if i not in p and j not in p:
      ans = min(i,j)
      break

    if i not in p:
      ans = i
      break
    elif j not in p:
      ans = j
      break

    i -= 1
    j += 1

print(ans)

Submission status: Accepted

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

Ps = set(P)
import sys

if X not in Ps:
    print(X)

else:
    dec = X - 1
    inc = X + 1

    while True:
        if dec not in Ps:
            print(dec)
            break
        else:
            dec -= 1
        
        if inc not in Ps:
            print(inc)
            break
        else:
            inc += 1

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
def main():
    x, N = map(int, input().split())
    if N == 0:
        print(x)
        sys.exit()
    p = [int(i) for i in input().split()]
    p.sort()
    min_ = 1000
    index_ = N
    count = [0] * 102
    for i in range(N):
        count[p[i]] = 1
    for i in range(102):
        if count[i] == 1:
            continue
        if min_ > abs(i - x):
            min_ = abs(i - x)
            index_ = i
    if min_ > abs(-1 - x):
        index_ = -1
    print(index_)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding cell (SUBMIT ONLY THIS CELL)

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


for i in range(100):
    if X - i not in p:
        print(X - i)
        break
    if 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)
else:
  p=list(map(int,input().split()))
  flag=False
  i=0
  while flag==False:
    if (X-i in p)==False:
      flag==True
      print(X-i)
      break
    if (X-i in p)==True and (X+i in p)==False:
      flag==True
      print(X+i)
      break
    i+=1

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    i = 0
    flag = False
    ans = 0
    while True:
        x_minus = x-i
        x_plus = x+i
        if x_plus not in p:
            ans = x_plus
            flag = True
        if x_minus not in p:
            ans = x_minus
            flag = True
        if flag:
            break
        else:
            i += 1
    print(ans)
    
else:
    print(x)

Submission status: Accepted

Solution code:
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b=mi()
if b==0:
  print(a)
else:
  l=list(mi())
  for i in range(100):
    if not(a-i in l):
      print(a-i)
      sys.exit()
    elif not(a+i in l):
      print(a+i)
      sys.exit()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    X, N = map(int, readline().split())
    P = list(map(int, readline().split()))
    diff = 1000
    ans = 0
    for i in range(102):
        if not i in P:
            if abs(X-i)<diff:
                ans = i
                diff = abs(X-i)

    print(ans)


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

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

Submission status: Accepted

Solution code:
#ONE TRUTH PREVAILS
import sys
K,N=map(int,input().split())
L=list(map(int,input().split()))
diff=float("inf")
ans=0
mi=float("inf")
for i in range(-200,200):
    if i not in L:
        diff=abs(i-K)
        if diff<mi:
            mi=diff
            ans=i
print(ans)

Submission status: Accepted

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

ng_map = {}
for p in P:
    ng_map[int(p)] = True

min_val = 999
candidate = x
for i in range(102):
    if i in ng_map:
        continue
    val = abs(x - i)
    if val < min_val:
        candidate = i
        min_val = val
print(candidate)

Submission status: Accepted

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

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

n = -1
m = 999
for num in range(-1, 102):
    if num in nums:
        continue
    elif m != min(m, abs(num - x)):
        n = num
        m = min(m, abs(num - x))

print(n)

Submission status: Accepted

Solution code:
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    #n = int(stdin.readline().rstrip())
    x,n = map(int, stdin.readline().rstrip().split())
    if n != 0:
        ps = list(map(int, stdin.readline().rstrip().split()))
    else:
        print(x)
        exit()
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ps.sort()
    ab = []
    for i in range(n):
        ab.append(abs(ps[i] - x))
    m = ps[ab.index(min(ab))]
    small = m
    big = m
    if m not in ps:
        print(m)
        exit()
    while True:
        small = small - 1
        big = big + 1
        if small not in ps:
            print(small)
            exit()
        elif big not in ps:
            print(big)
            exit()

main()

Submission status: Accepted

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

for i in range( n + 1 ):
    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:
import io,sys
def main():
    x,n = map(int,sys.stdin.readline().rstrip().split())
    p = list(map(int,sys.stdin.readline().rstrip().split()))

    x_pos = x
    x_neg = x
    while True:
        if x_neg not in p:
            print(x_neg)
            sys.exit()
        if x_pos not in p:
            print(x_pos)
            sys.exit()
        
        x_pos+=1
        x_neg-=1
main()

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()
    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:
A,B=list(map(int,input().split()))
if B==0:
   print(A)
   exit()
N=list(map(int,input().split()))
N=set(N)
S=0
l=float("Inf")
for i in reversed(range(A,A+101)):
   if i not in N:
      S=i
      l=abs(A-i)
for i in reversed(range(A-100,A+1)):
   if i not in N and l >= abs(A-i):
      S=i
      break
print(S)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    arr = []
    for i in range(-100, 201):
        if not i in p:
            arr.append(i)
    ans = arr[0]
    for ai in arr:
        if abs(ai - x) < abs(ans - x):
            ans = ai
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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

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

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

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

abs_diff = 1000000000
ans = 0
for i in range(1000,-1001,-1):
    if i in p:
        continue
    else:
        if abs_diff >= abs(X-i):
            abs_diff = abs(X-i)
            ans = i
        
print(ans)

Submission status: Accepted

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

A = set(list(map(int, input().split())))
ans = 0
diff = 1000
for i in range(102):
  if i in A:
    continue
  d = abs(X - i)
  if d < diff:
    diff = d
    ans = i

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    X,N = map(int,input().split())

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

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


    minim = INF
    ans = 0
    for i in range(10**4+1):
        if i in p: continue

        if minim > abs(i-X):
            ans = i
            minim = abs(i-X)


    print(ans)






if __name__ == "__main__":
  main()

Submission status: Accepted

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

for i in range(100):
    if x-i not in li:
        print(x-i)
        break
    if x+i not in li:
        print(x+i)
        break

Submission status: Accepted

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

li = []
for i in range(0, 102):
    if i not in P:
        li.append(i)

ans = -1
minimum_num = 200

for n in li:
    num = abs(n - X)
    if num < minimum_num:
        minimum_num = num
        ans = n

print(ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
if X in p:
  for i in range(1,100):
    if not X-i in p:
      print(X-i)
      break
    if not X+i in p:
      print(X+i)
      break
else:
  print(X)

Submission status: Accepted

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

for i in range(100):
    # print(i)
    # print
    if X-i not in p:
        print(X-i)
        exit()
    if X+i not in p:
        print(X+i)
        exit()

Submission status: Accepted

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

done = False
curr_diff = 0
while not done:
    curr = []
    if X - curr_diff not in p:
        curr.append(X - curr_diff)
    elif X + curr_diff not in p:
        curr.append(X + curr_diff)
    
    if curr:
        done = True
    curr_diff += 1

print(min(curr))

Submission status: Accepted

Solution code:
'''     ##     ##  #######  # #  ######
        ##     ##  ##   ##  ###    ##
        ##     ##  ##    #  # #    ##
        #########  #######  # #    ##    '''

import sys
import math
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())

def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end=" \ ")

MODPRIME = int(1e9+7); BABYMODPR = 998244353;

ONLINE_JUDGE = 1
if not ONLINE_JUDGE:
    sys.stdin = open("input.txt","r")  # <<<  Comment this line  >>> #
    sys.stdout = open("output.txt","w")  # <<<  Comment this line  >>> #
    sys.stderr = open("output.txt","w")  # <<<  Comment this line  >>> #

x, n = get_ints()
li = get_list()
li = set(li)
i = 0
ans = -1
while True:
    if x-i not in li:
        ans = x-i
        break
    elif x+i not in li:
        ans = x+i
        break
    i += 1
print(ans)
# for _testcases_ in range(int(input())):

'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS BY ME @luctivud ( UDIT GUPTA )
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
DO NOT PLAGIARISE.
TESTCASES:
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Submission status: Accepted

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

if n == 0:
    print(x)
    quit()
    
min_ = float('Inf')
ans = 0
for i in range(-1, 110):
    if i in p:
        continue
    #print(i)
    diff = abs(x - i)
    if diff < min_:
        min_ = diff
        ans = i
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
if N != 0:
  ps = sorted(list(map(int,input().split())))
  # print(ps)
  min_num = 1000
  min_abs = 1000
  p_index = 0
  for i in range(0,102):
    if i == ps[p_index]:
      p_index += 1
      p_index %= N
    elif abs(i-X)<min_abs:
      min_num = i
      min_abs = abs(i-X)
  print(min_num)
else:
  print(X)

Submission status: Accepted

Solution code:
# 

from sys import stdin
input = lambda: stdin.readline().rstrip()


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

def solve(A, B):
    if A not in P:
        print(A)
        return

    if B not in P:
        print(B)
        return
    
    solve(A-1, B+1)

solve(X,X)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
lists = list(input().split())
for i in range(n):
  lists[i] = int(lists[i])
loop = True
number = x
while True:
  if number in lists:
    number = number - 1
  else:
    break
number_2 = x
while True:
  if number_2 in lists:
    number_2 = number_2 + 1
  else:
    break
if abs(number - x) > abs(number_2 - x):
  print(number_2)
elif abs(number - x) == abs(number_2 - x):
  print(number)
else:
  print(number)

Submission status: Accepted

Solution code:
x,n=map(int, input().split())
if n==0:
    print(x)
else:
    a=list(map(int, input().split()))
    a.sort()
    sa=1000
    for i in range(0,102):
        if i not in a:
            if sa>abs(x-i):
                ans=i
                sa=abs(x-i)
    print(ans)

Submission status: Accepted

Solution code:

[X,N] = list(map(int,input().split()))
p = list(map(int,input().split()))

#p = sorted(p)
#ammy=[0]*

for i in range(200):
    if X+i in p:
        continue
    else:
        dammy1=X+i
        kouho1=i
        break

for j in range(200):
    if X-j in p:
        continue
    else:
        dammy2=X-j
        kouho2=j
        break

#print(dammy1,dammy2)

if kouho1<kouho2:
    print(dammy1)
else:
    print(dammy2)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
q = set(range(102))
r = sorted(list(q - p))

tmp = 200
for s in r:
    if abs(x-s) < tmp:
        res = s
        tmp = abs(x-s)

print(res)

Submission status: Accepted

Solution code:
import math
import pprint
import fractions
import collections
import itertools
from decimal import *
X,N=map(int,input().split())
p=list(map(int,input().split()))
n=len(p)
d={}
l=[i-1 for i in range(104)]
#print(l)
i=0
while i<n:
    for j in range(len(l)):
        if p[i]==l[j]:
            l.pop(j)
            break
    #print(l)
    #input()
    i=i+1
minim=float("inf")
l2=[]
for i in range(len(l)):
    if minim>abs(l[i]-X):
        minim=abs(l[i]-X)
        l2=[]
        l2.append(l[i])
    elif minim==abs(l[i]-X):
        l2.append(l[i])
#l2=list(l2)
#print(type(l2))
print(min(l2))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

x,n = na()
p = na()
q = [i for i in range(-1,102) if i not in p]
r = []

for i in range(len(q)):
    r.append(abs(q[i]-x))

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

k = min(r)
if x-k in q:
    print(x-k)
else:
    print(x+k)

Submission status: Accepted

Solution code:
import sys
import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
import math
start=time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
x,n = rl()
p=rl()
p.sort()
for i in range(100):
    if x-i not in p:
        print(x-i)
        sys.exit()
    
    if x+i not in p:
        print(x+i)
        sys.exit()

Submission status: Accepted

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

P = set(int(n) for n in input().split())

closest = float('inf')
diff = float('inf')

for p in range(-1,102):
    if not p in P and abs(X - p) < diff:
        closest = p
        diff = abs(X - p)

print(closest)

Submission status: Accepted

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

Submission status: Accepted

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

tmp=1000
ans=1000

for i in range(101,-1,-1):
    if abs(i-X)<=tmp and i not in p:
        tmp=abs(i-X)
        ans=i

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
else:
  print(x)
  exit()
  
def arimasuka(num,sign):
  if num in p:
    k=arimasuka(num+sign,sign)
  else:
    return num
  return k

p.sort()
ans1=arimasuka(x,1)
ans2=arimasuka(x,-1)
if abs(ans1-x)>=abs(ans2-x):
  print(ans2)
  exit()
else:
  print(ans1)
  exit()

Submission status: Accepted

Solution code:
X, N = [int(i) for i in input().split(' ')]
p_str = input()
p = [] if len(p_str) == 0 else [int(i) for i in p_str.split(' ')]

sorted(p)

j = 0 
while True:
  a = p.count(X+j)
  b = p.count(X-j)
  if b == 0:
    ans = X - j
    break
  if a == 0:
    ans = X + j
    break 
  j += 1

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba
#import math

def run():
    X, N = map(int, input().split())
    P = list(map(int, sysread().split()))
    exist = [False] * 201
    for p in P:
        exist[p] = True
    resid = 0

    while True:
        if not exist[X - resid]:
            print(X - resid)
            return None
        if not exist[X + resid]:
            print(X+resid)
            return None
        resid += 1


if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n != 0:
  p = list(map(int, input().split()))
  pp = set(p)
  ans = 200
  cnt = 0
  for i in range(102):
    if i in pp:
      continue
    if ans > abs(x-i):
      ans = abs(x-i)
      cnt = i
  print(cnt)
else:
  print(x)

Submission status: Accepted

Solution code:
def main():
    X,N = map(int, input().split())
    l = [int(x) for x in input().split()]
    
    ans=0
    if N == 0:
        ans = X
    
    for i in range(100000):
        if not (X-i in l):
            ans=X-i
            break
        elif not(X+i in l):
            ans=X+i
            break
    print(ans)
main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
P = set(list(map(int, input().split())))
ans = 0
diff = x
for a in range(102):
    if a not in P:
        tmp = abs(a-x)
        if diff > tmp:
            diff = tmp
            ans = a
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    x = kwargs["x"]
    n = kwargs["n"]
    P = kwargs["P"]

    for i in range(len(P)):
        P[i] -= x

    res = 0

    while True:
        if not res in P:
            break

        res *= -1

        if not res in P:
            break

        res *= -1

        res -= 1

    res += x
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["x"], kwargs["n"] = [int(i) for i in cin]
    cin = input().split()
    kwargs["P"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

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()
    ans = 10**9
    flag = False
    for i in range(1000):
        for j in range(n):
            if not x - i in p:
                print(x - i)
                flag = True
                break
            if x + i in p:continue
            else:
                print(x + i)
                flag = True
                break
        if flag:break

Submission status: Accepted

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

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

Submission status: Accepted

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

if N==0:
    print(X)
else:
    p = list(map(int, input().split()))
    for i in range(100): #多分100もいらない
        if X-i not in p:
            print(X-i)
            break
        if X+i not in p:
            print(X+i)
            break

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    X, K = MI()
    p = LI()
    diff = []
    ps = set(p)
    c = []

    for i in range(-100, 200):
        if i not in ps:
            c.append(i)

    for i in range(len(c)):
        n = (abs(c[i] - X), i)
        diff.append(n)

    diff.sort()

    # print(diff[:10])

    if len(diff) == 0:
        print(X)
    elif len(diff) == 1:
        print(c[diff[0][1]])
    elif len(diff) > 1:
        if diff[0][0] == diff[1][0]:
            a = c[diff[0][1]]
            b = c[diff[1][1]]
            print(min(a, b))
        else:
            a = c[diff[0][1]]
            print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ls = [i for i in range(102)]
for i in pn:
    ls[i] = 0

ls = list(set(ls))
ans = 0
m = 10**5
for j in ls:
    if abs(x - j) < m:
        m = abs(x - j)
        ans = j

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
zettaiti = float("inf")
for i in range(102):
    if i not in p:
        zettaiti2 = abs(i - x)
        if zettaiti > zettaiti2:
            zettaiti = zettaiti2
            ans = i
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
P = list(map(int, input().split()))
ans = 101
d = ans - x
for i in range(100, -1, -1):
    if i not in P:
        if abs(x-i) <= d:
            d = abs(x-i)
            ans = i
print(ans)