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 numpy as np
#import functools
#import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm
#import collections as C #most_common

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

for i in range(100):
    if X-i not in P:
        print(X-i)
        exit()
    elif X+i not in P:
        print(X+i)
        exit()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X, N, *P = map(int, read().split())

nums = list(range(-10, 110))

for p in P:
    nums.remove(p)

answer = min(nums, key=lambda x: (abs(x - X), x))
print(answer)

Submission status: Accepted

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

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

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

a, b = -1, 101
p.sort()
chk = [0] * 101

for x in p:
    chk[x] = 1

for x in range(k, -1, -1):
    if chk[x] == 0:
        a = x
        break

for x in range(k, 101):
    if chk[x] == 0:
        b = x
        break

if k - a <= b - k:
    print(a)
else:
    print(b)

Submission status: Accepted

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

k=0
while True:
    if X-k not in P:
        print(X-k)
        break
    elif X+k not in P:
        print(X+k)
        break
    k+=1

Submission status: Accepted

Solution code:
def main():
    x, n= map(int,input().split())
    inlis = list(map(int, input().split()))
    inlis.sort()

    if x in inlis:
        for i in range(1, 100):
            if x - i in inlis:
                if x + i in inlis:
                    pass
                else:
                    print(x+i)
                    exit()
            else:
                print(x-i)
                exit()
    else:
        print(x)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
if y==0:
  print(x)
else:
  l=set(list(map(int,input().split())))
  if x in l:
    i=1
    while True:
      if not x-i in l:
        print(x-i)
        quit()
      elif not x+i in l:
        print(x+i)
        quit()
      i+=1
  else:
    print(x)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


x, n = inpl()
p = set(inpl())
dif = 0

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

Submission status: Accepted

Solution code:
X,N = [int(v) for v in input().split()]
P = [int(v) for v in input().split()]
p_f = [False for _ in range(201)]

for p in P:
    p_f[p] = True

ans = 0
for i in range(100):
    if not p_f[X-i]:
        ans = X-i
        break
    elif not p_f[X+i]:
        ans = X+i
        break
print(ans)

Submission status: Accepted

Solution code:
import bisect
X, N = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
s = set([i for i in range(102)])

for x in p:
    s.remove(x)

s = sorted(list(s))

id = bisect.bisect_left(s, X)
a = s[id-1]
b = s[id]
ans = a
if abs(a-X) > abs(b-X):
    print(b)
else:
    print(a)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

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

ans = -1
nums = [True]*105
for p in P:
    nums[p] = False

MIN = 10**9
for i in range(105):
    if nums[i]:
        if MIN>abs(i-X):
            MIN = abs(i-X)
            ans = i

print(ans)

Submission status: Accepted

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

ans = 101
minD = 105
for i in range(102):
    if i in setP: continue
    diff = abs(i-X)
    if diff < minD:
        ans = i
        minD = diff

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
        return
    p = set(map(int,input().split()))
    p_var = set(range(-100,102))-p
    print(min(p_var,key= lambda x: abs(X-x) ) )
resolve()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
a=[0]*102
for i in range(len(p)):
    a[p[i]]=1
sa=500
for j in range(len(a)):
    if a[j]==0 and sa>abs(x-j):
        m=j
        sa=abs(x-j)
print(m)

Submission status: Accepted

Solution code:
def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    p = list(map(int, input().split()))
    for i in range(101):
        if not x - i in p:
            print(x - i)
            return
        if not x + i in p:
            print(x + i)
            return


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
x,n = list(map(int,input().split()))
if n==0:
	print(x)
	exit()
arr = list(map(int,input().split()))
d = {}
for i in arr:
	d[i] = 1
p = 0
while(True):
	if (x-p not in d):
		print(x-p)
		break
	if x+p not in d:
		print(x+p)
		break
	p+=1

Submission status: Accepted

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

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

if x not in a:
  print(x)
else:
  sa = 1
  while True:
    if x-sa not in a:
      print(x-sa)
      break
    if x+sa not in a:
      print(x+sa)
      break
    sa += 1

Submission status: Accepted

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

st = set(ps)

for i in range(100):
    if x - i not in st:
        print(x - i)
        exit(0)
    elif x + i not in st:
        print(x + i)
        exit(0)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
x,n=map(int,input().split())
p=list(map(int,input().split()))
ans=[10**9]*102
for i in range(102):
    if not i in p:
        ans[i]=abs(i-x)
m=0
ms=10**9
for i in range(102):
    if ans[i]<ms:
        ms=ans[i]
        m=i
print(m)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

x, n = rm()
if n >= 1:
  li = rl()
else:
  print(x)
  exit()
