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:
x,n=map(int,input().split())

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

s=[]
ans=0
for i in range(201):
    if x+i in p:
        ans+=1
    else:
        s.append(x+i)

t=[]
for j in range(201):
    if x-j in p:
        ans+=1
    else:
        t.append(x-j)

cnt=min(abs(min(s)-x),abs(max(t)-x))
if abs(min(s)-x)==abs(max(t)-x):
    print(x-cnt)
else:
    if cnt+x in p:
        print(abs(cnt-x))
    else:
        print(cnt+x)

Submission status: Accepted

Solution code:
a=input().split(' ')
X=int(a[0])
N=int(a[1])

if N!=0:
  Ls=input().split(' ')
  L=[]
  for i in range(N):
    L.append(int(Ls[i]))
  for i in range (N+1):
    if X-i in L and X+i in L:
      pass
    elif X-i not in L:
      s=X-i
      break
    elif X-i in L and X+i not in L:
      s=X+i
      break
else:
  s=X


print(s)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
x = a[0]
if a[1] == 0 :
    print(x)
else :
    b = list(map(int,input().split()))
    retu = []
    for i in range(0,102) :
        retu.append(i)
    for i in b :
        if i in retu :
            retu.remove(i)
    k = 1000
    ans = 0
    for i in retu :
        y = abs(i - x)
        if y < k :
            k = y
            ans = i
    print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
import numpy as np
P  = list(map(int, input().split()))
if len(P)==0:
    print(x)
else:
    a = x
    b = x
    for i in range(len(P)+1):
        if a not in P:
            print(a)
            break
        if b not in P:
            print(b)
            break
        a -= 1
        b += 1

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
l=list(map(int,input().split()))
def y(x,l):
    k=0
    while k>-1:
        if x-k not in l:
            return (x-k)

        elif x+k not in l:
            return (x+k)
        else:
            k+=1

print(y(x,l))

Submission status: Accepted

Solution code:
XN = input().split()
X = int(XN[0])
N = int(XN[1])
if N == 0:
    print(X)
else:
    p = input().split()
    A = [None]*N
    for i in range(N):
        A[i] = abs(int(p[i])-X)
    if 0 not in A:
        print(X)
    else:
        j = 1
        while A.count(j) == 2:
            j += 1
        if A.count(j) == 0:
            print(X-j)
        else:
            if str(X-j) in p:
                print(X+j)
            else:
                print(X-j)

Submission status: Accepted

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

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

    num = set(range(-102, 102))

    l = list(num.difference(p))
    l.sort()

    ans = 0
    absol = 110

    for i in l:
        a = abs(X - i)
        if a < absol:
            absol = a
            ans = i
        else:
            pass

    print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
if len(lst) == 0:
    print(X)
    exit()
A = X
while A in lst:
    A -= 1
B = X
while B in lst:
    B += 1
if X-A > B-X:
    print(B)
else:
    print(A)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
try:
    in_li = set(map(int, input().split()))
    num_li = list({i for i in range(min(list(in_li))-1,max(list(in_li))+2)} - in_li)
except:
    in_li = set()
    num_li = []

num_li.sort()
res = 0

if n == 0:
    print(x)
elif x not in in_li:
    print(x)
else:
    for i in num_li:
        if abs(x-i) < abs(x-res):
            res = i
    print(res)

Submission status: Accepted

Solution code:

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


if n <= 0:
    print(x)
else:
    p = list(map(int,input().split()))
    p.sort()
    p2 = [x for x in range(-200,200)]

    p_p2_diff = set(p)^set(p2)
    p_p2_diff_list = list(p_p2_diff)

    min_list = []
    for i in p_p2_diff_list:
        val = abs(x - i)
        min_list.append(val)

    print(p_p2_diff_list[min_list.index(min(min_list))])

Submission status: Accepted

Solution code:
import sys
import numpy as np

X,n=map(int,input().split())
p=list(map(int,input().split()))
if n==0:
    print(X)
    sys,exit()
pp = list(map(lambda x: abs(x-X), p))
pp.sort()
for i in range(1,100):
    tmp=X-pp[0]-i
    if not tmp in p:
        print(tmp)
        sys.exit()
    tmpp=X-pp[0]+i
    if not tmpp in p:
        print(tmpp)
        sys.exit()

