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
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    X,N=mis()
    p = lmis()
    score = INF
    ans = None
    for a in range(-1000, 1000):
        if a not in p:
            if abs(X-a) < score:
                ans = a
                score = abs(X-a)
    print(ans)

main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

X,N = IL()
P = IL()

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

NOKORI = [i for i in range(200)]

for p in P:
  NOKORI.remove(p)

BEST = INF
ans = 0
for p in NOKORI:
  if abs(p-X)<BEST:
    BEST = abs(p-X)
    ans = p
print(ans)

Submission status: Accepted

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

    for i in range(53):
        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=set(list(map(int,input().split())))
val=10**20
ans=-1
for i in range(-200,202):
    if i not in p:
        if val>abs(X-i):
            val=abs(X-i)
            ans=i

print(ans)

Submission status: Accepted

Solution code:
[x,n] = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
ls = []
for i in range(-101,202):
    if i not in p:
        ls.append(i)
diff = 1000
ans = -400
for i in ls:
    if abs(x-i) < diff:
        diff = abs(x-i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys

x, n, *ppp = map(int, sys.stdin.buffer.read().split())
ppp = set(ppp)

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

s = min(ppp)
t = max(ppp)

ans = s - 1
y = abs(x - ans)
for z in range(s, t + 2):
    if z in ppp:
        continue
    d = abs(x - z)
    if d < y:
        ans = z
        y = d

print(ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N>0:
	p=list(map(int,input().split()))
	p=set(p)
else:
    p=set()
for i in range(1000):
    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, *p = map(int, open(0).read().split())
ex = [0] * 102
for i in p: ex[i] = 1
ans = 0
for i in range(102):
    if ex[i]==0 and abs(x-i)<abs(x-ans):
        ans = i
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
P = set(map(int, input().split()))
kouho = x
for i in range(100):
    kouho1 = kouho - i
    kouho2 = kouho + i
    if kouho1 not in P:
        print(kouho1)
        exit()
    elif kouho2 not in P:
        print(kouho2)
        exit()
print("error")

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

for i in range(1000):
    x1 = x - i
    x2 = x + i
    if x1 not in p:
        print(x1)
        sys.exit()
    if x2 not in p:
        print(x2)
        sys.exit()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = set(map(int,input().split()))
i = 0
while True:
    if not x-i in p:
        print(x-i)
        exit()
    if not x+i 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()))
p.sort()
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:
def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    p = [int(i) for i in input().split()]
    for d in range(110):
        if x - d not in p:
            print(x - d)
            break
        if x + d not in p:
            print(x + d)
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
a=[999]*102
for i in range(102):
    if i not in p:
        a[i]=abs(x-i)
print(a.index(min(a)))

Submission status: Accepted

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

res, diff = 0, float("inf")
for i in range(0, 110):
    if i in P:
        continue
    if diff > abs(X - i):
        res = i
        diff = abs(X - i)

print(res)

Submission status: Accepted

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

A = list(set([i for i in range(200)]) - set(A))
A.sort()
# print(A)

B = [[abs(i-x), i] for i in A]
B.sort(key=lambda x:x[1])
B.sort()
print(B[0][1])

Submission status: Accepted

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

P = set(P)

A = []
for i in range(102):
    if i not in P:
        A.append((abs(x-i), i))

A.sort()
print(A[0][1])

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
p = set(p)
res = 0
for i in range(0, 120):
    if not i in p and abs(x - i) < abs(x - res):
        res = i

print(res)

Submission status: Accepted

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


def solve(X: int, N: int, p: "List[int]"):
    forbidden = set(p)
    for i in range(1000):
        if X - i not in forbidden:
            print(X-i)
            exit()
        if X + i not in forbidden:
            print(X+i)
            exit()
    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())
pl = list(map(int,input().split()))

for i in range(100):
    if -i + x not in pl:
        print(x-i)
        exit()
    if i + x not in pl:
        print(i+x)
        exit()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
    print(X)
    exit()
p=set([int(i) for i in input().split()])
for a in range(110):
    if not((X-a) in p):
        print(X-a)
        exit()
    if not((X+a) in p):
        print(X+a)
        exit()

Submission status: Accepted

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

out1 = 1000
out2 = 1000
for i in range(-200,200):
    if i not in P:
        if abs(X-i)<out1:
            out1=abs(X-i)
            out2=i
print(out2)

Submission status: Accepted

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

if not x in p:
    print(x)
else:
    for i in range(19999):
        if not x-i in p:
            res = x-i
            break
        elif not x+i in p:
            res = x+i
            break
    print(res)

Submission status: Accepted

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

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

p, m = X, X
while True:
    m -= 1
    if m not in P:
        print(m)
        break
    p += 1
    if p not in P:
        print(p)
        break

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

x, n = na()
p = na()
sp = set(p)

