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:
#!/usr/bin/env python3
import sys


def solve(X: int, N: int, p: "List[int]"):
    for i in range(N):
        if X - i not in p:
            print(X-i)
            return
        elif X + i not in p:
            print(X+i)
            return
    if N == 0:
        print(X)
    else:
        print(X-1)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X, N = map(int , input().split())
p = list(map(int, input().split()))
k = 0
hugou = 1
hantei = 0
while(hantei == 0):
    if(hugou == -1):
        X -= k
    elif(hugou == 1):
        X += k

    if(X not in p):
        print(X)
        hantei = 1
    else:
        if(hugou == 1):
            hugou = -1
        elif(hugou == -1):
            hugou = 1
        k += 1

Submission status: Accepted

Solution code:
num = input().split()
num=[int(i) for i in num]

if num[1]!=0:
  line = input().split()
  line=[int(i) for i in line]

  m=0
  while m>=0:
    if num[0]-m not in line:
      print(num[0]-m)
      break
    elif num[0]+m not in line:
      print(num[0]+m)
      break
    else:
      m+=1

else:
  print(num[0])

Submission status: Accepted

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

if N == 0:
    _ = input()
    print(X)
else:
    p = { int(i) for i in input().strip().split(' ')}

    all_set = { n for n in range(-1, 101+1, 1)}
    candidates = list(all_set - p)
    best_distance = 1000
    cand = -2
    for c in candidates:
        distance = abs(c-X)
        if best_distance > distance:
            cand = c
            best_distance = distance
    print(cand)

Submission status: Accepted

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

is_exit = [False] * 101

for p in P:
    is_exit[p] = True

if not is_exit[X]:
    print(X)
else:
    l = X - 1
    r = X + 1
    while True:
        if 1 <= l:
            if not is_exit[l]:
                print(l)
                exit()
        else:
            print(l)
            exit()
        if r <= 100:
            if not is_exit[r]:
                print(r)
                exit()
        else:
            print(r)
            exit()
        l -= 1
        r += 1

Submission status: Accepted

Solution code:
def _main(x, p_list):
    p_set = set(p_list)
    diff = 0
    while True:
        t_minu = x - diff
        if t_minu not in p_set:
            print(t_minu)
            break

        t_plus = x + diff
        if t_plus not in p_set:
            print(t_plus)
            break
        diff += 1


# if __name__ == "__main__":
x_a, n_a = map(int, input().split())
p_list_a = map(int, input().split())
_main(x_a, p_list_a)

Submission status: Accepted

Solution code:
from collections import defaultdict
it = lambda: list(map(int, input().strip().split()))
INF = float('inf')

def solve():
    X, N = it()
    arr = it()
    res = [False] * 102
    for i in range(N):
        res[arr[i]] = True
    
    i = X
    j = X
    while i >= 0 and j <= 101:
        if not res[i]:
            return i
        elif not res[j]:
            return j
        i -= 1
        j += 1

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
a = x-1
b = x+1

if x not in p:
    ans = x

else:
    while 1:
        if a not in p:
            ans = a
            break

        if b not in p:
            ans = b
            break

        a -= 1
        b += 1
    
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = set(map(int, input().split()))
U = set(range(-200, 201))
diff = sorted(list(U - P))

ans = 0
tmp = float('inf')
for i in diff:
    if tmp > abs(X - i):
        tmp = abs(X - i)
        ans = i
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X,N=(int(x) for x in input().split())
p=list(map(int,input().split()))
ans_sa=101
ans=-1
for n in range(-1,102):
    if n in p:
        continue
    sa=abs(X-n)
    if sa<ans_sa:
        ans_sa=sa
        ans=n
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
x,n = map(int,input().split())
b = 0
if n == 0:
  a = 1
else:
  b = [int(i) for i in input().split()]
  b.sort(reverse = True)
if b == 0:
  print(x)
else:
  c = [int(i) for i in range(102)]
  for i in b:
    c.pop(i)
  print(getNearestValue(c,x))

Submission status: Accepted

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

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

else:
    if not x in p:
        print(x)
        sys.exit()
    else:
        a1 = x - 1
        a2 = x + 1
        c = 0
        while True:
            if c % 2 == 0:
                if not a1 in p:
                    print(a1)
                    break
                else:
                    a1 -= 1
            else:
                if not a2 in p:
                    print(a2)
                    break
                else:
                    a2 += 1
            c += 1

sys.exit()

