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:
line = input()
line = line.rstrip().split(' ')

x = int(line[0])
n = int(line[1])

line = input()
line = line.rstrip().split(' ')

p = []

for i in range(n):
    p.append(int(line[i]))
p.sort()

if  n == 0:
    print(x)
else:
    min = p[0] - 1
    max = p[-1] + 1
    answer = 1000
    for i in range(min, max + 1):
        if i in p:
            continue
        if abs(x - i) < abs(x - answer):
            answer = i

    print(answer)

Submission status: Accepted

Solution code:
a = input().split()
X = int(a[0])
N = int(a[1])
OK = []
list = []
if N ==0:
    print(X)
else:
    P = input().split()
    for i in range(102):
        OK.append(str(i))
    for i in range(len(P)):
        OK.remove(P[i])
    for i in range(len(OK)):
        list.append(abs(int(OK[i]) - X))
    Y = list.index(min(list))
    print(OK[Y])

Submission status: Accepted

Solution code:
X, N = map(int, input("").split(" "))
p = list(map(int,input().split()))
p.sort()
q = [i+1 for i in range(-2*X,2*X)]

ans = 0
diff = 100

for i in q:
    if (abs(X - i) < diff and (not i in p)):
        ans = i
        diff = abs(X-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()))
p.sort()
#print(p)

exact=x
ansmin=x-1
ansmax=x+1

for i in range(n):
	if p[i]==exact:
		exact=200
#	if p[i]==ansmin:
#		ansmin-=1
	if p[i]==ansmax:
		ansmax+=1
		
p.sort(reverse=True)
#for i in range(n-1,0,-1):
for i in range(n):
	if p[i]==ansmin:
		ansmin-=1
	
#print(ansmin,exact,ansmax)
	
if exact==x:
	print(exact)
elif abs(ansmax-x)<abs(ansmin-x):
	print(ansmax)
else:
	print(ansmin)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
if n != 0:
  p = sorted(map(int,input().split()))
aa = []
for i in range(1,101):
  if not i in p:
    aa.append(i)
bb = []
if len(aa) == 0:
  if abs(x-(0)) <= abs(x-101):
    print(0)
    exit()
  else:
    print(101)
    exit()
else:
  for A in aa:
    eee = abs(x-A)
    bb.append(eee)

ans = bb.index(min(bb))
if abs(x-(0)) <= min(bb):
  print(0)
  exit()
elif abs(x-101) < min(bb):
  print(101)
  exit()
else:
  print(aa[ans])
  exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
p = list(map(int, input().split()))
ar1 = list(range(102))
ar2 = list(set(ar1) - set(p))
ar3 = sorted(ar2, reverse = True)
diff = 100
for i in ar3:
  if abs(x - i) <= diff:
    diff = abs(x - i)
    ans = i
  else:
    break

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

if X in P:
    for i in range(1,100):

        if not X - i in P:
            print(X - i)
            exit()
        if not X + i in P:
                print(X + i)
                exit()
else:
    print(X)

Submission status: Accepted

Solution code:
# X:整数　N:長さ
# p1 ... pN
# 含まれない整数のうちXに近いものを答える
import sys
X, N = map(int, input().split())
p = []
for i in sys.stdin:
    p = list(map(int, i.split()))
#p = list(map(int, input().split()))
for i in range(X, -51, -1):
    l = i
    if i not in p:
        break
for j in range(X, 151):
    r = j
    if j not in p:
        break
print(l if abs(l-X) <= abs(r-X) else r)

Submission status: Accepted

Solution code:
#H, W = map(int,input().split())
#N = int(input())
#al = list(map(int,input().split()))
X, N = map(int,input().split())
pl = list(map(int,input().split()))

lst = [i for i in range(-101,200)]

anslst = []
for n in lst:
    if not n in pl:
        anslst.append(n)



an = 1000
idx = 0
for i in range(len(anslst)):
    tmp = abs(X - anslst[i])
    if tmp < an:
        an = tmp
        idx = i


ans = anslst[idx]
print(ans)

Submission status: Accepted

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

cnt1 = 0
cnt2 = 0
ans1 = 0
ans2 = 0

for i in range(x,102):
    cnt1 += 1
    if not i in p:
        ans1 = i
        break

for i in range(x,-1,-1):
    cnt2 += 1
    if not i in p:
        ans2 = i
        break

if cnt1 < cnt2:
    print(ans1)
elif cnt1> cnt2:
    print(ans2)
else:
    print(ans2)