mn = 99999999
best = 99999999
for i in range(-100, 300):
    if i not in sp and abs(i-x) < mn:
        mn = abs(i-x)
        best = i
print(best)

Submission status: Accepted

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

if x not in nums:
    print(x)
    exit()
for i in range(1, 200):
    if x-i not in nums:
        print(x-i)
        exit()
    if x+i not in nums:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 10**12
    a = -1
    for i in range(0,102):
        if i not in p and abs(X-i) < ans:
            ans = abs(X-i)
            a = i
    print(a)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

sa = 10000
ans = 101
for i in range(0,102):
    if not (i in p) and abs(i - x) < sa:
        sa = abs(i-x)
        ans = i
        
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n!=0:
  s=set(list(map(int,input().split())))
else:
  s=[]
diff=10**18
ans=10**18
for i in range(-10000,10000):
  if i in s:
    continue
  else:
    if abs(x-i)<diff:
      ans=i
      diff=abs(x-i)
print(ans)

Submission status: Accepted

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

q = [(abs(X-i),i) for i in range(-110,210) if not i in P]
q.sort()

print(q[0][1])

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    x,n = LI()
    p = LI()
    f = [1]*(200)
    for i in p:
        f[i] = 0
    ans = x
    m = 0
    for i in range(200):
        if f[i]:
            d = abs(i-x)
            if d < ans:
                ans = d
                m = i
    print(m)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

for i in range(1, 200):
   if x - i not in p:
      print(x - i)
      exit()
   elif x + i not in p:
      print(x + i)
      exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
ans1 = 0
for i in range(x, -10, -1):
    if i not in p:
        ans1 = i
        break
ans2 = 0
for i in range(x, 110):
    if i not in p:
        ans2 = i
        break
if x - ans1 <= ans2 - x:
    print(ans1)
else:
    print(ans2)

Submission status: Accepted

Solution code:
X,N = [int(hoge) for hoge in input().split()]
P = [int(hoge) - X for hoge in input().split()]
for d in range(101):
    if (d in P) and (-d in P):
        continue
    elif -d in P:
        print(X + d)
        exit()
    else:
        print(X - d)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=set([int(j)for j in input().split()])
for i in range(1000):
    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=map(int,input().split())
p=list(map(int,input().split()))
for i in range(1000):
  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 math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    x,n = map(int,ipt().split())
    p = list(map(int,ipt().split()))
    for i in range(100):
        if not x-i in p:
            print(x-i)
            exit()
        if not x+i in p:
            print(x+i)
            exit()


    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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


for i in range(200):
    if X - i not in ps:
        print(X-i)
        exit()
    elif X + i not in ps:
        print(X+i)
        exit()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

x, n = MAP()
p = set(LIST())
ans = -100
for i in range(-100, 100):
    a = x + i
    if a in p:
        continue
    if abs(x - a) < abs(x - ans):
        ans = a
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

X,N=map(int,input().split())
p=set(list(map(int,input().split())))
ans=INF
for x in range(-100,1000):
    if not x in p and abs(X-x)<abs(ans-X):
        ans=x
print(ans)

Submission status: Accepted

Solution code:
X,N = [int(_n) for _n in input().split()]
P = [int(_n) for _n in input().split()]
res = 0
for i in range(102):
    if i in P:
        continue
    if abs(X - i) < abs(X - res):
        res = i
print(res)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
s = set(p)
from collections import defaultdict
d = defaultdict(list)
for i in range(-100, 210):
    if i not in s:
        j = abs(i-x)
        d[j].append(i)
k = min(d.keys())
ans = min(d[k])
print(ans)

Submission status: Accepted

Solution code:
X,N,*P=map(int, open(0).read().split())
S=set(P)
print(min((abs(i-X), i)for i in range(200) if i not in S)[1])

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = set(list(map(int,input().split())))
if X not in P:
    print(X)
    exit()
i = 1
while 1:
    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:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(X: int, N: int, p: "List[int]"):
    for i in range(1000):
        if not X - i in p:
            ret = X - i
            break
        if not X + i in p: 
            ret = X + i
            break
    print(ret)
    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()

Submission status: Accepted

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

ans = -1
for i in range(102):
    if i in P:
        continue
    if abs(ans-X) > abs(i-X):
        ans = i
print(ans)

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    p = set(map(int, input().split()))
    diff = float("inf")
    answer = 0
    for i in range(102):
        if i not in p:
            if abs(i - x) < diff:
                diff = abs(i - x)
                answer = i
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353



X, N = list(map(int, sys.stdin.buffer.readline().split()))
P = list(map(int, sys.stdin.buffer.readline().split()))


ans = -INF
m = INF
for i in reversed(range(-1000,1000)):
    if i not in P:
        if abs(X - i) <= m:
            m = abs(X-i)
            ans=i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3

LI = lambda: list(map(int, input().split()))

# input
X, N = LI()
P = LI()