for i in range(101):
  if (x-i) not in li:
    print(x-i)
    exit()
  elif (x + i) not in li:
    print(x+i)
    exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(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 sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

x, N = MAP()
A = LIST()

S = set(A)
i = 0
if x not in S:
    print(x)
    exit()
l = r = x
while 1:
    l -= 1
    r += 1
    if l not in S:
        print(l)
        break
    if r not in S:
        print(r)
        break

Submission status: Accepted

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

min_diff = 10000000
ans = 0
for i in range(-200, 201):
    if i not in p:
        if abs(X - i) < min_diff:
            ans = i
            min_diff = abs(X - i)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

A = [i for i in range(max(P)+2) if i not in P]
X = abs(x-A[0])
ans = A[0]
for a in A[1:]:
    if abs(x-a) < X: 
        X = abs(x-a)
        ans = a
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    i = 0
    while True:
        if X - i not in p:
            ans = X - i
            break
        if X + i not in p:
            ans = X + i
            break
        i += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
mi = 1000
for i in range(102):
    if i in p:
        continue
    if abs(i-x)<mi:
        mi = abs(i-x)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    X,N = map(int,input().split())
    P = set(map(int,input().split()))
    ans = -1
    M = INF
    for i in range(X - 105,X + 105):
        if i not in P:
            if M > abs(i - X):
                ans = i
                M = abs(i - X)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans1 = X
ans2 = X

while True:
  if ans2 not in p_list:
    print(ans2)
    exit()
  if ans1 not in p_list:
    print(ans1)
    exit()

  ans1 += 1
  ans2 -= 1

Submission status: Accepted

Solution code:
#N = int(input())
#N = int(input())
#S = input()
# = input().split()
# = input().split()
# = map(int,input().split())
X,N = map(int,input().split())
if N != 0:
    p = list(map(int,input().split()))
else:
    print(X)
    exit()
# = list(map(int,input()).split())
i = 0
while True:
    if X-i not in p:
        print(X-i)
        exit()
    if X + i not in p:
        print(X+i)
        exit()
    i += 1

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
lenge = 1000
for i in range(-1,102):
    if i not in P:
        if abs(X-i) < lenge:
            lenge = 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()))
for i in range(102):
  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:
x,n=map(int,input().split())
p=sorted(list(map(int,input().split())))
i=0
while True:
    if x-i not in p:
        print(x-i)
        exit(0)
    elif x+i not in p:
        print(x+i)
        exit(0)
    i+=1

Submission status: Accepted

Solution code:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    X,N = LMIIS()
    P = LMIIS()

    d = 0
    while True:
        if P.count(X-d) == 0:
            print(X-d)
            return
        elif P.count(X+d) == 0:
            print(X+d)
            return
        d += 1
        


    
main()

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

if not x in P:
    print(x)
    sys.exit()

i=1
while True:
    if not x-i in P:
        print(x-i)
        break

    if not x+i in P:
        print(x+i)
        break

    i+=1

Submission status: Accepted

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

i_max = 101
i_min = 0

for i in range(x, 101):
    if i not in p:
        i_max = i
        break

for i in range(x, 0, -1):
    if i not in p:
        i_min = i
        break

if x - i_min <= i_max - x:
    print(i_min)
else:
    print(i_max)

Submission status: Accepted

Solution code:
import sys
x,n=map(int,input().split())
a=list(map(int,input().split()))
tmp=0
while True:
    if x-tmp not in a: print(x-tmp);sys.exit()
    elif x+tmp not in a: print(x+tmp);sys.exit()
    tmp+=1

Submission status: Accepted

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

dif = 10**18
for d in range(1000):
    tmp = X - d
    if not tmp in P:
        print(tmp)
        exit()
    tmp = X + d
    if not tmp in P:
        print(tmp)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


def solve(X: int, N: int, p: "List[int]"):
    return min(filter(lambda x: x not in p, range(-1, 102)),
               key=lambda x: (abs(X-x), x))


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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]"
    print(solve(X, N, p))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
t1=x
t2=x
while True:
  if t1 in p:
    t1=t1-1
  else:
    print(t1)
    break
  if t2 in p:
    t2=t2+1
  else:
    print(t2)
    break

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

X, N = lr()
P = set(lr())
flag = True
answer = X
while answer in P:
    if flag:
        diff = abs(X - answer)
        answer = X - diff - 1
        flag = False
    else:
        diff = abs(X - answer)
        answer = X + diff
        flag = True

print(answer)

Submission status: Accepted

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

i=0
while True:
	ans_n=X-i
	if ans_n not in p_ls:
		print(ans_n)
		break
	
	ans_p=X+i
	if ans_p not in p_ls:
		print(ans_p)
		break
	
	i+=1



# 2darray [[0] * 4 for i in range(3)]

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    x, n = ns()
    p = na()

    set_p = set(p)

    res = -1

    for i in range(101):
        l = x + i
        s = x - i
        if s not in set_p:
            res = s
            break
        if l not in set_p:
            res = l
            break


    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    X, N = Scanner.map_int()
    P = Scanner.map_int()
    if N == 0:
        print(X)
        return
    t = INF
    for i in range(-1, 102):
        if i in P:
            continue
        t = min(t, abs(i - X))
    if X - t in P:
        print(X + t)
    else:
        print(X - t)


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
d=[0]*201
P=list(map(int,input().split()))
for p in P:
    d[p]=1
a=X
for i in range(101):
    if d[X-i]==0:
        a=X-i
        break
    elif d[X+i]==0:
        a=X+i
        break