Submission status: Accepted

Solution code:
import sys

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

def check(n, X, P):
    if not X - n in P:
        print(X - n)
        sys.exit()
    
    if not X + n in P:
        print(X + n)
        sys.exit()

for n in range(0, 101):
    check(n, X, P)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3
# coding: utf-8

ha = input()
kita = ha.split(" ")
roop = 0
isR = False
if(int(kita[1]) == 0):
    print(kita[0])
else:
    koi = input()
    n = koi.split(" ")

    while(True):
        a = True
        for num in n:
            if(int(kita[0])-roop == int(num)):
                a = False
        if(a):
            print(int(kita[0])-roop)
            break
        a = True
        for num in n:
            if(int(kita[0])+roop == int(num)):
                a = False
        if(a):
            print(int(kita[0])+roop)
            break
        roop += 1

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
if n == 0:
  print(x)
else:
  p_list = list(map(int, input().split()))
  if x in p_list:
    p_list.sort()
    pos = p_list.index(x)
    tmp1 = p_list[-1]+1
    tmp2 = p_list[0]-1
    for i, val in enumerate(p_list[pos+1:]):
      if val != p_list[pos + i] + 1:
        tmp1 = p_list[pos + i]+1
        break
    for i, val in enumerate(p_list[pos-1::-1]):
      if val != p_list[pos - i] - 1:
        tmp2 = p_list[pos - i]-1
        break
    if tmp1 - x < x - tmp2:
      print(tmp1)
    else:
      print(tmp2)
  else:
    print(x)

Submission status: Accepted

Solution code:
x, n = (int(e) for e in input().split())
i = 0
if(n != 0):
    p = list(map(int, input().split()))
else:
    p = -1
flag_f = False
for j in range(n):
    if(p[j] == x):
        flag_f = True
if(flag_f == False):
    print(x)

while(flag_f == True):
    i += 1
    flag_p = False
    flag_m = False
    for j in range(n):
        if(p[j] == x+i):
            flag_p = True
        elif(p[j] == x-i):
            flag_m = True
    if(flag_m == False):
        print(x-i)
        break
    elif(flag_p == False):
        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()))

def judge(p_,x_):
    p_d = list(set(sorted(map(lambda y: np.abs(x_-y),p_))))
    if p_d == []:
        return x_
    for delta in range(100):
        if (x_-delta not in p_):
            return x_-delta
        if (x+delta not in p_):
            return x_+delta
    return x_

print(judge(p,x))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    x, n = map(int, readline().split())
    P = [int(i) for i in readline().split()]
    notP = [i for i in range(-100, 200) if i not in P]
    abcxP = [abs(x-i) for i in notP]
    mi = 10000000
    idx = 0
    for i in range(len(abcxP)):
        if abcxP[i] < mi:
            mi = abcxP[i]
            idx = i
    print(notP[idx])
if __name__ == '__main__':
    main()

Submission status: Accepted

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

if y == 0:
    print(x)
    quit()

ans=[]
for i in range(-101,201):
    if not i in li:
        ans.append(abs(i - x))

if not x - min(ans) in li:
    print(x-min(ans))
elif not min(ans) + x in li:
    print(min(ans) + x)

Submission status: Accepted

Solution code:
import collections
X, N = map(int, input().split())
list = list(map(int, input().split()))
c = collections.Counter(list)
res1=-1000
res2=-1000
for i in range (0, 100):
  if(c[X+i]==0):
    res1=X+i
    if(c[X-i]==0):
      res2=X-i
    break
  if(c[X-i]==0):
    res2=X-i
    break
if(res1==-1000 and res2!=-1000):
  print(res2)
elif(res2==-1000 and res1!=-1000):
  print(res1)
elif(abs(X-res1)<abs(X-res2)):
  print(res1)
elif(abs(X-res2)<=abs(X-res1)):
  print(res2)

Submission status: Accepted

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

for r in range (0,102):
    if (r not in p):
        if (abs(x - int(r)) < k):
            A = int(r)
            k = abs(x - int(r))
if (A > x):
    if (2*x-A not in p):
        A = 2*x-A

print (A)

Submission status: Accepted

Solution code:
temp = list(map(int, input().split()))
X = temp[0]
N = temp[1]
if N > 0:
  num = list(map(int, input().split()))
  nums = [i for i in range(102) if i not in num]
  ans = 0
  for j in nums:
    if abs(j-X) < abs(ans-X):
      ans = j
  print(ans)
else:
  print(X)

Submission status: Accepted