Submission status: Accepted

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

p = set(map(int, input().split()))
a = set([i for i in range(105)])
np = a-p

ans = 0
dist = 1000000
for i in np:
  if(abs(x-i) < dist):
    dist = abs(x-i)
    ans = i
  elif(abs(x-i) == dist):
    ans = min(i, ans)
  else:
    pass
  
print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,(input().split()))
p = list(map(int,(input().split())))
ans = []
for i in range(0,102):
    if i not in p:
        m = abs(i-X)
        ans.append((m,i))
ans.sort()
print(ans[0][1])

Submission status: Accepted

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

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

for i in range(0,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 = list(map(int,input().split()))
else:
    p = []

result = []

i = 0

while len(result) == 0:
    if not (x - i in p):
        result.append(x - i)
    if not (x + i in p):
        result.append(x + i)
    
    i += 1

print(int(min(result)))

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if(N == 0):
    print(str(X))
    exit()
p = list(map(int,input().split()))
p = sorted(p)
tmp = 200
for i in range(102):
    if(i in p):
        pass
    else:
        tmp2 = abs(X-i)
        if(tmp2 < tmp):
            tmp = tmp2
            ans = i
        elif(tmp2 == tmp):
            pass
print(str(ans))

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
q = set(range(-1, 102))
r = list(q - set(p))
r.sort()
max = 1000
ans = X

if N == 0:
    print(X)
else:
    for i in r:
        if abs(X - i) < max:
            max = abs(X - i)
            ans = i

    print(ans)

Submission status: Accepted

Solution code:
def resolve():
    x,n = map(int, input().split())
    if n==0:
        print(x)
    else:
        a = list(map(int, input().split()))
        ans=0
        for i in range(102):
            if i not in a:
                if abs(ans-x)>abs(i-x):
                    ans=i
        print(ans)
resolve()

Submission status: Accepted

Solution code:
#from bisect import bisect_left

def main():
    X, N = tuple(int(c) for c in input().split(' '))
    if N==0:
        print(X)
        exit()
    p = set(int(c) for c in input().split(' '))
    q = [x for x in range(-2,102) if not x in p]
    q.sort()
    #print(q)

    minimum = 1000
    for x in q:
        d = abs(x-X)
        d2 = abs(minimum-X)
        if d < d2:
            minimum = x
    print(minimum)

    #index = bisect_left(p, X)
    #if 


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint


def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def main():
    x,y=map(int,input().split())
    n=list(map(int,input().split()))
    n=sorted(n)
    iti=x
    minn=10000

    for i in range(iti, 102):
        if i not in n:
            if abs(x - i) < abs(minn - x):
                minn = i
                break
    for i in range(iti,-1,-1):
        if i not in n:
            if abs(x-i)<=abs(minn-x):
                minn=i
                break
    print(minn)







if __name__ == "__main__":

    main()

Submission status: Accepted

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

score = 1000
answer = -1
for i in range(-1, 102):
    if i in p:
        continue
    if abs(X - i) < score:
        score = abs(X - i)
        answer = i
print(answer)

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()))
if not(x in p):
  print(x)
  sys.exit()
p.sort()
r=[]
for i in range(len(p)):
  if p[-1]>x: r.append(p.pop())
p.reverse()
r.reverse()
d=1
while True:
  if not(x-d in p):
    print(x-d)
    break
  elif not(x+d in r):
    print(x+d)
    break
  d+=1

Submission status: Accepted

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

for i in range(110):
    xm = x - i
    xp = x + i
    if xm not in p:
        ans = xm
        break
    elif xp not in p:
        ans = xp
        break
    else:
        continue
print(ans)

Submission status: Accepted

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

p_list = list(map(int, input().split()))
counter = 1

if x in p_list:
    while 1:
        if (x - counter) not in p_list:
            print(x - counter)
            break
        elif (x + counter) not in p_list:
            print(x + counter)
            break
        counter += 1
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()))
a = 0
for i in range(52):
    if  not x-a in p:
        print(x-a)
        exit()
    elif not x+a in p:
        print(x+a)
        exit()
    else:
        a += 1

Submission status: Accepted

Solution code:
import sys
import numpy as np

# 実行環境(0:vscode, 1:atcoder)
MODE = 1

# 入力の次元
DIMENSION = 2

# int型に変換
INT_TYPE = 1

if not (MODE):
    with open("input.txt", "r") as f:
        s = f.read()
