Problem:


Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Accepted

Solution code:
import sys

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

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

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

q = set(range(102))

r = q - p

ans = 0
diff = 1000

for i in r:
  if abs(x - i) < diff:
    diff = abs(x - i)
    ans = i
    
print(ans)

Submission status: Accepted

Solution code:
import sys

X, N = map(int, input().split())
p = list(map(int, input().split()))
flag = 0
if (X in p) is False:
    print(X)
    sys.exit()
Xmin = X
Xmax = X
while flag == 0:
    Xmin = Xmin - 1
    Xmax = Xmax + 1

    if (Xmin in p) is False:

        print(Xmin)
        sys.exit()
    if (Xmax in p) is False:
        print(Xmax)
        sys.exit()

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
P =list(map(int,input().split()))
ans = 1000
point = 0
for i in range(103):
    if i not in P:
        if ans > abs(X-i):
            ans = abs(X-i)
            point = i
print(point)

Submission status: Accepted

Solution code:
#import numpy as np
#import math
#from fractions import gcd

def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    X = first_input[0]
    N = first_input[1]
    if N!=0:
        p_list = list(map(lambda x:int(x), input().split(" ")))
    else:
        print(X)
        return

    if X not in p_list:
        print(X)
        return

    x = X
    for i in range(1,52):
        if x-i not in p_list:
            print(x-i)
            return
        if x+i not in p_list:
            print(x+i)
            return



if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
m = float("inf")
for i in range(-200, 200):
    if i not in p:
        if abs(i-x) < m:
            ans = i
            m = abs(i-x)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def prepare(X):
    N = 101
    List = [X] * N
    for i in range(0, 50):
        List[2*i+1] = X-i-1
        List[2*i+2] = X+i+1
    return List

def remove(List, N, PList):
    for Num in range(N):
        if(PList[Num] in List):
            List.pop( List.index(PList[Num]) )
    print(List[0])
if(__name__ == "__main__"):

    XY = input().strip().split()
    X = int(XY[0])
    N = int(XY[1])

    PList = [0] * N
    if(N > 0):
        P_str = input().strip().split()

        for i in range(N):
            PList[i] = int( P_str[i] )

        List = prepare(X)
        remove(List, N, PList)
    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()))
  Q = [n for n in range(-1000,1000) if n not in P]
  a = 10000
  d1 = 10000
  
  for q in Q:
    d2 = abs(q-X)
    if d2<d1:
      d1 = d2
      a = q
  
  print(a)

Submission status: Accepted

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

if N == 0:
    print(X)
else:
    p = list(map(int,input().split()))
    p.sort()
    q = list(range(p[-1]+2))
    pq=list(set(p)^set(q))
    ind = bisect.bisect_left(pq, X)
    #print("pq",pq,"ind",ind)

    if abs(X-pq[ind]) >= abs(X-pq[ind-1]):
        print(pq[ind-1])
    else:
        print(pq[ind])


#print(min(abs(X-pq[ind]),abs(X-pq[ind]-1)))

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
ans=0
sa=1000
if N==0:
    print(X)
    exit()
for i in range(-1,102):
    tmp=0
    if i in p:
        continue
    else:
        tmp=abs(X-i)
        if tmp<sa:
            sa=tmp
            ans=i
print(ans)

Submission status: Accepted

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

    NP = list()

    for i in range(-500, 501):
        if i in P:
            pass
        else:
            NP.append(i)

    mi = 10000

    for i in range(len(NP)):
        diff = abs(NP[i] - X)

        if diff < mi:
            mi = diff

    ans = list()

    for i in range(len(NP)):
        if abs(NP[i] - X) == mi:
            ans.append(NP[i])

    ans.sort()
    print(min(ans))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

import sys
x, n = map(int, input().split(" "))

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

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

Submission status: Accepted

Solution code:
# 幅優先探索（行きがけ）
import collections
import sys
import math


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    X, N = LI()
    PArry = LI()
    ans = float("inf")
    sa = float("inf")
    for i in range(-N, N+1):
        a = X+i
        if a in PArry:
            continue
        s = abs(X-a)
        if sa == s:
            ans = min(ans, a)
        if s < sa:
            ans = a
            sa = s

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(101):
        if not x - i in p:
            print(x - i)
            break
        if not x + i in p:
            print(x + i)
            break

Submission status: Accepted

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

tmp = x
x_2 = x

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

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

else:
    x -= 1
    if x not in p:
        print(x)
        exit()
    if (x_2 + 1) not in p:
        print(x_2+1)
        exit()

    else:
        x_2 += 1