Submission status: Accepted

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

def AddV2(v,w):
    return [v[0]+w[0],v[1]+w[1]]

dir4 = [[1,0],[0,1],[-1,0],[0,-1]]


def clamp(x,y,z):
    return max(y,min(z,x))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
#
def Zaatsu(a):
    a.sort()
    now = a[0][0]
    od = 0
    for i in range(n):
        if(now==a[i][0]):
            a[i][0]=od
        else:
            now = a[i][0]
            od+=1
            a[i][0] = od
    
    a.sort(key = lambda x : x[1])
    return a

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rl(x):
    return range(len(x))

# a = list(map(int, input().split()))

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

#31-

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

if(n>0):
    a = list(map(int, input().split()))
else:
    a=[]

val = [0 for i in range(102)]

for i in a:
    val[i]=1

if(val[x]==0):
    print(x)
    exit()
    
for i in range(1,101):
    if(val[x-i]==0):
        print(x-i)
        exit()
    if(val[x+i]==0):
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n > 0:
    P = list(map(int, input().split()))
else:
    P = []

ans, dist = 0, 1000
for i in range(-200, 200):
    if i not in P:
        if abs(i - x) < dist:
            dist = abs(i - x)
            ans = i
print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = list(map(int, input().split()))
num=list(range(-99,201))
for i in range(N):
    num.remove(p[i])
min_=210
for i in range(len(num)):
    s=abs(X-num[i])
    if s<min_:
        min_=s
        min_list=[num[i]]
    elif s==min_:
        min_list.append(num[i])
print(min(min_list))

Submission status: Accepted

Solution code:
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
x,n=get_ints()
p=get_array()
ans1=x 
ans2=x
for j in range(x,-100,-1):
    if j not in p:
        ans1=j 
        break
for k in range(x,200):
    if k not in p:
        ans2=k 
        break
if ans2-x<x-ans1:
    print(ans2)
elif x-ans1<ans2-x:
    print(ans1)
else:
    print(ans1)

Submission status: Accepted

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

if A.count(X)==0:
  print(X)
  exit()

for k in range(N+10):
  if A.count(X-k)==0:
    print(X-k)
    exit()
  elif A.count(X+k)==0:
    print(X+k)
    exit()

Submission status: Accepted

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

t = 0
for i in range(N + 1):
    x = X - i
    y = X + i
    if x in p_list:
        t += 0
    else:
        print(x)
        break
    if y in p_list:
        t += 0
    else:
        print(y)
        break

Submission status: Accepted

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

alpha = x
if not p:
  print(x)
  exit()

for i in range(n+1):
  if alpha in p:
    alpha += (i+1)*(-1)**(i+1)
    continue
  else:
    print(alpha)
    exit()

Submission status: Accepted

Solution code:
import math
X,N=map(int,input().split())
p = list(map(int,input().split()))
abs_list=[0]*N
for i,a in enumerate(p):
    abs_list[i]=a-X
abs_new=sorted(abs_list, key = abs)
flag1=False
flag2=False
flag=False
if N==0:
    flag=True
    print(X)
for i,a in enumerate(abs_new):
    if i%2==1:
        flag1=False
        flag2=False
    if i==0 and a!=0:
        print(X)
        flag=True
        break
    elif (math.floor((i-1)/2)+1)==a:#+がある
        flag1=True
    elif (math.floor((i-1)/2)+1)==(-a):#-がある
        flag2=True
    if i%2==0 and i!=0:
        if flag2==False:
            print(X-(math.floor((i-1)/2)+1))
            flag=True
            break
        elif flag1==False:
            print(X+math.floor((i-1)/2)+1)
            flag=True
            break
if flag==False:
    if abs_new[-1]==0:
        print(X-1)
    elif abs_new[-1]<0:
        if flag1==True:
            print(X+(abs_new[-1]-1))
        else:
            print(X-abs_new[-1])
    else:
        if flag2==True:
            print(X-(abs_new[-1]+1))
        else:
            print(X-abs_new[-1])

Submission status: Accepted

Solution code:
print(sorted((lambda n,p:[[p.count(i),abs(n[0]-i),i] for i in range(-1,102)])(list(map(int,input().split())),list(map(int,input().split()))))[0][2])

