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:
a = list(map(int,input().split()))
if not a[1] ==0:
  b = list(map(int,input().split()))
  b2 = sorted(b)##小さい順に並べる
  if abs(a[0]-b2[0]) <= abs(a[0]-b2[a[1]-1]):#bがすべて連続の場合の対策
    c = b2[0]-a[0]-1
  else:
    c = b2[a[1]-1]-a[0]+1
  if a[0] < b2[0]:
    print(a[0])
  elif a[0] > b2[a[1]-1]:
    print(a[0])
  else:
    for i in range(a[1]-1):
      if abs(b2[i+1]-b[i])>1:
        for j in range(b2[i+1]-b2[i]-1):##差分が1より大きい場合ソート
          if abs(c) > abs(b2[i]-a[0]+j+1):
            c = b2[i]-a[0]+j+1
          elif abs(c) == abs(b2[i]-a[0]+j+1) and c > b2[i]-a[0]+j+1:
            c = b2[i]-a[0]+j+1
    print(c+a[0])
else:
  print(a[0])

Submission status: Accepted

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

if N != 0:
  plist = list(map(int,input().split()))
  plistnew = []
  plistno = []
  anslist = []
  abslist1 = []
  abslist2 = []
  
  for i in range(-5,105):
    plistnew.append(i)
  
  for j in plistnew:
    if j in plist:
      pass
    else:
      plistno.append(j)

  for k in plistno:
    abslist1.append(X-k)
    abslist2.append(abs(X-k))
  
  minabs = min(abslist2)

  for l in range(len(abslist2)):
    if abslist2[l] == minabs:
      anslist.append(plistno[l])
  print(min(anslist))
  
if N == 0:
  print(X)

Submission status: Accepted

Solution code:
import sys

def minCheck(X):
  if X in L:
    return minCheck(X-1)
  else:
    return X

def maxCheck(X):
  if X in L:
    return maxCheck(X+1)
  else:
    return X

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

A = input().split()
L = [int(b.strip()) for b in A]  

#print(L)
if X in L:
  minA = minCheck(X-1)
  maxB = maxCheck(X+1)
  a = abs(X - minA)
  b = abs(X - maxB)
  if a > b:
    print(maxB)
  else:
    print(minA)
else:
  print(X)

Submission status: Accepted

Solution code:
x,n,*p=map(int,open(0).read().split())
print(min({*range(999)}-{*p},key=lambda y:(abs(y-x),y)))

Submission status: Accepted

Solution code:
import sys
def my_index(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default
list_n = [0, -1, 1]
for i in range(2, 101):
  list_n.append(-i)
  list_n.append(i)
X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))
x = [0] * N
for i in range(0, N):
    x[i] = p[i] - X
for i in list_n:
    if my_index(x, i) == -1:
        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()))
    mini = 999
    ANS = 0
    for i in range(102):
        if P.count(i) == 0:
            if mini > abs(X-i):
                mini = abs(X-i)
                ANS = i
    print(ANS)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
else:
  ps = list(map(int, input().split()))
counters = [0 for _ in range(len(ps)+1)]
counters[0] = 1

for i,p in enumerate(ps):
  distance = abs(x - p)
  if distance < len(ps):
    counters[distance] += 1

for i,counter in enumerate(counters):
  if counter == 0:
    print(x-i)
    break
  elif counter == 1:
    if x-i in ps:
      print(x+i)
    else:
      print(x-i)
    break

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
p=list(map(int,input().split()))
if X not in p:
  print(X)
  exit()
else:
  for i in range(200):
    if X-i not in p:
      print(X-i)
      exit()
    elif X+i not in p:
      print(X+i)
      exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