print(a)

Submission status: Accepted

Solution code:
candidates = {i for i in range(-1, 102)}
X, N = map(int, input().split())
P = set(map(int, input().split()))
diff = float('inf')
ans = -100
for x in candidates - P:
    if abs(x - X) < diff:
        diff = abs(x - X)
        ans = x
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = set(map(int, input().split()))
d = 0
while True:
    x = X-d
    if x not in P: break

    x = X+d
    if x not in P: break

    d += 1

print(x)

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    P = list(map(int, input().split()))
    m = x
    M = x
    if len(P) == 0:
        print(x)
        exit()
    if not x in P:
        print(x)
        exit()

    while True:
        m -= 1
        M += 1
        if not m in P:
            print(m)
            exit()
        if not M in P:
            print(M)
            exit()



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
l = list(map(int, input().split()))
vis = [0] * 103
for i in l: vis[i] = 1
mn = 9999
ans = -1
for i in range(103):
    if vis[i] == 0:
        if abs(x - i) < mn:
            mn = x - i
            ans = i
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    x, n = map(int, input().split())
    a = set(map(int, input().split()))
    a = sorted(set([i for i in range(102)]) - a)
    s = inf
    for i in a:
        s = min(s, abs(x - i))

    for i in a:
        if abs(x - i) == s:
            print(i)
            return
main()

Submission status: Accepted

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


if x not in p:
  print(x)
  exit()
else:
  i = 1
  while True:
    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:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

x,n=MI()
lis=LI()
for i in range(500):
    l=x-i
    u=x+i
    if not l in lis:
        print(l)
        sys.exit()
    elif not u in lis:
        print(u)
        sys.exit()

Submission status: Accepted

Solution code:
import bisect
x, n = map(int,input().split())
p = list(map(int,input().split()))
if n == 0:
	print(x)
	exit()
p.sort()
a = bisect.bisect_left(p, x)
a = p[a]
cnt = 0
while True:
	if not a-cnt in p:
		ans = a-cnt
		break
	if not a+cnt in p:
		ans = a+cnt
		break
	cnt += 1
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
arr = list(map(int, input().split()))
xSet = set(arr)

notInc = [i for i in range(-1, 102) if i not in xSet]
print(sorted(notInc, key = lambda i : abs(i - x))[0])

Submission status: Accepted

Solution code:
M,N = map(int,input().rstrip().split(" "))
if N != 0:
    A = set(map(int,input().rstrip().split(" ")))
    ans = -100
    sa = 10 ** 5
    for i in range(-1,102):
        if not i in A:
            if sa > abs(M - i):
                sa = abs(M - i)
                ans = i
    print(ans)
else:
    print(M)

Submission status: Accepted

Solution code:
def solve(x, n, p_list):
    diff_min = 101
    res = 0
    for i in range(102):
        if i not in p_list:
            if abs(x - i) < diff_min:
                diff_min = abs(x - i)
                res = i
    return res


def main():
    x, n = map(int, input().split())
    p_list = list(map(int, input().split()))
    res = solve(x, n, p_list)
    print(res)


def test():
    assert solve(6, 5, [4, 7, 10, 6, 5]) == 8
    assert solve(10, 5, [4, 7, 10, 6, 5]) == 9
    assert solve(100, 0, []) == 100


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

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

nearest = 0
distance = 100
for x in range(0, 101 + 1):
	if x not in p_set and distance > abs(x - X):
		nearest = x
		distance = abs(x - X)

print(nearest)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 0
diff = 100
for i in range(0, 102):
    if i not in p and abs(x-i) < diff:
        ans = i
        diff = abs(x-i)
print(ans)

Submission status: Accepted

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

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

for i in range(1, 200):
    if X - i not in P:
        print(X-i)
        exit(0)
    elif X + i not in P:
        print(X+i)
        exit(0)

Submission status: Accepted

Solution code:
def main():
    integar, length = [int(x) for x in input().split()]
    numbers = {int(x) for x in input().split()}
    for diff in range(101):
        aa = integar - diff
        bb = integar + diff
        if aa not in numbers:
            print(aa)
            return
        elif bb not in numbers:
            print(bb)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    x, n = map(int, input().split())
    ans = 0
    p = set(map(int, input().split()))
    for i in range(110):
        if i in p:
            continue
        else:
            if abs(i-x) < abs(ans-x):
                ans = i
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n>0:
  p=list(map(int,input().split()))
if n==0:
  p=[]
for i in range(1000):
  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())
S = list(map(int, input().split()))

ans = X
for i in range(200):
    if X-i not in S:
        print(X-i)
        break
    elif X+i not in S:
        print(X+i)
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62


def solve(X: int, N: int, p: "List[int]"):
    kouho = list((set(v + 1 for v in p) | set(v - 1 for v in p)) - set(p))
    kouho.sort()
    diff = INF
    ans = X
    for v in kouho:
        cdiff = abs(v - X)
        if diff > cdiff:
            diff = cdiff
            ans = v
    print(ans)
    return


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