Solution code:
import sys

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

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

smallest = int(2 ** 63 - 1)
ans = x
for i in range(-1000, 1000):
  if i in p:
    continue

  tmp = abs(x - i)
  if tmp < smallest:
    smallest = tmp
    ans = i

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p_list = [int(x) for x in input().split()]
  x_list = list(range(102))
  for i in range(n):
    p_i = p_list[i]
    if p_i in x_list:
      x_list.remove(p_i)
  for i in range(51):
    x_hiku = x - i
    x_tasu = x + i
    if x_hiku in x_list:
      print(x_hiku)
      break
    elif x_tasu in x_list:
      print(x_tasu)
      break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n==0:
    print(x)
else:
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    while i < n and p[i] < x:
        i += 1

    if p[i] != x:
        print(x)
    else:
        j = 1
        up = x+j
        down = x-j
        while True:
            if i-j>=0 and p[i-j] != x-j:
                print(x-j)
                break
            elif i-j < 0:
                print(x-j)
                break
            if i+j<n and p[i+j] != x+j:
                print(x+j)
                break
            elif i+j >= n:
                print(x+j)
                break
            j += 1

Submission status: Accepted

Solution code:
from collections import defaultdict
if __name__ == "__main__":
    x,n = map(int,input().split())
    l = list(map(int,input().split()))
    if n == 0 :
        print(x)
    else :
        l.sort()
        count = 0
        dist = 999
        ans = -100
        for i in range(-100,201) :
            if i in l :
                continue
            if dist > abs(x - i) :
                dist = abs(x - i)
                ans = i 
        print(ans)

Submission status: Accepted

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

    min_val = 0
    diff = abs(x-min_val)
    for i in range(1, 102):
        if diff > abs(x-i) and not(i in p):
            min_val = i
            diff = abs(x-min_val)
        elif diff < abs(x-i) and not(i in p):
            break

    print(min_val)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
m = {}
for i in range(102):
    if i in P:
        continue
    ab = abs(i - X)
    m[i] = ab
# min_kv_list = [kv for kv in m.items() if kv[1] == min(m.values())]
min_k_list = [kv[0] for kv in m.items() if kv[1] == min(m.values())]
print(min(min_k_list))

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted([i for i in range(-102, 102)], reverse=True)

ans = {'diff':1000, 'ans':0}

for i in q:
    if not i in p:
        if abs(x-i) <= ans['diff']:
            ans['diff'] = abs(x-i)
            ans['ans'] = i

print(ans['ans'])

Submission status: Accepted

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

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

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

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:
    ans = x
else:
    p = sorted(p)
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = 0
    if x < min_p:
        ans = x
    elif x > max_p:
        ans = x
    elif x == min_p:
        ans = min_p-1
    elif x == max_p:
        if max_p-1 == p[len(p)-2]:
            ans = max_p+1
        else:
            ans = max_p-1
    else:
        for i in range(min_p-1, max_p+1):
            if i == p[j]:
                j += 1
                if len(p) == j:
                    im_i = p[j-1] +1
                    if abs(ans-x) > abs(im_i-x):
                        ans = im_i
            else:
                if abs(ans-x) > abs(i-x):
                    ans = i
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n > 0:
    ps = list(map(int, input().split()))
else:
    print(x)
    exit()
nums = [n for n in range(-1, 102) if n not in ps]

abs_plus = sorted([n-x for n in nums if n-x >= 0])
abs_minus = sorted([-(n-x) for n in nums if n-x < 0])
if abs_plus == []:
    print(x-abs_minus[0])
elif abs_minus == []:
    print(x+abs_plus[0])
elif abs_plus[0] >= abs_minus[0]:
    print(x-abs_minus[0])
else:
    print(x+abs_plus[0])

Submission status: Accepted

Solution code:
import sys
X, N = [int(x) for x in input().split()]
if N == 0:
    print(X)
    sys.exit()

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

p.sort()

t = []
t.append(p[0] - 1)

for i in range(p[0], p[N-1]+1):
    if i not in p:
        t.append(i)
t.append(p[N-1]+1)

_min = 1000000000000
res = 100000000000
for i in t:
    if abs(X - i) == _min:
        res = min(res, i)
    if abs(X - i) < _min:
        _min = abs(X - i)
        res = i

print(res)

Submission status: Accepted

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

  l100 = list(range(102))
  for i in p:
    if i in l100:
      l100.remove(i)
  sa = []
  for i in l100:
    sa.append(abs(x-i))

  idx = sa.index(min(sa))
  print(l100[idx])

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
p=list(map(int,input().split()))
a=x
b=x
while a in p:
    a-=1