P = list(map(int, input().split()))
for i in range(n + 1):
    if x - i not in P:
        print(x - i)
        exit()
    elif x + i not in P:
        print(x + i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    X, N = [int(i) for i in input().split()]
    if N == 0:
        print(X)
        return
    p_list = [int(i) for i in input().split()]
    min_len_with_X = 200
    min_len_i = 0
    for i in range(102):
        if i in p_list:
            continue
        if abs(i - X) < min_len_with_X:
            min_len_with_X = abs(i - X)
            min_len_i = i
    print(min_len_i)

resolve()

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 or  x+i not in p:
        if x-i not in p:
            print(x-i)
        else:
            print(x+i)

        break
    else:
        i += 1

Submission status: Accepted

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

ans = x
p.sort()  
cnt = 0

for i in range(100):
  if not (x - cnt) in p:
    print(x-cnt)
    exit()
  elif not (x + cnt) in p:
    print(x+cnt)
    exit()
  else:
    cnt += 1

Submission status: Accepted

Solution code:
import math
input_a= input().split(" ")
X=int(input_a[0])
N=int(input_a[1])
dis=X+3
dis2=100
if N!=0:
  array= input().split(" ")
else:
  array=[0,0]

num=X
num2=-100
for i in range(N+1):

  
  if str(num) not in array:
    dis=abs(X-num)
    num2=X-dis
    num1=num
    if str(num2) not in array:
    	numa=min([num,num2])
    else:
      numa=num1
    break
  num=num+1
    

num=X
i=0
for i in range(dis):
  
  if str(num) not in array:
    
    dis2=abs(X-num)
    num3=X+dis2

    if str(num3) not in array:
    	numb=min([num,num3])
    else:
      numb=num
      break
  num=num-1

if dis<dis2:
  print(numa)
elif dis==dis2:
  print(numb)
else:
  print(numb)

Submission status: Accepted

Solution code:
import collections
x,n=map(int,input().split())
if n!=0:
    l=list(map(int,input().split()))
    v=collections.Counter(l)
if n==0:
    print(x)
else:
    for i in  range(101):
        if x not in v:
            ans=x
            break
            
        if x-i not in v:
            ans=x-i
            break
        if x+i not in v:
            ans=x+i
            break
    print(ans)

Submission status: Accepted

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

def minus(num):
    return int(num) - 1


def plus(num):
    return int(num) + 1


if n != 0:
    lst = list(map(int, input().split()))
    for j in range(n):
        count = 0
        for i in lst:
            if x1 == i:
                x1 = minus(x1)
                break
            count += 1
        if count == n:
            break
    for j in range(n):
        count = 0
        for i in lst:
            if x2 == i:
                x2 = plus(x2)
                break
            count += 1
        if count == n:
            break

    if x >= 0:
        ans1 = x - x1
        ans2 = x2 - x
        if ans1 <= ans2:
            print(x1)
        else:
            print(x2)
    else:
        ans1 = (x1 - x) * (-1)
        ans2 = (x - x2) * (-1)
        if ans1 <= ans2:
            print(x1)
        else:
            print(x2)
else:
    print(x)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
not_p = []
if n != 0:
    p = list(map(int, input().split()))
    not_p = [i for i in range(201) if i not in p]
else:
    not_p = [i for i in range(201)]

mn = 101
ans = 100
for i in not_p:
    d = abs(x - i)
    if mn > d:
        mn = d
        ans = i

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  diffs = [i-x for i in range(102)]
  for p_i in p:
    diffs[p_i] = 1000
    ans = 1000
    for n in diffs:
      if abs(ans) > abs(n):
        ans = n
  print(x+ans)

Submission status: Accepted

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

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

    chk_x = False
    pmax = 0
    pmin = 101
    for pr in p:
        if pmax < pr:
            pmax = pr
        if pmin > pr:
            pmin = pr
        if pr == x:
            chk_x = True

    all_i = list(range(0,102))
    target_i = list(set(all_i)^set(p))

    minsub = abs(target_i[0] - x) + 1
    ans = -1
    for i in target_i:
        if abs(i-x) < minsub:
            minsub = abs(i-x)
            ans = i
    if not chk_x:
        print(x)
    else:
        print (ans)

Submission status: Accepted

Solution code:
X, N = list(map(int, input().split()))
if N == 0:
  print(X)
  exit()
p = list(map(int, input().split()))
absp = []
for i in p:
  absp.append(i-X)
if not 0 in absp:
  print(X)
  exit()
for check in range(1,101):
  if not check*(-1) in absp:
    print(X-check)
    exit()
  if not check in absp:
    print(X+check)
    exit()

Submission status: Accepted

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

main1()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
import sys
if n==0:
    _=input()
    print(x)
    sys.exit()
    
p_list=list(map(int,input().split()))
r=list(range(102))
a=list(set(r)-set(p_list))
ans=100000
kkk=100000
for i in a:
    tem=abs(i-x)
    if ans>tem:
        ans=tem
        kkk=i
    
print(kkk)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
q = set(range(0,102))
q = q - set(p)
q_list = list(q)
ans = 100
d = 100
for i in range(102-n):
   if d != min(d,abs(x - q_list[i])):
       ans = q_list[i]
       d = abs(x - q_list[i])
print(ans)

Submission status: Accepted

Solution code:
X,Y=map(int, input().split())
p=list(map(int, input().split()))
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)