Submission status: Accepted

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

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

p_int_set = set(p_int_list)

if X not in p_int_set:
    print(X)
    exit()

for i in range(1, 10000):
    if X - i not in p_int_set:
        print(X - i)
        exit()
    elif X + i not in p_int_set:
        print(X + i)
        exit()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p_list=list(map(int,input().split()))
f_list=list(range(102))
for i in p_list:
    f_list.remove(i)
ans=f_list[0]
for i in f_list:
    if abs(X-ans)>abs(X-i):
        ans=i
print(ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if(N==0):
  print(X)
  exit()
P= list(map(int,input().split()))
c=-100
ans=100000
for i in range(200):
  a=0
  for i in range(200):
    if (abs(X-c)>=abs(X-c-a)):
      if not (c+a in P):
        
        if (abs(X-ans) >=abs(X-c-a)):
          ans=c+a
          
          
    a+=1
  c+=1
if (ans>X):
  if not(X-ans+X in P):
    ans=X-ans+X
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()))

# num=[i for i in range(1,101)]
# for i in p:
#     num[i-1]=-1

# num.append(0)
# num.append(101)
# num.sort()
# while True:
#     if num[0]!=-1:
#         break
#     num.pop(0)
# print(num)

# min=1000
# for i in num:
#     if min>abs(x-i):
#         min=abs(x-i)
#         ans=i
# print(ans)

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

# num=[]
# for i in range(101):
#     num.append(x-i)
#     num.append(x+i)

Submission status: Accepted

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

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

P = input().split()
for i in range(len(P)):
    P[i] = int(P[i])

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


abs_num_p = X + 1
abs_num_n = X - 1
while True:

    if abs_num_p in P:
        flag_p = True
    else:
        flag_p = False

    if abs_num_n in P:
        flag_n = True
    else:
        flag_n = False
    if(  flag_p == True  and flag_n == True ):
        abs_num_p += 1
        abs_num_n -= 1
        continue;
    elif(flag_p == True  and flag_n == False):
        print(abs_num_n)
        break;
    elif(flag_p == False and flag_n == True ):
        print(abs_num_p)
        break;
    elif(flag_p == False and flag_n == False):
        print(abs_num_n)
        break;

    i += 1

Submission status: Accepted

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

p.sort()
s = 0
t = 0

for i in range(0,103-x):
    if x+i not in p:
        s = x+i
        break

for j in range(0,-100,-1):
    if x+j not in p:
        t = x+j
        break

if abs(x-s) < abs(x-t):
    print(s)
else:
    print(t)

Submission status: Accepted

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

Submission status: Accepted

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

def p(i):
    return i+1
def m(i):
    return i-1

if not X in A:
    print(X)
else:
    pl=p(X)
    mi=m(X)
    for _ in range(100):
        if not mi in A:
            print(mi)
            break
        else:
            mi = m(mi)
        if not pl in A:
            print(pl)
            break
        else:
            pl = p(pl)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
  print(x)
  exit()
  
# x, n = 10, 5
# p =  [4, 7, 10, 6, 5]
# ->9が解
# x, n = 6, 5
# p = [4, 7, 10, 6, 5]

# x, n = 1, 1
# # p = list(range(1, 101))
# p = [1]

# pに含まれない整数リストを、最小値-1最大値+1も含めて求める
pl = min(p)-1
pr = max(p)+2
npl = list(range(pl, pr))
np = list(set(npl) - set(p))
if len(np) == 0:
  print(x)
  exit()
np.sort()

# np内で最もxに近い数値を算出する
mx = x
res = np[0]
for k in np:
  t = abs(k - x)
  if t < mx:
    mx = t
    res = k
 
print(res)

Submission status: Accepted

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

flag = [True] * 105
for p in P:
    flag[p] = False

ans = [float("inf"), 0]
for i in range(105):
    if not flag[i]: continue

    if ans[0] > abs(i - X):
        ans[0] = abs(i - X)
        ans[1] = i

print(ans[1])

Submission status: Accepted

Solution code:
print(sorted((lambda n,p:[[p.count(i),abs(n[0]-i),i] for i in range(-100,200)])(list(map(int,input().split())),list(map(int,input().split()))))[0][2])