while True:
    if(x - 1) not in p:
        print(x-1)
        exit()

    else:
        x -= 1
        if (x_2 + 1) not in p:
            print(x_2+1)
            exit()

        else:
            x_2 += 1

Submission status: Accepted

Solution code:
import sys
X, N = map(int, input().split())
if N==0:
    P = {}
else:
    P = set(map(int, input().split()))

answer = sys.maxsize

for i in range(100):
    A = X-i
    B = X+i

    if A in P:
        pass
    else:
        print(A)
        exit()

    if B in P:
        pass
    else:
        print(B)
        exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
	a=list(map(int,input().split()))
	box=[0]*101
	for i in a:
		if -50<= i-x <=50:
			box[50+i-x]=1
	for i in range(51):
		if box[50-i]==0:
			print(x-i)
			break
		elif box[50+i]==0:
			print(x+i)
			break

Submission status: Accepted

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

targets = set(range(-101, 102)) - P
if targets:
    print(min([(target, abs(X - target)) for target in targets], key=lambda x: x[1])[0])
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()))
i = 0
while True:
  l = X - i
  r = X + i 
  if X - i not in P:
    print(X-i)
    exit()
  elif X + i not in P:
    print(X + i)
    exit()
  i += 1

Submission status: Accepted

Solution code:
from typing import List


def forbidden_list(x: int, p: List[int]) -> int:
    for i in range(len(p)):
        if x - i not in p:
            return x - i
        if x + i not in p:
            return x + i
    return x - len(p)


if __name__ == "__main__":
    X, _ = map(int, input().split())
    p = [int(a) for a in input().split()]

    ans = forbidden_list(X, p)
    print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
listP=[]
while True:
    try:
        listP=list(map(int,input().split()))
    except:
        break;
        
candidate_list=list(range(-101,201))
for num in listP:
  candidate_list.remove(num)

for num in range(120):
  minus=candidate_list.count(X-num)
  plus=candidate_list.count(X+num)
  if minus==1:
    print(X-num)
    break
  if plus==1:
    print(X+num)
    break

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()
if p[0]>x or p[-1]<x:
    print(x)
else:
    now=x
    ans1=p[-1]+1
    ans2=p[0]-1
    while now<=p[-1]:
        if now in p:
            now+=1
        else:
            ans1=now
            break
    now=x
    while now>=p[0]:
        if now in p:
            now-=1
        else:
            ans2=now
            break
if abs(x-ans1)>=abs(x-ans2):
    print(ans2)
else:
    print(ans1)

Submission status: Accepted

Solution code:
import queue

X,N = map(int,input().split())
if N == 0:
  print(X)
else:
  p = list(map(int,input().split()))
  
  q = queue.Queue()

  q.put(X)

  while not q.empty():
    a = q.get()
    flag = "true"
    for i in p:
      if a==i:
        flag = "false"
        break
    if flag == "true":
      print(a)
      break
    else:
#    print(a,"は違うよ")
      if a != 0 and X-a >= 0:
        q.put(a-1)
      if a != 101 and X-a <= 0:
        q.put(a+1)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    P=list(map(int,input().split()))
    N=[i for i in range(0,102)]

    for p in P:
        N.pop(N.index(p))

    L=[]
    for a in N:
        l=abs(a-x)
        L.append(l)
    
    m=L.index(min(L))
    print(N[m])

Submission status: Accepted

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

X, N = MAP()
p = LIST()

ans = -1
min_num = float("INF")
for i in range(-1, 102):
    if i in p:
        continue
    
    if min_num > abs(X-i):
        min_num = abs(X-i)
        ans = i


print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
if X not in p:
    print(X)
else:
    n = 1
    ans = ""
    while ans == "":
        if X - n not in p:
            ans = X - n
        elif X + n not in p:
            ans = X + n
        n += 1
    print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = set()
if N != 0:
    p = set(map(int, input().split()))
pp = sorted(list({i for i in range(102)} - p))
ans = -100
for i in pp:
    if abs(X - ans) > abs(X - i):
        ans = i
print(ans)

Submission status: Accepted

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

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

p.sort()

num = [i for i in range(-2, 103)]
for i in p:
    num.remove(i)

for i in range(len(num)):
    if x < num[i]:
        if abs(num[i]-x) >= abs(num[i-1]-x):
            print(num[i-1])
            break
        else:
            print(num[i])
            break

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
ans = float('inf')
find = -1

if n == 0:
    ans = x
    