else:
    s = sys.stdin.read()

if DIMENSION == 0:
    if INT_TYPE == 1:
        s = int(s)
elif DIMENSION == 1:
    if INT_TYPE == 0:
        s = s.split()
    elif INT_TYPE == 1:
        s = [int(x) for x in s.split()]
elif DIMENSION == 2:
    if INT_TYPE == 0:
        s = [x.split() for x in s.splitlines()]
    elif INT_TYPE == 1:
        s = [[int(y) for y in x.split()] for x in s.splitlines()]

if len(s) == 1:
    print(s[0][0])
    exit()

X, N = s[0]
P = s[1]

x_upper = X
x_lower = X
while 1:
    if P.count(x_lower) == 0:
        print(x_lower)
        exit()
    elif P.count(x_upper) == 0:
        print(x_upper)
        exit()
    x_upper += 1
    x_lower -= 1

Submission status: Accepted

Solution code:
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    ls = [1, 2, 3, 5]
    X, N = input_number_list()
    P = input_number_list()
    if P.count(X) == 0:
        print(X)
        return
    d = 1
    while True:
        if P.count(X - d) == 0:
            print(X - d)
            break
        elif P.count(X + d) == 0:
            print(X + d)
            break
        d += 1


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
x, n = [int(i) for i in input().split()]
if n != 0:
  ps = np.array([int(i) for i in input().split()])

  ps.sort()

  m = -1000
  ans = m
  di = 0
  while ans == m:
    if not x - di in ps:
      ans = x - di
    elif not x + di in ps:
      ans = x + di
    di += 1
else:
  ans = x
print(ans)

Submission status: Accepted

Solution code:
date=input().rstrip().split(" ")
X=int(date[0])
N=int(date[1])
if N==0:
    print(X)
else:
    date0=list(map(int, input().split(" ")))
    date0=sorted(date0)
    if date0.count(X)==0:
        print(X)
    else:
        for i in range(1,51):
            C=date0.count(X-i)
            D=date0.count(X+i)
            if C==0:
                print(X-i)
                break
            elif D==0:
                print(X+i)
                break

Submission status: Accepted

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

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

ans = math.inf
off = 0
while ans == math.inf:

    left = x - off
    right = x + off

    try:
        p.index(left)
    except:
        print(left)
        exit()

    try:
        p.index(right)
    except:
        print(right)
        exit()
    off+=1

Submission status: Accepted

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

if(x not in t):print(x);exit()
down = x-1
up = x+1
while(True):
    if down not in t:print(down);exit()
    if up   not in t:print(up);exit()
    down-=1
    up+=1

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = set(map(int, input().split())) if N > 0 else set()
for i in range(101):
    if X-i not in P:
        print(X-i)
        exit()
    if X+i not in P:
        print(X+i)
        exit()

Submission status: Accepted

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

ans = x
for i in range(2*n):
    if x-i not in nums:
        ans = x-i
        break
    elif x+i not in nums:
        ans = x+i
        break
    else:
        continue
print(ans)

Submission status: Accepted

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

    if not (X in set(p)):
        print(X)
        return

    bucket = [False] * 102
    for i in range(N):
        bucket[p[i]] = True
    
    high = 0
    low = 0
    for i in range(X,102):
        if not bucket[i]:
            high = i
            break

    for i in range(X,0,-1):
        if not bucket[i]:
            low = i
            break

    if abs(X-high) > abs(X-low):
        print(low)
    elif abs(X-high) == abs(X-low):
        print(min(low,high))
    else:
        print(high)
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
ans=101
for i in range(103):
  if 101-i not in p:
    if abs(x-(101-i))<=abs(x-ans):
      ans=101-i
print(ans)

Submission status: Accepted

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

v = 0
if N == 0:
    print(X)
else:
    while True:
        res = X - v
        if not res in p:
            break
        res = X + v
        if not res in p:
            break
        v += 1
    print(res)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n > 0:
    p = list(map(int, input().split()))
    for i in range(n + 1):
        if (x - i) not in p:
            print(x - i)
            break
        
        if (x + i) not in p:
            print(x + i)
            break
    
else:
    print(x)

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
P = list(map(int,input().split()))
Q = []
ans = 100
for i in range(-100,101):
    if i+1 in P:continue
    else:
        Q.append(i+1)
for j in Q:
    d = abs(j - x)
    ans = min(d, ans)

l = x -ans
m = x + ans
if l in Q:
    print(l)