Submission status: Accepted

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


q = list(range(x-n,x+n+1))


for i in range(len(p)):
    if p[i] in  q:
        q[q.index(p[i])] = 0




a = [0]*len(q)
for i in range(len(q)):
    a[i]  = abs(q[i] - x)


print(q[(a.index(min(a)))])

Submission status: Accepted

Solution code:
x, n = input().split(' ')
line = input()
if line == '':
    print(x)
    exit()

x = int(x)

alist = line.split(' ')
for i in range(int(n)):
    alist[i] = int(alist[i])
if not x in alist:
    print(x)
    exit()

blist = [i for i in range(0,102)]
bset = set(blist)
aset = set(alist)
cset = bset-aset
clist = list(cset)
clist.append(x)
clist.sort()

count = 0
for i,v in enumerate(clist):
    if v == x:
        count = i
if count == 0:
    print(clist[1])
elif count == len(clist)-1:
    print(clist[-2])
else:
    minx = x - clist[count-1]
    maxx = clist[count+1]-x
    if minx > maxx:
        print(clist[count+1])
    else:
        print(clist[count-1])

Submission status: Accepted

Solution code:
import sys
import numpy as np

X, N = (int(item) for item in sys.stdin.readline().split())
p = np.array([int(item) for item in sys.stdin.readline().split()], dtype=np.int8)

# 空配列の時
if N == 0:
    print(X)
    exit()

diff = [0 for _ in range(100)]
for item in p-X:
    diff[abs(item)] += 1
diff_ans = 0
while(True):
    if diff[diff_ans] < 2:
        ans_small = X - diff_ans
        if diff_ans > 0:
            if ans_small in p:
                print(X + diff_ans)
            elif diff_ans:
                print(ans_small)
            break
        elif X not in p:
            print(X)
            break
    diff_ans += 1

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
lis=[i-1 for i in range(103)]
flag=True
if n==0:
  flag=False
  print(x)

if flag:
  p=list(map(int,input().split()))
  for i in p:
    lis.remove(i)
  #print(lis)
  for i in range(len(lis)):
    if lis[i]>x:
      index=i
      break
  if abs(x-lis[index])<abs(x-lis[index-1]):
    print(lis[index])
  else:
    print(lis[index-1])

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
P = list(map(int, input().split()))
sortP = sorted(P)
if N==0:
    print(X)
elif sortP[0]>X:
    print(X)
elif sortP[N-1]<X:
    print(X)
else:
    for n in range(sortP[0]-2,sortP[N-1]+2):
        if n in sortP:
            continue
        if n ==X:
            print(X)
            break
        elif n>X:
            if X-a<=n-X:
                print(a)
                break
            else:
                print(n)
                break
        a = n

Submission status: Accepted

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

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

for i in range(100):
    a = x+i
    b = x-i
    if p.count(b)==0:
        print(b)
        exit()
    elif p.count(a)==0:
        print(a)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
x,n = map(int,input().split())
p = list(map(int,input().split()))
q = []
for i in range(-101,102):
    q.append(i)
for i in range(n):
    q.remove(p[i-1])

def getNearestValue(list, num):

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


print(getNearestValue(q, x))

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if(n==0):
  print(x)
else:
    l=[]
    l1=[]
    li=list(map(int,input().split()))
    for i in range(n+1):
        if x-i not in li:
            l.append(x-i)
        if x+i not in li:
            l1.append(x+i)
    a=max(l)
    b=min(l1)
    if(abs(a-x)>abs(b-x)):
        print(b)
    else:
        print(a)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
b = 0
ue = sita = n
flag = 0

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

while b == 0:
    for i in l:
        if(ue == i):
            flag = 1
            break
            
    if(flag == 0):
        b = 1
        break
        
    flag = 0
    ue += 1
    
b = 0
flag = 0

while b == 0:
    for i in l:
        if(sita == i):
            flag = 1
            break
            
    if(flag == 0):
        b = 1
        break
        
    flag = 0
    sita -= 1
    
##print(ue)
##print(sita)
##print(n)    
    
if(ue-n > n-sita or ue-n == n-sita):
    print(sita)
else:
    print(ue)

Submission status: Accepted