else:
    p = list(map(int,input().split()))
    next = []
    next.append(x)
    while find == -1:
        y = next.pop(0)
        if all(y != p[i] for i in range(n)):
            ans = y
            find = 0
        else:
            if len(next) == 0:
                next.append(y - 1)
                next.append(y + 1)
            elif y < x:
                next.append(y - 1)
            else:
                next.append(y + 1)
        
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
A = list(map(int, input().split()))
total = [i for i in range(-1, 102)]
for i in range(len(A)):
    total[A[i]+1] = 10000
dif = [0]*103
for i in range(103):
    dif[i] = abs(X-total[i])
min_index = dif.index(min(dif))

print(min_index-1)

Submission status: Accepted

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

arr = [0] * 1000
for i in p:
    arr[i] = 1

ans1 = 0
for i in range(x, -1, -1):
    if arr[i] == 0:
        ans1 = i
        break

# print(arr)

ans2 = 0
for i in range(x, 102):
    if arr[i] == 0:
        ans2 = i
        break

if abs(ans1 - x) <= abs(x - ans2):
    print(ans1)
else:
    print(ans2)

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
if n == 0:
    print(x)
    exit()
p = [int(i) for i in input().split()]
flg = True
ans = 0
d = 0
while flg:
    if not x in p:
        ans = x
        flg = False
        break
    elif not x-d in p:
        ans = x-d
        flg = False
        break
    elif not x+d in p:
        ans = x+d
        flg = False
        break
    else:
        d += 1
print(ans)

Submission status: Accepted

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

    l = [int(i) for i in range(105, -105, -1)]
    for i in range(n):
        l.remove(p[i])
    ans = 105
    for i in range(len(l)):
        if ans >= abs(l[i]-x):
            ans = abs(l[i]-x)
        else:
            return l[i-1]
    



print(solve())

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    smaller = 0
    for i in range(x):
        if x - i in p:
            pass
        else:
            smaller = x-i
            break

    bigger = 2*x
    for j in range(x):
        if x + j in p:
            pass
        else:
            bigger = x + j
            break

    ans = smaller if x - smaller <= bigger - x else bigger
    #print(bigger)
    print(ans)
else:
    print(x)

Submission status: Accepted

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

for i in range(1,100):
  if x not in v:
    print(x)
    break
  if x-i not in v:
    print(x-i)
    break
  elif x+i not in v:
    print(x+i)
    break

Submission status: Accepted

Solution code:
import itertools
import decimal
import math
import collections
import sys
input = sys.stdin.readline

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

if(N==0):
    ans=X
else:
    ListP=list(map(int,input().split()))

    min = 999999
    for i in range(-200,200):
        if(min > abs(X-i)):
            if(i not in ListP):
                min=abs(X-i)
                ans=i


print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
X, Y = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
tmp = 10**9+7
P = set(list(range(-200, 200))) - set(P)
P = list(P)
P.sort(reverse=True)


ans = 0
for i in P:
    if abs(X-i) <= tmp:
        ans = i
        tmp = abs(X-i)

print(ans)

Submission status: Accepted

Solution code:
import sys
a,b = map(int,input().split())
if b==0:
  print(a)
else:
  b = list(map(int,input().split()))
  for i in range(101):
    _min=a-i
    _max=a+i
    if _min not in b:
      print(_min)
      sys.exit(0)
    if _max not in b:
      print(_max)
      sys.exit(0)

Submission status: Accepted

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

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

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

left = 0
right = 101

i = 1
while i <= x:
    if i not in p:
        left = i
    i += 1
while right == 101:
    if i not in p:
        right = i
        break
    i += 1

if x - left <= right - x:
    print(left)
else:
    print(right)

Submission status: Accepted

Solution code:
def main():
	X, N = map(int, input().split(" "))
	if N == 0:
		print(X)
		return
	P = list(map(int, input().split(" ")))
	CONTINUE = True
	dif = 0
	while CONTINUE:
		temp_1 = X - dif
		temp_2 = X + dif
		if (temp_1 not in P):
			print(temp_1)
			CONTINUE = False
		elif (temp_2 not in P):
			print(temp_2)
			CONTINUE = False
		else:
			dif += 1
      
      
    
      
if __name__ == "__main__":
  main()

Submission status: Accepted

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

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

xp = x
xm = x
while True:
    xp += 1
    xm -= 1
    if xp in p and xm in p:
        continue
    elif xm not in p:
        print(xm)
        break
    else:
        print(xp)
        break

Submission status: Accepted

Solution code:
import bisect
x,b=map(int,input().split())
arr=list(map(int,input().split()))
if x not in arr:
    print(x)
    quit()