Submission status: Accepted

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

    a = [i for i in range(102)]
    for i in range(n):
        a[p[i]] = 1000
    minimum = 1000
    result = 1000
    for i in reversed(range(102)):
        if a[i] != 1000:
            if minimum >= abs(x - a[i]):
                minimum = abs(x - a[i])
                result = a[i]

    print(result)

Submission status: Accepted

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

        num1 = x

        for i in range(n):
            num1 += 1
            if num1 not in p:
                dif1 = num1- x
                break

        num2 = x
        for k in range(n):
            num2 -= 1
            if num2 not in p:
                dif2 = x - num2
                break

        if dif1 > dif2:
            print(num2)
        elif dif1 < dif2:
            print(num1)
        elif dif1 == dif2:
            print(num2)

Submission status: Accepted

Solution code:
x, n = [int(s) for s in input().split(" ")]
if n == 0:
  print(x)
else:
  plist = [int(s) for s in input().split(" ")]

  dlist = {}
  for p in plist:
    d = abs(p - x)
    if d in dlist or d == 0:
      dlist[d] = (True, None)
    else:
      dlist[d] = (False, p - x)

  sorted_d = sorted(dlist.items(), key=lambda x:x[0])

  ans = 0
  prevk = 0
  flag = False
  for k, v in sorted_d:
    if not flag and prevk == 0 and k >= 1:
      ans = 0
      break
    elif k - prevk > 1:
      ans = -(prevk + 1)
      break
    elif not v[0]:
      ans = -v[1]
      break
    flag = True
    prevk = k
    ans = -(k + 1)
  print(x + ans)

Submission status: Accepted

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

nearest = x
sub = 0

if p:
    dets = [i == x for i in p]
    hit = any(dets)
    sub += 1
    while hit:
        nearest = x - sub
        dets = [i == nearest for i in p]
        hit = any(dets)
        if not hit:
            break
        nearest += 2 * sub
        dets = [i == nearest for i in p]
        hit = any(dets)
        if not hit:
            break
        sub += 1

print(nearest)

Submission status: Accepted

Solution code:
data = input().split()
x = int(data[0])
n = int(data[1])

p = input().split()
for i in range(n):
	p[i] = int(p[i])

if n == 0:
	print(x)
	exit()
if not x in p:
	print(x)
	exit()

for i in range(102)[1:]:
	if not (x-i) in p:
		print(x-i)
		exit()
	elif not (x+i) in p:
		print(x+i)
		exit()

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
A = list(map(int, input().split()))
if N == 0:
    print(X)
