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
import math
import heapq
import bisect
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

X,N=LI()
L=LI()
L.sort()

# print(L)

for i in range(1000):
    ip=bisect.bisect_left(L, X+i)
    im=bisect.bisect_left(L, X-i)
    # print(i)

    res = None
    if ip >= 0 and ip < N:
        if L[ip] != X+i:
            res = X+i
    else:
        res = X+i

    if im >= 0 and im < N:
        if L[im] != X-i:
            res = X-i
    else:
        res = X-i

    if res != None:
        print(res)
        exit()

Submission status: Accepted

Solution code:

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

    ax, px = x, x
    for i in range(100):
        ax = x + i
        px = x - i
        if px not in p:
            print(px)
            exit(0)
        if ax not in p:
            print(ax)
            exit(0)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A, B = map(int, input().split())
if B != 0:
    li = list(map(int, input().split()))

if B == 0:
    print(A)
else:
    count = 0
    while(1):
        if A - count  not in li:
            print(A-count)
            break
        if A + count not in li:
            print(A + count)
            break
        count += 1

Submission status: Accepted

Solution code:
X ,N= map(int,input().split())
p=[]
if N!=0:
    p = list(map(int, input().split()))
    p = set(p)
for i in range(101):
    if  not((X-i)in p):
        d = -i
        break
    if not ((X+i)in p):
        d = i
        break
    

print(X+d)

Submission status: Accepted

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

not_p = set(range(102)) - set(P)

min_value = 200
min_list = []

for v in not_p:
    dist = abs(X-v)

    if dist < min_value:
        min_value = dist
        min_list = [v]

    if dist == min_value:
        min_list.append(v)

print(min(min_list))

Submission status: Accepted

Solution code:

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

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

Sa=[]

for i in range(100):
    ma=X+i
    mi=X-i
    if mi not in P:
        print(mi)
        sys.exit()
    elif ma not in P:
        print(ma)
        sys.exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
ls = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    i, j = 0, 0
    while True:
        if x + i not in ls:
            num1 = x + i
            break
        else:
            i += 1

    while True:
        if x - j not in ls:
            num2 = x - j
            break
        else:
            j += 1

    if abs(x - num1) > abs(x - num2):
        print(num2)
    elif abs(x - num1) < abs(x - num2):
        print(num1)
    else:
        print(min(num1, num2))

Submission status: Accepted

Solution code:
import sys
x,n=map(int,input().split())
p=set(list(map(int,input().split())))
for i in range(100):
    if x-i in p:
        if x+i in p:

            continue
        else:
            print(x+i)
            sys.exit()
    else:
        print(x-i)
        sys.exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n!=0:
    p=list(map(int,input().split()))
    dif=1000
    ans=-1
    for i in range(0,102):
        if i not in p:
            if abs(x-i)<dif:
                ans=i
                dif=abs(x-i)
    print(ans)
else:
    print(x)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = float("inf")
for i in range(1000):
    if not x - i in p:
        a = x - i
        break
    elif not x + i in p:
        a = x + i
        break
print(a)

Submission status: Accepted

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

a = [i for i in range(1, 1000)]
b = [-i for i in range(1, 1000)]
c = []
for idx in range(len(a)):
    c.append(a[idx])
    c.append(b[idx])
c.append(0)
c.sort()

tmp = []
for i in c:
    if not i in p:
        tmp.append([abs(X-i), i])
tmp2 = [10000000000, -1]
for i in tmp:
    if tmp2[0] > i[0]:
        tmp2[0] = i[0]
        tmp2[1] = i[1]

print(tmp2[1])

Submission status: Accepted

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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''
#import bisect
x,n=map(int, input().split())
p=list(map(int, input().split()))
p.sort()
#n=bisect.bisect_left(x)
if x not in p:
    print(x)
    sys.exit()

for i in range(1,1000-x):
    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:
import bisect

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

p.sort()

temp = 100
temp2 = 0

if(n == 0):
    print(x)
else:
    for i in range(102):
        temp3 = abs(x-i)
        if(temp3 < temp):
            flag = 1
            for j in p:
                if(i == j):
                    flag = 0
            if(flag == 1):
                temp2 = i
                temp = temp3
    print(temp2)

Submission status: Accepted

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

def func1():
    #最初Xそのものがあるか
    if p.count(x)==0:
        print(x)
        return

    for i in range(100):
        if p.count(x-i)==0:
            print(x-i)
            return
        if p.count(x+i)==0:
            print(x+i)
            return