while b in p:
    b+=1
if abs(x-a)>abs(x-b):
    print(b)
elif abs(x-a)<abs(x-b):
    print(a)
else:
    print(min(a,b))

Submission status: Accepted

Solution code:
x , n= map(int,input().split())
p = list(map(int,input().split()))
ans = []
if n == 0:
    print(x)
else:
    for i in range(-10,102):
        if i in p:
            pass
        else:
            ans.append(i)
    sa = []
    for i in range(len(ans)):
        sa.append(abs(ans[i]-x))
    MIN=min(sa)
    for i in range(len(ans)):
        if MIN == abs(ans[i]-x):
            print(ans[i])
            break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if(n > 0):
  p = list(map(int, input().split()))
  lists = list(range(102))
  del lists[0]
  sa = []
  for i in lists:
    if(i in p):
      sa.append(999)
    else:
      sa.append(abs(x-i))
    ind = sa.index(min(sa))
    ans = lists[ind]
else :
  ans = x
if (x <= ans - x):
  ans = 0
print(ans)

Submission status: Accepted

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

dps = set(ps)

i = X
j = X

while True:
    if i not in dps:
        print(i)
        break
    if j not in dps:
        print(j)
        break
    i -= 1
    j += 1

Submission status: Accepted

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

i = 0
while True:

    a = (x + i) in p
    b = (x - i) in p

    if a == False:
        if b == False:
            print(x - i)
            break
        else:
            print(x + i)
            break

    elif b == False:
        if a == False:
            print(x + i)
            break
        else:
            print(x - i)
            break

    i += 1

Submission status: Accepted

Solution code:
X, N = list(map(int, input().split()))
# X, N = 10, 5

def func():
    if N == 0:
        return X

    P = list(map(int, input().split()))
    # P = [4, 7, 10, 6, 5]
        
    diff = 0
    while True:
        if X - diff not in P:
            return X - diff
        if X + diff not in P:
            return X + diff
        diff += 1


print(func())

Submission status: Accepted

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

i = X
ans_big = X

while(True):
  #print("1",i)
  if((i in p_list)==True):
    pass
  else:
    ans_big = i
    break
  i = i + 1
    
i = X
ans_small = X
while(True):
  #print("2",i)
  if((i in p_list)==True):
    pass
  else:
    ans_small = i
    break
  i = i - 1

#print(ans_big,ans_small)
if(abs(X-ans_small)>abs(X-ans_big)):
  print(ans_big)
else:
  print(ans_small)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
if N==0:
	p = [0]
r = 0
n = 0
while True:
    a = X+n
    if a not in p:
        b = a
        r = 1
    a = X-n
    if a not in p:
        b = a
        r = 1
    if r == 1:
        break
    else:
        n +=  1
print(b)

Submission status: Accepted

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

if n!=0:
    a=list(map(int,input().split()))
    a.sort
    x_p=x
    x_n=x
    
    while True:
        if all(elem != x_p for elem in a) and all(elem != x_n for elem in a):
            print(x_n)
            break;
        elif all(elem != x_p for elem in a):
            print(x_p)
            break;
        elif all(elem != x_n for elem in a):
            print(x_n)
            break;
        x_n-=1
        x_p+=1
            
else:
  print(x)

Submission status: Accepted

Solution code:
def main():
  X, N = map(int, input().split()) # スペース区切り入力
  p = [int(x) for x in input().split()]
  a = 1
  
  if N == 0:
    print(X)
  else:
    if X in p:
      while True:
        if X - a in p and X + a in p:
          a += 1
          continue
        elif X - a in p:
          print(X + a)
          break
        else:
          print(X - a)
          break
    else:
      print(X)

    
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import math

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



def main(X, N):
  if N == 0:
    print(X)
    return
     
  p = list(map(int, input().strip().split()))
  if not X in p:
    print(X)
    return
    
  for i in range(math.ceil((N-1)/2)+1):
    a = X-i-1
    b = X+i+1
    if not a in p:
      print(X-i-1)
      return
    if not b in p:
      print(X+i+1)
      return
   
  
main(X, N)

Submission status: Accepted

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

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

  for i in range(100):
  #  print("-i:",p.count(x-i))
  #  print("+i:",p.count(x+i))
    if p.count(x-i) == 0:
      print(x-i)
      break
    elif p. count(x+i) == 0:
      print(x+i)
      break