for i in range(x+1,102):
    if i not in arr:
        ma=i
        break
for i in range(x-1,-2,-1):
    if i not in arr:
        mi=i
        break
if x-mi<=ma-x:
    print(mi)
else:
    print(ma)

Submission status: Accepted

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

if n == 0:
    print(x)
else:    
    p = [int(e) for e in input().split()]

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

Submission status: Accepted

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

if n == 0:
    p = input()
    print(x)
else:
    p = [int(x) for x in input().split(' ')]
    s = set([x for x in range(102)])
    s -= set(p)
    for i in range(0,51):
        if x-i in s:
            print(x-i)
            break
        if x+i in s:
            print(x+i)
            break

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
pi = list(map(int, input().split()))
newpi = [0 for i in range(N)]
for i in range(N):
    newpi[i] = pi[i] - X
for x in range(101):
    if not(((-1) * x) in newpi):
        print((-1) * x + X)
        break
    if not(x in newpi):
        print(x + X)
        break

Submission status: Accepted

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


pn = [0] * 105
nn = [0] * 105


for pp in p:
    a = pp - x
    if a > 0:
        pn[a] = 1
    elif a < 0:
        nn[-a] = 1
    else:
        pn[0] = nn[0] = 1

for i in range(101):
    if nn[i] == 0:
        print(x-i)
        exit(0)
    if pn[i] == 0:
        print(x+i)
        exit(0)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p_li = set(map(int,input().split()))
p = set(range(-200,200))
kouho = p - p_li
ans = 10000
sa_min = 1000000
for i in sorted(list(kouho)):
    sa = abs(X-i)
    if sa_min > sa:
        ans = i
        sa_min = sa
print(ans)

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

x,n = mi()
p =li()

# small side
xs = x
while 1:
    if xs not in p:
        break
    xs -= 1

# large side
xl = x
while 1:
    if xl not in p:
        break
    xl += 1

if x-xs > xl - x:
    print(xl)
else:
    print(xs)

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
P = list(map(int,input().split()))
a = [i for i in range(-220, 220)]
for p in P:
    a.remove(p)

if x in a:
    print(x)
    exit()

l = x-1
r = x+1
for i in range(120):
    if l in a:
        print(l)
        exit()
    l -= 1

    if r in a:
        print(r)
        exit()
    r += 1

Submission status: Accepted

Solution code:
import sys

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

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

p_set = set(P)

if not (X in p_set):
    print(X)
    sys.exit()

for i in range(1, 100):
    if not (X-i in p_set):
        print(X-i)
        break
    if not (X+i in p_set):
        print(X+i)
        break

Submission status: Accepted

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

small = x - 1
large = x + 1
while True:
    if small not in p:
        print(small)
        break
    elif large not in p:
        print(large)
        break
    else:
        small -= 1
        large += 1

Submission status: Accepted

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

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

for i in range(N + 1):
    if X - i not in list_p:
        print(X - i)
        exit()
    elif X + i not in list_p:
        print(X + i)
        exit()

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x,n=n1()

if n==0:
    print(x)
else:
    P=n1()
    if (not x in P):
        print(x)
    else:
        d=[]
        d2=[]
        for i in range(0,102):
            if (not i in P):
                d.append(i)
                d2.append(abs(x-i))

        a=min(d2)
        if (x-a) in d:
            print(x-a)
        else:
            print(x+a)

Submission status: Accepted

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

all_num = [i for i in range(0, 102)]

for p in ps: # 10000
    all_num.remove(p)

diff = 1000
ans = 1000
anss = []

for num in all_num:
    my_diff = abs(num - X)
    if my_diff < diff:
        ans = num
        diff = my_diff

# print('-----output-----')
print(ans)

Submission status: Accepted

Solution code:
a,b = map(float,input().split())
p = list(map(int,input().split()))

t = 10000
for i in range(103,-1,-1):
    if i not in p:
        if abs(a-i)<= t:
            ans = i
            t = abs(a-i)
        # print(t)
print(ans)

Submission status: Accepted

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

def main(x,n,p):
    if (len(p)==0):
        return x

    mindist=102
    nearest=0
    for y in range(0,102):
        if y in p:
            continue
        if abs(x-y) < mindist:
            mindist = abs(x-y)
            nearest=y        
    return nearest

if __name__=='__main__':
    x,n,p=readinput()
    ans=main(x,n,p)
    print(ans)

Submission status: Accepted

Solution code:
import sys

X, N = map(int, sys.stdin.readline().strip().split())
P = set(map(int, sys.stdin.readline().strip().split()))