func1()

Submission status: Accepted

Solution code:

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

x, n =na()
p = na()

ans = x
for i in range(100):
    temp = x - i
    if not temp in p:
        print(temp)
        quit()
    temp = x + i
    if not temp in p:
        print(temp)
        quit()

Submission status: Accepted

Solution code:
def main():
  x,n = map(int,input().split())
  if(n==0):
    print(x)
    return 0
  p = list(map(int,input().split()))
  if(not x in p):
    print(x)
    return 0
  d=1
  while(True):
    if(not x-d in p):
      print(x-d)
      return 0
    elif(not x+d in p):
      print(x+d)
      return 0
    d+=1

main()

Submission status: Accepted

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

#####################################################################################

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)












###################################################################
def main():
    #CODE GOES HERE:
    x,n=mi()
    p=li()
    s=set(p)
    for i in range(x,102):
        if i not in s:
            c1=i
            break
    for i in range(x,-2,-1):
        if i not in s:
            c2=i
            break
    if(abs(c1-x)<abs(c2-x)):
        print(c1)
    else:
        print(c2)

        











































""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

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


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Accepted

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

ans = float('inf')
cnt = 0
while ans == float('inf'):
  ans_plus = X + cnt
  ans_minus = X - cnt
  if not ans_plus in P:
    ans = ans_plus
  if not ans_minus in P:
    ans = min(ans, ans_minus)
  cnt += 1

print(ans)

Submission status: Accepted

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

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

ans = [x]
if x in p:
    ans.remove(x)
    i = x
    while i in p:
        i -= 1
    ans.append(i)
    i = x
    while i in p:
        i += 1
    ans.append(i)
    if abs(ans[0] - x) > abs(ans[1] - x):
        ans = [ans[1]]
    else:
        ans = [ans[0]]

print(ans[0])

Submission status: Accepted

Solution code:
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
a = []
for i in range(-2,102):
    if i not in p:
        a.append(i)

m = []
for i in range(len(a)):
    m.append(abs(a[i] - x))

miner = min(m)
res = []
for i in a:
    if abs(x - i) == miner:
        res.append(i)

print(min(res))

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline

x, n = map(int, readline().split())
if n == 0:
    ans = x
else:
    p = list(map(int, readline().split()))
    for i in range(100):
        if (x - i not in p):
            ans = x-i
            break
        if (x + i not in p):
            ans = x+i
            break
print(ans)

Submission status: Accepted

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

ans = X
for i in range(100):
    flag1 = -i in p
    if flag1 == False:
        ans = X - i
        break
    flag2 = i in p
    if flag2 == False:
        ans = X + i
        break

print(ans)

Submission status: Accepted

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

tmp = 10**9
ans = 10**9

if P:
    for p in range(-20, 110):
        if p in P:
            continue
        abs_PX = abs(X-p)
        if abs_PX < tmp:
            ans = p
            tmp = abs_PX
else:
    ans = X

print(ans)