def main():
    s = set(P)
    for i in range(1000):
        if X - i not in s:
            print(X - i)
            return
        if X + i not in s:
            print(X + i)
            return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    val = 1000
    ans = -1
    for x in range(0, 102):
        if x in P:
            continue
        if abs(X - x) < val:
            ans = x
            val = abs(X - x)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X, N = list(map(int, input().split()))
p = list(map(int,input().split()))
ma = 10 ** 9 + 7
for i in range(-200, 200):
    if i not in p:
        dis = abs(i - X)
        if dis < ma:
            ans = i
            ma = dis
print(ans)

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    X,N=MI()
    p=LI()
    ans=0
    d=1000
    for i in range(-100,105):
        if not(i in p):
            if abs(i-X)<d:
                ans=i
                d=abs(i-X)
    print(ans)
    

main()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n > 0:
    a = list(map(int,input().split()))
else:
    a = []
fl = [False] * 1000
for i in a:
    fl[i] = True

res = -1
mn = 10 ** 100
for i in range(-10000, 10000):
    if 0 <= i < 1000 and fl[i]:
        continue
    xx = abs(x - i)
    if xx < mn:
        mn = xx
        res = i
print(res)

Submission status: Accepted

Solution code:

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

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

import sys
for i in range(200):

    if X-i not in p:
        print (X-i)
        sys.exit()
    elif X+i not in p:
        print (X+i)
        sys.exit()

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

X, N = na()
p = na()
kouho = []
for i in range(1, 101):
    if i in p:
        continue
    kouho.append((abs(X - i), i))
print(min(kouho)[1])

Submission status: Runtime Error

Solution code:
import bisect

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

A = {i for i in range(1,101)}

S = list(A - P)

T = bisect.bisect_left(S, X)

if T == 0:
    print(S[0])
elif X - S[T-1] > S[T] - X:
    print(S[T])
else:
    print(S[T-1])

Submission status: Runtime Error

Solution code:
N = map(int, input().split())
p = list(map(int, input().split()))
for d in range(X + 1):
  for s in [-1, +1]:
    a = X + s * d
    if p.count(a) == 0:
      print(a)
      exit(0)

Submission status: Runtime Error

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

min =10000
temp = 0

for i in range(-1000, 1000):
  temp = abs(X - i)
  
  if temp < min and i not in p:
    min = temp
    
print(min)

Submission status: Runtime Error

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

min =10000
temp = 0

for i in range(-1000, 1000):
  temp = abs(X - i)
  
  if temp < min and i not in p:
    min = temp
    
print(min)

Submission status: Runtime Error

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

min =10000
temp = 0

for i in range(-1000, 1000):
  temp = abs(X - i)
  
  if temp < min and i not in p:
    min = temp
    
print(min)

Submission status: Runtime Error

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

if n == 0:
    print(m)
    exit()
else:
    pp = list(range(1, max(p)+1))
    ppp = list(filter(lambda x: x not in p, pp))
    pppp = list(map(lambda x: abs(x-m), ppp))
    print(ppp[pppp.index(min(pppp))])

Submission status: Runtime Error

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

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

    P_exist = [False] * (101)
    for p in P:
        P_exist[p] = True

    if not P_exist[X]:
        print(X)
        return
    
    for i in range(1, 200):
        if (not P_exist[X-i]) and (not P_exist[X+i]):
            print(X-i)
            return
        if not P_exist[X-i]:
            print(X-i)
            return
        if not P_exist[X+i]:
            print(X+i)
            return

main()

Submission status: Runtime Error

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

l = [i for i in range(1,101)]

for j in p:
    l.remove(j)

m = []

for k in l:
    m.append(abs(k-x))

print(l[m.index(min(m))])

Submission status: Runtime Error

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
l = [i for i in range(1,101)]

for j in p:
    l.remove(j)

m = []

for k in l:
    m.append(abs(k-x))

print(l[m.index(min(m))])

Submission status: Runtime Error

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

max_num = max(p)
lst = []
for i in range(max_num+2):
  if i not in p:
    lst.append(i)
tmp = float("inf")
for j in lst:
  if tmp > abs(X-j):
    tmp = abs(X-j)
    ans = j
print(ans)

Submission status: Runtime Error

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

table = [0] * 102
ans = X
dist = 102

for p in range(P):
  table[p] = 1

for i in range(102):
  if table[i] == 1:
    continue
  if abs(i - X) < dist:
    ans = i
    dist = abs(i - X)
  elif abs(i - X) == dist:
    ans = min(i, ans)

Submission status: Runtime Error

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

table = [0] * 102
ans = X
dist = 102

for p in range(P):
  table[p] = 1

for i in range(102):
  if abs(i - X) < dist:
    ans = i
    dist = abs(i - X)
  elif abs(i - X) == dist:
    ans = min(i, ans)

print(str(ans))