ans = X
ans_v = X
for i in range(102):
    if i in P:
        continue
    tmp = abs(X - i)
    if tmp < ans or (tmp == ans and i < ans_v):
        ans_v = i
        ans = tmp
        # print(ans, ans_v)
print(ans_v)

Submission status: Accepted

Solution code:
#import numpy as np
import sys
#from collections import deque
#import copy


def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


x, n = xnxn()

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

p = xnxn(flag="l")


i = 0
while True:
    if (x - i in p) == False:
        print(x - i)
        sys.exit()
    elif (x + i in p) == False:
        print(x + i)
        sys.exit()
    i += 1

Submission status: Accepted

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

if n == 0:
  pass
elif x not in p:
  print(x)
else:
  for i in range(1,101):
    if x-i not in p:
      print(x-i)
      break
    elif x+i not in p:
      print(x+i)
      break

Submission status: Accepted

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

for i in range(0,101):
  no = x-i
  if ps.count(no) == 0 & (no > 0):
    print(no)
    exit()
  no = x+i
  if ps.count(no) == 0 & (no < 101):
    print(no)
    exit()

Submission status: Accepted

Solution code:
x, n = [int(x) for x in input().split()]
if n == 0:
    print(x)
else:
    arr = {int(x):True for x in input().split()}
    if x not in arr:
        print(x)
    else:
        left, right = x-1, x+1
        while True:
            if left not in arr:
                print(left)
                break
            elif right not in arr:
                print(right)
                break
            left -= 1
            right += 1

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans_p = X
ans_m = X
while True:
    if ans_m not in P:
        ans = ans_m
        break
    if ans_p not in P:
        ans = ans_p
        break
    ans_p += 1
    ans_m -= 1
print(ans)

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import deque
import pprint

inf = 10**18
mod = 10**9+7

x,n = map(int, input().split())
if n == 0:
    print(x)
    sys,exit()
p = list(map(int, input().split()))
p.sort()
ind = bisect.bisect_left(p,x)
if ind == n:
    print(x)
elif ind == 0:
    if p[ind] != x:
        print(x)
    else:
        print(x-1)
else:
    if p[ind] != x:
        print(x)
    else:
        maxans = 0
        minans = inf
        pre = x
        k = ind
        while k != n and pre == p[k]:
            k+=1
            pre+=1
        maxans = p[k-1]+1
        pre = x
        k = ind
        while k != -1 and pre == p[k]:
            k-=1
            pre-=1
        minans = p[k+1]-1
        ans = 0
        if abs(x-maxans) < abs(x-minans):
            ans = maxans
        else:
            ans = minans
        print(ans)

Submission status: Accepted

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

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

m = [True] * (105)
for i in range(n):
  m[p[i]] = False

l = x
r = x

for i in range(105):
  if m[l] and m[r]:
    print(l)
    exit(0)
  if m[l] and not m[r]:
    print(l)
    exit(0)
  if not m[l] and m[r]:
    print(r)
    exit(0)
  l -= 1
  r += 1

Submission status: Accepted

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



for i in range(1000000):
  x = X-i
  if x not in p:
    print(x)
    exit()
  x = X+i
  if x not in p:
    print(x)
    exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p_li = list(map(int,input().split()))
p_li.sort()
if p_li.count(x) == 0:
    print(x)
    exit()
dum1 = x-1
dum2 = x+1
for i in range(n):
    if p_li.count(dum1) == 0:
        print(dum1)
        exit()
    if p_li.count(dum2) == 0:
        print(dum2)
        exit()
    dum1 -= 1
    dum2 += 1

Submission status: Accepted

Solution code:
import sys
import math as mt
input=sys.stdin.buffer.readline  
#t=int(input())
mod=10**9+7
t=1
for __ in range(t):
    
    x,n=map(int,input().split())
    l=[0]*103
    #n=int(input())
    #a=[[0 for j in range(m)] for i in range(n)]
    p=list(map(int,input().split()))

    for i in range(n):
        l[p[i]]=1
    mini=abs(x)
    ans=0
    #print(l)
    for i in range(102):
        if l[i]==0:
            if abs(x-i)<mini:
                mini=abs(x-i)
                
                ans=i
        
    print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N>0:
    p_set = set(map(int,input().split()))
else:
    p_set = set()
min_dist_xp = 1000
for p in reversed(range(0,102)):
    if p not in p_set:
        dist_xp = abs(X-p)
        if dist_xp<=min_dist_xp:
            min_dist_xp = dist_xp
            ans = p
print(ans)