else:
    print(m)

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

num1 = X-1
num2 = X+1
if X not in p:
  print(X)
  sys.exit()
while 1:
  if num1 == 0:
    print(num1)
    break
  if num1 in p and num2 not in p:
    print(num2)
    break
    
  elif num1 not in p and num2 in p:
    print(num1)
    break
  elif num1 not in p and num2 not in p:
    print(num1)
    break
  else:
    num1 -= 1
    num2 += 1

Submission status: Accepted

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

  if N == 0:
    return print(X)

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

  P2 = set([abs(p-X) for p in P])
  #print(P2)
  for i in range(101):
    ans1 = X - i
    ans2 = X + i
    #print(i, ans1, ans2)
    if ans1 not in P:
      print(ans1)
      return
    if ans2 not in P:
      print(ans2)
      return
  
main()

Submission status: Accepted

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

for i in range(100):
    m = X-i
    n = X+i
    if m not in nums: 
        print(m)
        break
    elif n not in nums: 
        print(n)
        break

Submission status: Accepted

Solution code:
x,n=map(int, input().split())
P=list(map(int, input().split()))
ans=[]
for i in range(102):
    ans.append(i)

m=99999999999999
for p in P:
    del ans[ans.index(p)]
y=99999999999999
#print(ans)
for i in ans:
    if abs(i-x)<y:
        y=abs(i-x)
        m=i

print(m)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if(n==0):
    print(x)
else:
    ans=99999999999
    s=set(list(map(int,input().split())))
    # print(s)
    for i in range(200,-1,-1):
        if i not in s:
            if(abs(x-i)<=abs(x-ans)):
                ans=i
    print(ans)

Submission status: Accepted

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

INF = 10 ** 10


def solve(x, n, ps):
    qs = sorted(set(range(0, 103)) - set(ps))
    delta = INF
    val = INF
    for q in qs:
        new_delta = abs(q - x)
        if new_delta < delta:
            delta = new_delta
            val = q
    return val


def main():
    x, n = (int(z) for z in input().split())
    ps = [int(p) for p in input().split()]
    res = solve(x, n, ps)
    print(res)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
p_list = list(map(int,input().split()))
p_list.sort()
ans_sa = abs(-1-x)
ans = -1
for i in range(0,200):
    if i in p_list:
        pass
    else:
        if ans_sa > abs(i-x):
            ans_sa = abs(i-x)
            ans = i
        elif ans_sa == abs(i-x):
            ans = min(ans,i)

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
l=list(map(int,input().split()))
l=set(l)
k=0
a=x
b=x
while True:
  if a-k not in l:
    print(a-k)
    exit()
  if a+k not in l:
    print(a+k)
    exit()
  k+=1

Submission status: Accepted

Solution code:
targ, length = map(int, input().split(' '))

banned = [False] * 100

bans = input()
if bans != '':
    for ban in bans.split(' '):
        banned[int(ban) - 1] = True

for dist in range(100):
    if targ - dist > 0:
        if not banned[targ - dist - 1]:
            print(targ - dist)
            exit()
    else:
        print(targ - dist)
        exit()
    if targ + dist <= 100:
        if not banned[targ + dist - 1]:
            print(targ + dist)
            exit()
    else:
        print(targ + dist)
        exit()

Submission status: Accepted

Solution code:
import itertools
from collections import deque,Counter
import bisect
import heapq

def IN(): return int(input())
def sIN(): return input()
def MAP(): return map(int,input().split())
def LMAP(): return list(map(int,input().split()))
def TATE(n): return [input() for i in range(n)]
MOD = 10**9 + 7

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()
for i in range(1,5555555):
  a = x-i
  b = x+i
  if a not in p and b not in p:
    print(a)
    exit()
  if a not in p and b  in p:
    print(x-i)
    exit()
  if b not in p and a in p:
    print(x+i)
    exit()

Submission status: Accepted

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

ans=[float("inf"),float("inf")]
for i in range(102):
    if i in P:
        continue
    tmp=abs(i-X)
    if tmp<ans[0]:
        ans[0]=tmp
        ans[1]=i
print(ans[1])

Submission status: Accepted

Solution code:

import sys
import math
import itertools
import collections

def solve(X,N,P):
    ans = {i for i in range(-200,201,1)}
    ans -= set(P)
    result = 10**2
    q = []
    for a in list(ans):
        target = abs(X - a)
        if(result == target):
            q.append(a)
        elif(result > target):
            result = target
            q = [a]
    return min(q)