else:
  print(x)

Submission status: Accepted

Solution code:
import sys

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

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

d = 101

for k in p:
    if d > abs(x - k):
        d = abs(x - k)

for i in range(101):
    if not x - (d + i) in p:
        print(x - (d + i))
        sys.exit()
    elif not x + (d + i) in p:
        print(x + (d + i))
        sys.exit()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
 
if N==0:
    _=input()
    print(X)
    
else:
    Ps=list(map(int,input().split()))
    d=0
    while 1:
        if X-d not in  Ps:
            print(X-d)
            break
        elif X+d not in Ps:
            print(X+d)
            break
        d+=1

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
m=100
ans=0
lis=list(range(101,-1,-1))
for k in lis:
    for l in range(N):
        if k==P[l]:
            lis[101-k]=0
for i in lis:
    if abs(i-X)<=m:
        m=abs(i-X)
        ans=i
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()))
P.append(x)
PP=sorted(P)
if PP.count(x) == 1:
  print(x)
else:
  i=PP.index(x)
  k=1
  high=x
  low=x
  while k>0:
    if PP.count(x+k)==0:
      high=x+k
    if PP.count(x-k)==0:
      low=x-k
    k+=1
    if low!=x:
      print(low)
      exit()
    elif high!=x:
      print(high)
      exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n ==0:
    print(x)
    
else:
    p = list(map(int, input().split()))
    p.sort()
    #print(p)
    ans = 1000
    xx = 0
    for i in range(102):
        if not i in p:
            if x-i>=0 and ans>x-i:
                ans = x-i
                xx = i
            elif i-x>0 and ans>i-x:
                ans = i-x
                xx = i
    print(xx)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
cnt = 0
while True:
    tmp = []
    if x+cnt not in p:
        tmp.append(x+cnt)
    
    if x-cnt not in p:
        tmp.append(x-cnt)
    


    if len(tmp) != 0:
        print(min(tmp))
        break

    cnt += 1

Submission status: Accepted

Solution code:
X,N = list(map(int,input().split()))
if N != 0:
  p = list(map(int,input().split()))
else:
  p = [X+1]
def f(p):
  global X
  return p - X

p2 = list(map(f,p))

p3 = list(map(abs,p2))

OK = 2
j = 0


if min(p3) ==0:
  while(OK==2):
    j+=1
    OK = p3.count(min(p3)+j)
  if OK == 1:
    print(X-p2[p3.index(min(p3)+j)])
  else:
    print(X-j)
else:
  print(X)

Submission status: Accepted

Solution code:
import sys
input1 = list(map(int, input().split()))
X = input1[0]
N = input1[1]
p = list(map(int, input().split()))

if N == 0:
    print(X)
    sys.exit()
elif (X in p) == False:
    print(X)
    sys.exit()

# print(X)
flag = True
diff = 1
# print((X - diff) in p)
while(flag):
    if ((X - diff) in p) == False:
        answer = X - diff
        flag = False
    elif ((X + diff) in p) == False:
        answer = X + diff
        flag = False
    else:
        diff += 1

print(answer)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
min = 0
min_dis = 10**10
ch = [0 for i in range(102)]
for i in range(len(p)):
    ch[p[i]] = 1
for i in range(102):
    idx = 101-i
    if ch[idx] == 0 and abs(x-idx) <= min_dis :
        min = idx
        min_dis = abs(x-idx)
print(min)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
line = sorted(list(map(int,input().split())))
anss = [i for i in range(max(line)+2)]
for i in range(n):
  anss.remove(line[i])
anss.append(x)
ans = sorted(anss)
a = []
for i in range(len(ans)):
  if ans[i] == x:
    a = ans[i-1:i+2]
    break
low = a[1]-a[0]
high = a[2] - a[1]
if high < low:
  print(a[2])
else:
  print(a[0])

Submission status: Accepted

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

if x not in p:
    print(x)
else:
    t = [i for i in range(-101,201)]
    for i in range(n):    
        t.remove(p[i])
#         print(t)

    res = 100
    s = 1000
    for i in range(len(t)):
#         print(t[i])
        if s >= abs (x - t[len(t)-1-i]):
            s = abs (x - t[len(t)-1-i])
            res = t[len(t)-1-i]
    print(res)

Submission status: Accepted

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


l = [0]*200

for i in range(N):
  l[abs(p[i] - X)] += 1

#print(p.index(9))

if N == 0:
  print(X)