Submission status: Accepted

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

    num = list(range(0, 102))

    ans = [0] * len(num)
    inf = 1000
    for i, n in enumerate(num):
        if n in p:
            ans[i] = inf
        else:
            ans[i] = abs(n-X)

    print(ans.index(min(ans)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n==0:
  print(x)
else:
  p = list(map(int,input().split()))
  numberset = set()
  for i in range(0,102):
    numberset.add(i)
  for s in p:
    numberset.remove(s)
  diff = 100
  mindifint = 101
  for s in numberset:
    if abs(s-x)<diff:
      diff = abs(s-x)
      mindifint = s
    elif abs(s-x)==diff:
      mindifint = min(mindifint,s)
  print(mindifint)

Submission status: Accepted

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

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

if n != 0:
    P = list(map(int, input().split()))

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

bl = False
i = 1
while not bl:
    if (x - i) not in P:
        print(x - i)
        exit()
    if (x + i) not in P:
        print(x + i)
        exit()
    i += 1

Submission status: Accepted

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

Submission status: Accepted

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

X,N=(int(x) for x in input().rstrip('\n').split())
ps=[int(x) for x in input().rstrip('\n').split()]
if N==0:
  print(X)
else:
  for i in range(100):
    if X-i not in ps:
      print(X-i)
      break
    elif X+i not in ps:
      print(X+i)
      break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

x,n=mii()
arr0=limii()

if len(arr0)==0:
    print(x)
    exit()

arr=[]
for i in range(0,102):
    if i not in arr0:
        arr.append(i)
arr.sort()
ans=[10**100,10*100]

for i in reversed(arr):
    if abs(i-x)<ans[1]:
        
        if i<ans[0]:
            ans[0]=min(ans[0],i)
            ans[1]=abs(i-x)
    elif abs(i-x)==ans[1]:
        ans[0]=min(ans[0],i)
print(ans[0])

Submission status: Accepted

Solution code:
def C():
    x,n = list(map(int, input().split()))
    p = list(map(int, input().split()))
    for dist in range(102):
        if x-dist not in p:
            print(x-dist)
            return
        if x+dist not in p:
            print(x+dist)
            return
C()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
P = list(map(int, input().split()))
INF = 10**18
ans = INF
if x not in P:
    print(x)
    exit()
for i in range(-100, 200):
    if i in P:
        continue
    if ans > abs(x-i):
        ans = abs(x-i)
        cnt = i
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math

low = 1
high = 100

#t = int(input())
tmp = input().split()
x,n = list(map(lambda a: int(a), tmp))

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

tmp = input().split()
p = list(map(lambda a: int(a), tmp))

ans=[]
for i in range(102):
	ans.append(0)

#print(ans)

for i in range(n):
	ans[p[i]]+=1

tmp=0
if(ans[x]==0):
	print(x)
	sys.exit()

for i in range(102):
	if(ans[x-tmp]==0):
		print(x-tmp)
		sys.exit()
	if(ans[x+tmp]==0):
		print(x+tmp)
		sys.exit()
	tmp+=1

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(300000)
from bisect import bisect_right, bisect_left

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


X, N = MI()
if N == 0:
    print(X)
    exit()
else:
    P = LMI()
P.sort()
ng = set(P)
m = INF
ans = -1
l, r = min(X - 1, P[0]), max(X + 1, P[-1] + 1)
for i in range(l - 100, r + 100):
    if i in ng:
        continue
    if abs(X - i) < m:
        m = abs(X - i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=map(int,input().split())
P=sorted(p)
PS=[abs(X-y) for y in P]
if N==0:
    print(X)
else:
    if not 0 in PS:
        print(X)
    else:
        for n in range(1,100):
            if PS.count(n)==1:
                place=PS.index(n)
                answer=0
                break
            elif PS.count(n)==0:
                answer=1
                break
        if answer==0:
            if P[place] - X < 0:
                print(X + n)
            else:
                print(X - n)
        else:
            print(X-n)

Submission status: Accepted

Solution code:
import numpy as np

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

P = set(P)
All = set( np.arange(0,102) )
Q = np.array(list(All-P))

Q_X = np.absolute( Q-X )
ans = Q[ np.argmin(Q_X ) ]

print(ans)

Submission status: Accepted

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

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

b, u = x, x
while True:
   b, u = b-1, u+1
   if b not in ps:
      print(b)
      exit()
   if u not in ps:
      print(u)
      exit()

Submission status: Accepted

Solution code:
X, N = [int(i) for i in input().split(' ')]
if N>0:
  p = [int(i) for i in input().split(' ')]
  abs_list = {}

  for i in range(-100,200):
    if(i in p):
      continue
    abs_list[i] = abs(X - i)
  min_k = min(abs_list, key=abs_list.get)
  print(min_k)
else:
  print(X)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
ab = min(abs(101 - x),abs(x))
if abs(101 - x) >= abs(x):
    answer = 0
else:
    answer = 101
for i in range(1,101):
    if i in p:
        continue
    else:
        if ab > abs(x - i):
            ab = abs(x - i)
            answer = i
        elif ab == abs(x-i) and answer > i:
            answer = i
print(answer)

Submission status: Accepted

Solution code:
X,N = (int(x) for x in input().split())
ans = 10000
ansnum = -3
if (N > 0):
    p = list(map(int, input().strip().split()))
    for i in range(-1,102):
        preans = abs(X-i)
        if(preans < ans) and (i in p ) == False:
            ans = preans
            ansnum = i
    print(ansnum)
else:
    print(X)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
N_list =  list(map(int, input().split()))
A = []
for x in range(-100,200):
    A.append(x)
for x in N_list:
    A[x+100] = 1000
m = 200
s = 0
for x in A:
    if abs(X-x) < m:
        m = abs(X-x)
        s = x
print(s)

Submission status: Accepted

Solution code:
''''atcoder beginner contest-170'''

import math
from collections import defaultdict
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''C'''
x,n=rm()
l=True
try:
    a=rl()
except:
    a=[]
b=defaultdict(int)
for i in a:
    b[i]=1
mini=math.inf
value=-1
for j in range(-101,201):
    if b[j]!=1:
        if abs(x-j)<mini:
            mini=abs(x-j)
            value=j
print(value)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = input().split()
p = [int(s) for s in p]
low = X
up = X
while 1 > 0:
    if low not in p:
        answer = low
        break
    elif up not in p:
        answer = up
        break
    low -= 1
    up += 1

print(answer)

Submission status: Accepted

Solution code:
import numpy as np
import sys

x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()
p = np.array(list(map(int, input().split())))
diff = set(p - x)
for i in range(102):
    if -i not in diff:
        print(x-i)
        break
    elif i not in diff:
        print(x+i)
        break

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
Ps =  set(map(int, input().split()))
for i in range(N+1):
    if (X-i) not in Ps:
        print(X-i)
        exit()
    elif (X+i) not in Ps:
        print(X+i)
        exit()

Submission status: Accepted

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    x,n=L()
    if n!=0:p=L()
    z=[]
    for i in range(0,105):
        flag=False
        for j in range(n):
            if i==p[j]:
                flag=True
                break
        if(flag): continue
        z.append(i)
    
    mini=1e+5
    ans=1e+5
    for i in range(len(z)):
        absxz=abs(x-z[i])
        if absxz<mini:
            mini=absxz
            ans=z[i]
    print(ans)
            
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

if N == 0:
    print(X)
elif X not in p_list:
    print(X)
else:
    check_list = []
    for i in range(1, 105+1):
        check_list.append(X-i)
        check_list.append(X+i)

    for el in check_list:
        if el not in p_list:
            break

    print(el)

Submission status: Accepted

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

l=[i for i in range(-3, 102)]

new_l=list(set(l)-set(p))
new_l.sort()

ans=-3
sa=100
for l_i in new_l:
    # print(abs(l_i-x), sa)
    if abs(l_i-x)<sa:
        ans=l_i
        sa=abs(l_i-x)

print(ans)

Submission status: Accepted

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

r_ascend = x
while r_ascend in n_list:
    r_ascend += 1

r_descend = x
while r_descend in n_list:
    r_descend -= 1

if abs(x - r_descend) <= abs(x - r_ascend):
    print(r_descend)
else:
    print(r_ascend)

Submission status: Accepted

Solution code:
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

a,b=ml()
if(b==0):
    n=set()
else:
    n=ll()
    n=set(n)
r=0
for i in range(a,1001):
    if(i not in n):
        r=i
        break
l=0    
for i in range(a-1,-1,-1):
    if(i not in n):
        l=i
        break
if(abs(l-a)<=abs(r-a)):
    print(l)
else:
    print(r)

Submission status: Accepted

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

#!/usr/bin/env python3

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

A = list(map(int, input().split()))
Min = 101

cnt = -200
for i in range(1,400):
    #print(cnt)
    if cnt in A:
        cnt += 1
        continue
    if abs(cnt-X) < Min:
        ans = cnt
        Min = abs(cnt-X)
    cnt += 1
print(ans)

Submission status: Accepted

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

def main():
    X,N = map(int, input().split())
    p = list(map(int, input().split()))
    
    if X not in p:
        ans=X
    else:
        for i in range(100):
            if X-i not in p:
                ans=X-i
                break
            elif X+i not in p:
                ans=X+i
                break
        
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
xn = input('')
x = int(xn.split(' ')[0])
n = int(xn.split(' ')[1])
ps = list(map(int,input().split()))

max_width = 2*x

result = x
for i in range(max_width):
    x1 = x-i
    x2 = x+i
    if x1 not in ps:
        result = x1
        break
    if x2 not in ps:
        result = x2
        break

print(result)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N==0:
    ans = X
else:
    p = list(map(int, input().split()))
    
    finished = False
    cnt = 1

    if X not in p:
        ans = X

    else:    
        while(not finished):
            L = X-cnt
            R = X+cnt

            if L not in p:
                ans = L
                finished = True
            elif R not in p:
                ans = R
                finished = True

            else:
                cnt += 1

print(ans)

Submission status: Accepted

Solution code:
X, N= list(map(int, input().split()))
P = list(map(int, input().split()))
for i in range(0, 51):
    try:
        P.index(X - i)
    except Exception:
        print(X - i)
        break

    try:
        P.index(X + i)
    except Exception:
        print(X + i)
        break