else:
    if N == 1:
        if A[0] != X:
            print(X)
        else:
            print(X-1)
    else:
        B = []
        for i in range(N):
            B.append(abs(X-A[i]))
        B.sort()
        t = 0
        for i in range(N):
            if (i+1)//2 != B[i]:
                break
            else:
                t = t+1
        if t == N:
            if N%2 == 1:
                print(X-((N+1)//2))
            else:
                k = 0
                for i in range(N):
                    if A[i] == X-(N//2):
                        k = k+1
                if k == 0:
                    print(X-(N//2))
                else:
                    print(X+(N//2))
        else:
            if t%2 == 1:
                print(X-(t+1)//2)
            else:
                k = 0
                for i in range(N):
                    if A[i] == X-(t//2):
                        k = k+1
                if k == 0:
                    print(X-(t//2))
                else:
                    print(X+(t//2))

Submission status: Accepted

Solution code:
num = list(map(int, input().split()))
if num[1] != 0:
    arr = list(map(int, input().split()))
    arr.sort()
    l_num = arr[0]
    l_diff = 10000
    for i in range(arr[0]-1, arr[-1]+2):
        if abs(num[0]-i) < l_diff and i not in arr:
            #print(i, num[0], l_num, abs(i-num[0]))
            l_num = i
            l_diff = abs(num[0]-i)
    print(l_num)
else:
    print(num[0])

Submission status: Accepted

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

lis = [1] * (201)
for p in P: lis[p+99] -= 1

for i in range(100+1):
    up = X+i
    down = X-i
    if lis[100+down-1] == 1:
        print(down)
        exit()
    elif lis[100+up-1] == 1:
        print(up)
        exit()

Submission status: Accepted

Solution code:
X, N = input().split()
X = int(X)
N = int(N)
searchA = X
searchB = X
max = 100
z = X

if N != 0:
  A = list(map(int, input().split()))
  for val in range(max):
    if searchA in A:
      if searchA > -1:
        searchA -= 1
      else:
        continue
    else:
      z = searchA
      break
    if searchB in A:
      if searchB < 102:
        searchB += 1
      else:
        continue
    else:
      z = searchB
      break
    
print(z)

Submission status: Accepted

Solution code:
import numpy as np
x, n = map(int, input().split())
num_list = list(map(int,input().split()))
num_list = sorted(num_list)
num_100 = list(range(-100, 102))

if n ==0:
    print(x)
else:
 for num in num_list:
     num_100.remove(num)

 numbers1 = np.array(num_100)
 numbers2 = numbers1 - x
 numbers3 = np.abs(numbers2)
 min_index = numbers3.argmin()
 print(numbers1[min_index])

Submission status: Accepted

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

i=0

while True:
    if X-i not in P:
        result=X-i
        break
    elif X+i not in P:
        result=X+i
        break
    else:
        i+=1

print(result)

Submission status: Accepted

Solution code:
import sys
x,n=map(int,input().split())
ans=10000
ans1=[]
ans2=[]
if n>0:
    l=list(map(int,input().split()))
else:
    print(x)
    sys.exit()
for i in range(len(l)):
    if abs(ans-l[i])<ans:
        ans1.append(l[i])
        ans1.append(l[i]-1)
        ans1.append(l[i]+1)
ans1=sorted(ans1)
for j in range(len(ans1)):
    if abs(x-ans1[j])<ans and ans1[j] not in l:
        ans2.append(ans1[j])
        ans=min(ans,x-ans1[j])
print(max(ans2))

Submission status: Accepted

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

if n == 0:
    print(x)
elif n ==100:
    if x >50:
        print(101)
    else:
        print(0)
else:
    p = list(map(int, input().split()))
    d = []
    c=0
    for e in p:
        d.append(abs(e-x))
    d1 = d[0]
    z=p[0]
    for i in range(len(d)):
        if d[i] < d1:
            d1 = d[i]
            z = p[i]
    for j in range(1,100):
        for g in p:
            if z+j != g:
                c +=1
                w1 = z+j
        if c == n:
            break
        c = 0
    c=0
    for j2 in range(1,100):
        for g2 in p:
            if z-j2 != g2:
                c +=1
                w2 = z-j2
        if c == n:
            break
        c = 0
    if w2 < 0:
        print(w1)
    elif abs(w1-x) < abs(w2-x):
        print(w1)
    else:
        print(w2)

Submission status: Accepted

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

  for i in range(100):
    plus = (x+i)  in li
    minus = (x-i)  in li
  
    if plus == 1 and minus == 1:
      pass  
    elif plus == 1 and minus == 0:
      print(x-i)
      break
    elif plus == 0 and minus == 1:
      print(x+i)
      break
    else:
      print(x-i)
      break

Submission status: Accepted

Solution code:
x, n = input().split()
pn = map(int,input().split())
ints = [i for i in range(102)]
for p in pn:
  ints[p] = -200

x = int(x)
_min = 200
argmin = -100
for _int in ints:
  if abs(_int - x) < _min:
    _min = abs(_int - x)
    argmin = _int

print(argmin)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
P = list(map(int, input().split()))
maxP = 0 if P == [] else max(P)
le = 1000
for k in reversed(range(X+1)):
  if k not in P:
    le = X-k
    ans = k
    break
# for k in range(X,maxP+1):
for k in range(X,102):
  if k not in P:
    if le > k-X:
      ans = k
      break
print(ans)

Submission status: Accepted

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

if n != 0:
  p = list(map(int, input().split()))
  q = []
  for i in range(102):
    if i in p:
      q.append(150)
    else:
      q.append(abs(i-x))
  list_indexMin = [i for i, v in enumerate(q) if v == min(q)] 
  print(min(list_indexMin))
else:
  print(x)

Submission status: Accepted

Solution code:
import sys
x,n=map(int,input().split())
ans=10000
ansaa=10000
ans1=[]
ans2=[]
ans3=[]
if n>0:
    l=list(map(int,input().split()))
else:
    print(x)
    sys.exit()
for i in range(len(l)):
    if abs(ans-l[i])<ans:
        ans1.append(l[i])
        ans1.append(l[i]-1)
        ans1.append(l[i]+1)
ans1=sorted(ans1)
for j in range(len(ans1)):
    if abs(x-ans1[j])<ans and ans1[j] not in l:
        ans2.append(ans1[j])
        ans=min(ans,x-ans1[j])
print(max(ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X,N = list(map(int,input().split()))
p = list(map(int,input().split()))
s = 1
t = 1
for i in range(100):
    for j in range(N):
        if p[j] == X-i:
            s *= 0
        else:
            s *= 1
        if p[j] == X+i:
            t *= 0
        else:
            t *= 1
    if s == 1:
        print(X-i)
        break
    elif t == 1:
        print(X+i)
        break
    else:
        s = 1
        t = 1

Submission status: Accepted

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

if n ==0:
    print(x)
else:
    for j in range(51):
        ll = []
        if not x-j in p:
            ll.append(x-j)
        if len(ll) != 0:
            print(min(ll))
            break
        if not x+j in p:
            ll.append(x+j)
        if len(ll) != 0:
            print(min(ll))
            break

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
li = []
ans = []
Min_sa = 9999999999
for i in range(-200,201):
    if i not in p:
        li.append(i)
for i in li:
     Min_sa = min(Min_sa,abs(x-i))
for i in li:
    if abs(x-i) == Min_sa:
        ans.append(i)
print(min(ans))

Submission status: Accepted

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

if n == 0 :
    print(x)
    exit()
elif not x in p :
    print(x)
    exit()
p.sort()
mini = abs(x-(p[0]-1))
maxi = abs(x-(p[-1]+1))
indenxX = p.index(x)
for i in range(1,indenxX+1) :
    if p[indenxX-i] !=  x-i :
        mini = i
        break
for i in range(1,n-indenxX) :
    if p[indenxX+i] != x+i :
        maxi = i
        break


if mini <= maxi :
    print(x-mini)
else :
    print(x+maxi)

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
ps = list(map(int,input().split()))
mtmp = x
ptmp = x
rt = True
r = []
if x not in ps:
  print(x)
elif len(ps) == 0:
  print(x)
else:
  while True:
    if mtmp+1 not in ps:
      r.append(mtmp+1)
      rt = False
    if ptmp-1 not in ps:
      r.append(ptmp-1)
      rt = False
    mtmp = mtmp+1
    ptmp = ptmp-1
    if rt:
      continue
    else:
      break
  print(min(r))

Submission status: Accepted

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

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

i = 0
for i in range(100):
    if not x-i in ps:
        print(x-i)
        break
    if not x+i in ps:
        print(x+i)
        break

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N > 0:
    P = list(map(int, input().split()))
    res = float('Inf')
    A = [0]*101
    for n in range(N):
        A[P[n]-1] += 1
    cnt = 1
    man = float('Inf')
    for a in A:
        if a == 0:
            total = abs(X - cnt)
            if res > total:
                res = total
                man = cnt
        cnt += 1
    if abs(X - 0) <= res:
        man = 0
    print(man)
else:
    print(X)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
L=list(map(int,input().split()))
L.append(X)
if L.count(X)==1:
  print(X)
else:
  set(L)
  for i in range(1,X+1):
    if X-i not in L:
      print(X-i)
      break
    elif X+i not in L:
      print(X+i)
      break

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
	print(x)
else:
	l=list(map(int,input().split()))
	if x not in l:
		print(x)
	else:
		v=0
		c=0
		d=0
		for i in range(1,len(l)+1):
			if x-i not in l:
				print(x-i)
				v=1
				break
			else:
				c+=1
			if x+i not in l:
				print(x+i)
				v=1
				break
			else:
				d+=1	
		if v==0:
			print(min(x-c-1,x+d+1))

Submission status: Accepted

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

  ans = X;
  min_value = 202

  if N == 0:
    print(ans)
  else:
    p = list(map(int, input().split()))
    a = [i for i in range(0, 202)]

    for v in p:
      a[v] = -1

    for i in range(0, 202):
      if a[i] != -1:
        d = abs(X - a[i])

        if(min_value > d):
          min_value = d
          ans = i

    print(ans);

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from sys import stdin

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

def solve():
    i = 1
    if N == 0:
        print(X)
        return
    if not X in p:
        print(X)
        return
    while True:
        if not X-i in p:
            print(X-i)
            return
        if not X+i in p:
            print(X+i)
            return
        i += 1

solve()

Submission status: Accepted

Solution code:
#! env/bin/local python3
import sys

x, n = map(int, input().split())
try:
    p = list(map(int, input().split()))
except EOFError:
    print(x)
    sys.exit()

sorted_p = sorted(p, reverse=True)
except_p = [i for i in range(0, 102) if i not in sorted_p]

memory_min = 10000
memory_index = 0

for k, ep in enumerate(except_p):
    if abs(ep - x) < memory_min:
        memory_min = abs(ep - x)
        memory_index = k

print(except_p[memory_index])

Submission status: Accepted

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

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

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

ans = 0
for i in range(1,102):
    if i in a:
        continue
    if abs(x-ans) > abs(x-i):
        ans = i
print(ans)

Submission status: Accepted

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

if N == 0 or p.count(X) == 0: #整数列pが空行のとき、または、Xのカウント回数が0(整数列pにXが含まれない)とき
    print(X)
else:
    for i in range(60): #整数列pとXの絶対値での比較
        i += 1 #iは0から始まるので、あらかじめ+1しておく
        A = X - i
        B = X + i
        if p.count(A) == 0 and p.count(B) == 0: #AもBもカウント回数が0(整数列pにAもBも含まれない)とき
            print(A)
            break
        elif p.count(A) == 0:
            print(A)
            break
        elif p.count(B) == 0:
            print(B)
            break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
p = list(map(int, input().split()))
unique = set(range(0, 102)) - set(p)
ans = {}
ans2 = []
for i in unique:
  calc = abs(x-i)
  if calc in ans.keys():
    ans[calc] = min(ans[calc], i)
  else:
    ans[calc] = i
  ans2.append(calc)
print(ans[min(ans2)])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
*P, = map(int, input().split())
Q = [q for q in range(1000) if q not in P]
dist = 1000
for q in Q:
    if abs(q - x) < dist:
        ans = q
        dist = abs(q - x)
print(ans)

Submission status: Accepted

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

for i in range(1, 101):
    if N == 0:
        print(X)
        break
    elif p.count(X) == 0:
        print(X)
        break
    elif p.count(X-i) == 0:
        print(abs(X-i))
        break
    elif p.count(X+i) == 0:
        print(abs(X+i))
        break

Submission status: Accepted

Solution code:
import bisect
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())))
b = []
if n == 0:
    print(x)
else :
    for i in range(-200, 300):
        if not i in p:
            b.append(i)
    index = bisect.bisect_left(b, x)
    a = abs(x-b[index-1]) 
    c = abs(x-b[index])
    if a <= c:
        print(b[index-1])
    else :
        print(b[index])

Submission status: Accepted

Solution code:
import sys

X, N = map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
p = input().split(" ")
a = X
b = X
for i in range(len(p)):
  for i in range(len(p)):
    if int(p[i]) == a:
      a = a + 1
    if int(p[i]) == b:
      b = b - 1
  #print(int(p[i]))
#print(a,b)
if -1*(X - a) < X - b:
  print(a)
else:
  print(b)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
lst = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
lst.sort()
container = []
store = []
d = []
lst_num = list(range(0, lst[-1] + 2))


for i in lst_num:
    base = lst_num.index(x)
    if i not in lst:
        container.append(i)
for y in container:
    if y < x:
        store.append(y)
    else:
        d.append(y)
if x - max(store) <= min(d) - x:
    print(max(store))
else:
    print(min(d))

Submission status: Accepted

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

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()))
p = sorted(p)
ans_tmp = 10**9+7
ans = 0
if N==0:
    print(X)
else:
    if X not in p:
        print(X)
        exit()
    else:
        tmp1,tmp2 = X-1,X+1
        while True:
            if tmp1 not in p:
                print(tmp1)
                exit()
            if tmp2 not in p:
                print(tmp2)
                exit()
            tmp1 -= 1
            tmp2 += 1

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = []
while True:
  try:
    p = list(map(int, input().split()))
  except EOFError:
    break

for num in range(100 + 1):
  high, low = x + num, x - num
  if low not in p:
    print(low)
    break
  if high not in p:
    print(high)
    break

Submission status: Accepted

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

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

P = [int(x) for x in input().split()]

before = x
after = x
while True:
    if before not in P:
        print(before)
        break
    elif after not in P:
        print(after)
        break
    before -= 1
    after += 1

Submission status: Accepted

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

list_a = []
for a in range(-102,102):
    if a not in p:
        list_a.append(abs(X-a))

m = X - min(list_a)
l = X + min(list_a)
if m not in p:
    print(m)
else:
    print(l)