def main():
    X,N = map(int,input().split())
    P = list(map(int,input().split()))
    # solve()
    print(solve(X,N,P))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys 
from collections import deque
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def LS(): return list(sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def main():
    x,n = IL()
    p = LI()
    i=0
    while True:
        if i==0:
            if not x in p:
                print(x)
                exit()
        else:
            if not x-i in p:
                print(x-i)
                exit()
            if not x+i in p:
                print(x+i)
                exit()
        i+=1
    return

if __name__=='__main__':
    main()

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):
    if not X-i in p:
        print(X-i)
        break
    elif not X+i in p:
        print(X+i)
        break
    i += 1

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
l = set(list(map(int,input().split())))
for i in range(max(x,100-x)+1):
    if x-i not in l:
        print(x-i)
        exit()
    if x+i not in l:
        print(x+i)
        exit()

Submission status: Accepted

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

n = 0
while True:
    candidate = X - n
    if candidate not in l:
        print(candidate)
        break
    candidate = X + n
    if candidate not in l:
        print(candidate)
        break
    n += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
xn = list(map(int, input().split()))
pn = list(map(int, input().split()))

for i in range(100):
    if(not ((xn[0] - i) in pn)):
        print(xn[0] - i)
        break
    if(not ((xn[0] + i) in pn)):
        print(xn[0] + i)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
X,N = map(int,input().split())
lisP = list(map(int,input().split()))

tmp = 1000
ans = 1000
for p in range(-120,121):
    if p in lisP:
        continue
    num = abs(X-p)
    if num == tmp:
        ans = min(ans,p)
    elif num < tmp:
        tmp = num
        ans = p

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
p = list(map(int,input().split()))
minimum = [-1,float('inf')]
item = [0]*102
for pi in p:
    item[pi] = 1
for i in range(102):
    if item[i] == 0 and minimum[1] > abs(x-i):
        minimum[1] = abs(x-i)
        minimum[0] = i
print(minimum[0])

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
result = X
if N == 0:
    print(X)
    import sys
    sys.exit()

arr = [i for i in range(max(P)+2) if i not in P]
diff = [abs(i - X) for i in arr]

print(arr[diff.index(min(diff))])

Submission status: Accepted

Solution code:
import numpy as np
import functools
import operator
import sys

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

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

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

L = [x for x in range(max(ps) + 3)]

for p in ps:
    L.remove(p)


# min2nd_absval = 100000000
min_absval = 100000000
val = 100000
for i, l in enumerate(L):
    absval = abs(l - X)

    if min_absval > absval:
        min_absval = absval
        val = l


print(val)

Submission status: Accepted

Solution code:
def main():
    X, N = map(int, input().split())
    if N != 0:
        A = list(map(int, input().split()))
    else:
        A = []
    min_diff = 1e5
    for i in range(0, 102):
        if i not in A:
            min_diff = min(min_diff, abs(i - X))
    
    for i in range(0, 102):
        if i not in A and abs(i - X) == min_diff:
            print(i)
            return 
  
if __name__ == '__main__':
    main()

Submission status: Accepted

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


  for i in P:
    list[i]=-1

  sa=10**3
  ans=-1
  for i in range(len(list)):
    if abs(X-list[i])<sa:
      sa=X-list[i]
      ans=list[i]
  print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
lst = list(map(int, input().split()))
dis = 10000
ans = 0
for i in range(300):
  if not i in lst:
    if abs(x-i) < dis:
      dis = abs(x-i)
      ans = i
print(ans)

Submission status: Accepted

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

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

exist = [False] * 102
for pi in p:
  exist[pi] = True
  
minabs = X
ans = 0
for i in range(102):
  if exist[i]:
    continue
  if abs(X-i) < minabs:
    ans = i
    minabs = abs(X-i)
    
print(ans)

Submission status: Accepted

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

for i in range(N):
    p[i] = int(p[i])
    
if N == 0:
    print(X)
else:    
    for i in range(2*N):
        if not (X-i) in p:
            print(X-i)
            break
        elif not (X+i) in p:
            print(X+i)
            break
        else:
          continue

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
li = [i for i in map(int, input().split())]
k = 0
ans = 1000
while X-k >= 0 or X + k <= N:
    if X - k not in li:
        ans = X - k
        break
    if X+k not in li:
        ans = X+k
        break
    k += 1
print(ans)