Solution code:
##C
X,N = map(int,input().split())
P = list(map(int,input().split()))
i=0
j = 0
while X+i<=101:
    if X+i not in P:
        ans1 = X+i
        break
    i += 1
while X-j>=-1:
    if X-j not in P:
        ans2 = X-j
        break
    j += 1
if ans1-X>=X-ans2:
    print(ans2)
else:
    print(ans1)

Submission status: Accepted

Solution code:
def main():
  X, N = map(int, input().split())
  if N == 0:
    print(X)
    return
  p = tuple(map(int, input().split()))  
  if X not in p:
    print(X)
    return
  
  not_p = list(set([i for i in range(max(p)+2)]) - set(p))
  not_p_X = [abs(X - i) for i in not_p]
  print(not_p[not_p_X.index(min(not_p_X))])
    
main()

Submission status: Accepted

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

def main():
    if n == 0:
        print(x)
        return

    ans_l = list(range(-100, 201))

    diff_l = list(set(p) ^ set(ans_l))
    diff_l.sort()

    cnt = 100
    ans = 100
    for i in range(0, len(diff_l)):
        check = abs(diff_l[i]-x)
        if check < cnt:
            cnt = check
            ans = diff_l[i]
    print(ans)
    return

main()

Submission status: Accepted

Solution code:
import numpy as np

x,n=map(int,input().split())
a=[]*n
a=list(map(int,input().split()))
answer=0
b=[i for i in range(n+x+10)]
c=list(set(b)-set(a))
d=[x for i in range(len(c))]
e=[abs(x-y) for (x,y) in zip(c,d)]
f=np.argmin(e)
print(c[f])

Submission status: Accepted

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

for i in range(0,100):
    if not x-i in p:
        print(x-i)
        break
    else:
        if not x+i in p:
            print(x+i)
            break

Submission status: Accepted

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

if n!=0:
    p_list=[int(i) for i in input().split()]
    
    if x not in p_list:
        print(x)
        
    else:
        i=1
        while True:
            if (x-i) not in p_list:
                print(x-i)
                break
            elif (x+i) not in p_list:
                print(x+i)
                break
            else:
                i+=1
                


else:
    print(x)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  P = list(map(int, input().split()))
  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
    else:
      pass

Submission status: Accepted

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

not_in_p = list(range(-101,102))
for pn in p:
    if pn in not_in_p:
        not_in_p.remove(pn)

diff_p = []
for not_in_pn in not_in_p:
    diff_p.append(abs(not_in_pn - X))
answer = not_in_p[diff_p.index(min(diff_p))]

print(answer)

Submission status: Accepted

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

if N == 0:
    print(X)

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

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()]
l=[i for i in range(-1,102) if i not in P]
abslist = list(map(lambda a:abs(a-X),l))
print(l[abslist.index(min(abslist))])

Submission status: Accepted

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

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

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

li = []
# res = float('inf')
# for i in n:
#      std = abs(x - p_list[i])
#      if std <= res:
#          res = std    
def dfslower(std) :
    """
    argument x : 基準となる数字
    y 結果となりうる数字？
    return : 結果
    """
    if std  in p_list:
        return dfslower(std-1)
        #print(std)
    else:
        return std
        

def dfsupper(std) :
    """
    argument x : 基準となる数字
    y 結果となりうる数字？
    return : 結果
    """
    if std  in p_list:
        return dfsupper(std+1)
        #print(std)
    else:
        return(std)

mininte = dfslower(x)
maxinte =  dfsupper(x)

if abs(mininte-x)> abs(maxinte -x):
    print(maxinte)
elif abs(mininte-x) <= abs(maxinte -x):
    print(mininte)

Submission status: Accepted

Solution code:
X, N = map(int, input().split(' '))
found = False
goal = 0
challenge_plus = X
challenge_minus = X
# そもそもNが0ならXが正解
# Xを基準に大きい方向、小さい方向の両方向へ1づつ数値をずらしていき、
# p_listにヒットしない整数が合ったときに正解となる。
# 同時に大小ヒットした場合は小さいほうが正解

if(N == 0):
  goal = X
  found = True