else:
  for i in range(N+1):
    if i == 0:
      if l[0] == 1:
        continue
      else:
        print(X)
        break
    else:
      if l[i] == 0:
        print(X-i)
        break
      elif l[i] == 1:
        try:
          p_index = p.index(X-i)
          print(X+i)
        except:
          print(X-i)
        break

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
p = readints()
tmp = list(range(-200, 201))
# print(tmp)
for i in range(n):
    tmp.remove(p[i])
#print('tmp', tmp)
ans = [None]*500

for i in range(len(tmp)):
    ans[tmp[i]] = abs(tmp[i]-x)
# print(ans)
x = 10**5
for i in range(len(ans)):
    if ans[i] != None:
        x = min(x, ans[i])
# print(x)
print(ans.index(x))

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 1
    a = x-1
    b = x+1
    m = min(P[N-1]-X, X-P[0])
    for i in range(1,m+2):
      if a < 0:
        a = 0
      if b > N-1:
        b = N-1
      if X-i != P[a]:
        ans = X-i
        break
      elif X+i != P[b]:
        ans = X+i
        break
      else:
        a -= 1
        b += 1
print(ans)

Submission status: Accepted

Solution code:
# C - Forbidden List

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

    
if x not in p:
    print(x)
else:
    for i in range(1, 100):
        a = x-i
        if a not in p:
            print(a)
            break
        b = x+i
        if b not in p:
            print(b)
            break

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
from bisect import bisect_left
from operator import lt, le
def find_nearst_value(lst, val, left=True):
    """ソート済のリストから，valに最も近い要素を返す.
    @param lst: ソート済のリスト
    @param left:
        lv < val < rv，val-lv == rv-val のとき，
        Trueならばlvを，Falseならばrvを選択する
    @return もっともvalに値が近いlstの要素
    """
    pos = bisect_left(lst, val)
    if pos == 0: return lst[0]
    if pos == len(lst): return lst[-1]
    lv, rv = lst[pos-1:pos+1]
    op = le if left else lt
    return lv if op(val-lv, rv-val) else rv
#======================================================#
def main():
    x, n = MII()
    pp = MII()
    setp = set(pp)
    qq = [i for i in range(200) if not i in setp]
    qq.sort()
    # print(*qq)
    print(find_nearst_value(qq,x))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def MS(): return map(str, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# N = I()
# A = [LI() for _ in range(N)]

import bisect


x,n =MI()
p =LI()
j = 0
while x+j in p and x-j in p:
    j += 1

if not(x+j in p) and not(x-j in p):
    print(x-j)
elif x+j in p:
    print(x-j)
else:
    print(x+j)

Submission status: Accepted

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

    sample = list(range(0,max(p)+2)) 
    reject = list(set(p))

    for i in range(len(reject)):
        sample.remove(reject[i])

    champ = abs(sample[0] - x)
    ans = sample[0]
    for i in range(1, len(sample)):
        if abs(sample[i] - x) < champ:
            champ = abs(sample[i] - x)
            ans = sample[i]
        elif abs(sample[i] - x) == champ:
            if ans >= sample[i]:
                ans = sample[i]
            else:
                pass
        else:
            pass

    print(ans) 

else:
    print(x)

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

for i in range(101):
    tmp1 = x - i
    tmp2 = x + i
    if not tmp1 in p:
        ans = tmp1
        break
    elif not tmp2 in p:
        ans = tmp2
        break

print(ans)

Submission status: Accepted

Solution code:
def challenge(X, numlist, vec):
  while True:
    try:
      numlist.index(X)
    except:
      return(X)
    if vec:
      X -= 1
    else:
      X += 1

list1 = input().split()
X = int(list1[0])
N = int(list1[1])
  
if N == 0:
  print(X)
else:
  list2 = input().split()
  numlist = []
  for i in list2:
    numlist.append(int(i))

  num1 = challenge(X, numlist,True)
  num2 = challenge(X, numlist,False)
  wk1 = abs(X - num1)
  wk2 = abs(X - num2)
  if wk1 > wk2:
    print(num2)
  else:
    print(num1)

Submission status: Accepted

Solution code:
import bisect

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

p.sort()

index = bisect.bisect_left(p,x)

if n==0:
    print(x)
else:
    p= p+[p[n-1]+2]
    for i in range(n):
        # print(index-i, index+i)
        if p[max(index-i,0)] != x-i:
            print(x-i)
            break
        elif p[min(index+i,n)] != x+i:
            print(x+i)
            break
    else:
        print(p[0]-1)