else:
  p_list = list(map(int, input().split(' ')))
  max_p = max(p_list)
  min_p = min(p_list)
  #print(X,N)
  #print(p_list)
  #print(max_p, min_p)
  
  if not(X in p_list):
    goal = X
    found = True
  else:
    for i in range(102):
      tmp_break = False
      challenge_plus += 1
      challenge_minus -= 1
      #print("比較対象は{0}, {1}".format(challenge_plus, challenge_minus))
      if not (challenge_plus in p_list):
        goal = challenge_plus
        found = True
        tmp_break = True
      
      if not(challenge_minus in p_list):
        goal = challenge_minus
        found = True
        break
        
      if(tmp_break):
        break

if(found):
  print(goal)
else:
  challenge_plus += 1
  challenge_minus -= 1
  #print("foundが最後までfalseだった例. {0}, {1}".format(challenge_plus, challenge_minus))
  #dist_plus = abs(challenge_plus - X)
  #dist_minus = abs(challenge_minus - X)
  if(dist_plus < dist_minus):
    print(challenge_plus)
  else:
    print(challenge_minus)

Submission status: Accepted

Solution code:
x, n, = map(int, input().split())
p = list(map(int, input().split()))
#print("p = {}".format(p))

ret = 0
diff = 0
flag = False
while True:
    flag = False
    ret = x - diff
    #print("ret = {}".format(ret))
    for i in p:
        if i == ret:
            flag = True
            break
    if flag == False:
        break

    flag = False    
    ret = x + diff
    #print("ret = {}".format(ret))
    for i in p:
        if i == ret:
            flag = True
            break
    if flag == False:
        break

    diff += 1

print("{}".format(ret))

Submission status: Accepted

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

if N == 0:
  print(X)
else:
  p_list = sorted(p_list)
  all_range = list(range(102))
  A = [i for i in all_range if i not in p_list]
  B = [abs(i - X) for i in A]

  low = X - min(B)
  high = X + min(B)

  output = 0
  if high > 101:
    output = low
  if low < 0:
    output = high

  if output != 0:
    print(output)
  elif high in p_list:
    print(low)
  elif low in p_list:
    print(high)
  else:
    print(low)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if p == []:
    print(x)
    exit()
t = [0]*(max(p)+2)
for i in p:
    t[i] = 1

mi = t[:x+1]
ma = t[x:]
mi.reverse()
mii = mi.index(0)
maa = ma.index(0)

if mii < maa:
    print(x-mii)
elif mii > maa:
    print(x+maa)
elif mii == maa:
    print(x-mii)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
m=float("inf")
m1=float("inf")
if n==0:
    print(x)
else:
    for i in range(x,x-100,-1):
        if i not in p:
            m=i
            break
    for i in range(x+1,x+100):
        if i not in p:
            m1=i
            break
    diff=abs(x-m)
    diff1=abs(x-m1)
    if diff<diff1:
        print(m)
    elif(diff>diff1):
        print(m1)
    else:
        print(min(m,m1))

Submission status: Accepted

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

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

    if x not in p:
        print(x)
    else:
        off = 1
        for i in range(200):
            k = x - off
            if k not in p and -99 < k <= 200:
                print(k)
                break
            k = x + off
            if k not in p and -99 < k <= 200:
                print(k)
                break
            off += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

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


x,n = map(int, input().split())
def deflis(n):
    tempn=int(n)
    return tempn-x
num_list = list(map(deflis, input().split()))
num_list.sort()
count=0
maxans=0
minans=0
maxflag=False
minflag=False
minlist=[]
maxlist=[]
for num in num_list:
    if(num<0):
        minlist.append(num)
    elif(num==0):
        minlist.append(num)
        maxlist.append(num)
    else:
        maxlist.append(num)

for mintemp in range(len(minlist)):
    if(minlist[len(minlist)-mintemp-1]==minans):
        minans=minans-1
for maxtemp in maxlist:
    if(maxtemp==maxans):
        maxans=maxans+1

if(abs(minans)>abs(maxans)):
    print(x+maxans)
else:
    print(x+minans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N > 0:
    A = list(map(int,input().split()))
    d = {}
    for i in range(102):
        d[i] = 0
    for a in A:
        d[a] = 1
    for i in range(0,100):
        x = X - i
        y = X + i
        if d[x] == 0:
            print(x)
            quit()
        if d[y] == 0:
            print(y)
            quit()
else:
    print(X)