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:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  a=list(map(int,input().split()))
  l=[x+i for i in range(101)]
  s=[x-i for i in range(101)]
  m=min(len(l),min(s))
  mada=1
  k=0
  while mada:
    if s[k] not in a:
      ans=s[k]
      mada=0
      break
    elif l[k] not in a:
      ans=l[k]
      mada=0
      break
    else:
      k+=1
  print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N != 0:
  p = list(map(int, input().split()))
  num = float("inf")
  for i in range(1, 101):
    if abs(i-X) < abs(num-X) and not i in p:
      num = i
  if abs(0-X) <= abs(num-X) and abs(0-X) <= abs(101-X):
    print(0)
  elif abs(101-X) < abs(num-X):
    print(101)

  else:	
    print(num)
else:
  print(X)

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    x, n = i_map()
    if n == 0:
        print(x)
        exit()
    num_list = i_list()

    abs_num = INF
    ans_list = []

    for i in range(0,102):
        if i in num_list:
            continue
        if abs_num > abs(i-x):
            ans_list = []
            abs_num = abs(i-x)
            ans_list.append(i)
        elif abs_num == abs(i-x):
            ans_list.append(i)

    ans_list.sort()

    print(ans_list[0])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if (XN[1] == 0):
    print(XN[0])
    exit()

P = list(map(int, input().split()))
bucket = [0] * 100
for i in range(XN[1]):
    bucket[P[i] - 1] = 1

#正方向
pcounter = 0
for i in range(XN[0], 101):
    if (i == 101):
        break
    if (bucket[i - 1] == 0):
        break
    pcounter += 1

#負方向
mcounter = 0
for i in range(XN[0], -1, -1):
    if (i == 0):
        break
    if (bucket[i - 1] == 0):
        break
    mcounter += 1


if (pcounter >= mcounter):
    print(XN[0] - mcounter)
else:
    print(XN[0] + pcounter)

Submission status: Accepted

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

length = 102
ans = 102
for i in range(-100,201):
    if not (i in P):
        if abs(x-i)<length:
            length = abs(x-i)
            ans = i

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

l = input().rstrip().split(" ")
X = int(l[0])
N = int(l[1])

if N == 0:
    print(X)
else:
    P = input().rstrip().split(" ")
    P2 = []
    for i in range(N):
        P2.append(int(P[i]))
    #print(P2)
    
    cnt = 103
    ans = 0
    for i in range (-2, 103):
        a = 0
        for j in range(N):
            if i == P2[j]:
                a = 1
        if i > X:
            b = i - X
        else:
            b = X -i
        if a == 0 and b < cnt:
            cnt = b
            ans = i
    print(ans)

Submission status: Accepted

Solution code:
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


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


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


x, n = invr()
if n == 0:
    print(x)
else:
    mark = [0]*101
    a = inlist()

    lx = rx = res = x
    while True:
        if lx not in a:
            res = lx
            break
        if rx not in a:
            res = rx
            break
        lx -= 1
        rx += 1
    print(res)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
l = list(map(int, input().split()))
min_abs = 51
ans = 0
for i in range(102):
    if i in l:
        continue
    if abs(i - X) < min_abs:
        min_abs = abs(i - X)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys

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

for i in range(100):
    if (x - i in listdame):
        pass
    else:
        print(x - i)
        sys.exit()

    if (x + i in listdame):
        pass
    else:
        print(x + i)
        sys.exit()

Submission status: Accepted

Solution code:
X, N = 6, 5
PRR = [4, 7, 10, 6, 5]

# X, N = 10, 5
# PRR = [4, 7, 10, 6, 5]

# X,N = 100, 0
# PRR = []

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


def calculate(x, n, prr):
    up = x
    while up in prr:
        up = up + 1

    down = x - 1

    while down in prr:
        down = down - 1

    if abs(x - down) == abs(x - up):
        return min(down, up)

    if abs(x - down) < abs(x - up):
        return down
    else:
        return up


result = calculate(X, N, PRR)

print(result)

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(100):
    left = X - i
    right = X + i
    
    if left not in P and right not in P:
        print(min(left, right))
        exit()
    elif left not in P and right in P:
        print(left)
        exit()
    elif left in P and right not in P:
        print(right)
        exit()
    else:
        continue

Submission status: Accepted

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

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

    P = sorted(P)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

i = 0
while True:
  if not (x - i) in ps:
    print(x - i)
    break
  if not (x + i) in ps:
    print(x + i)
    break
  i += 1

Submission status: Accepted

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

all_list = [i for i in range(1,101)]
p = reversed(sorted(p))

for i in p:
  all_list.pop(i-1)
  
all_list.insert(0,0)
all_list.insert(0,-1)
all_list.append(101)

if x in all_list:
  ans = x
else:
  abs_ = 1000
  for i in all_list:
    if abs(x - i) < abs_:
      abs_ = abs(x - i)
      ans = i

print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
nP = list(map(lambda x: abs(x - X), P))
nP.sort()

if N == 0:
    print(X)
elif nP[0] != 0:
    print(X)
else:
    cnt = 1
    while True:
        if nP.count(cnt) != 2:
            if not X - cnt in P:
                print(X - cnt)
            else:
                print(X + cnt)
            break
        cnt += 1

Submission status: Accepted

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

mindif = 1000
candidate = 0
for i in range(102):
    if abs(i - X) < mindif and i not in p:
        mindif = abs(i - X)
        candidate = i

print(candidate)

Submission status: Accepted

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

A = [1] * 102
for p in P:
    A[p] = 0

tmp = float("inf")
for i in range(102):
    if A[i]:
        if abs(x - i) < tmp:
            tmp = abs(x - i)
            ans = i

print(ans)

Submission status: Accepted

Solution code:
import sys
X,N = map(int,input().split())
p=input().split()
for i in range(100):
  if not(str(X-i) in p):
    print(X-i)
    sys.exit()
  if not(str(X+i) in p):
    print(X+i)
    sys.exit()

Submission status: Accepted

Solution code:
x, n = tuple(map(int, input().split()))
p = list(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()
    if (x + i) not in p:
        print(x + i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(110):
    S = X - i
    B = X + i
    if S not in PS:
        print(S)
        exit()
    if B not in PS:
        print(B)
        exit()

Submission status: Accepted

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

def bin(arr, val):
    l,r = 0, len(arr)-1
    while l <= r:
        mid = (l + r)//2
        if arr[mid] == val: return 1
        elif arr[mid] <= val: l = mid + 1
        elif arr[mid] >= val: r = mid - 1
    return 0

x,n = imap()
p = sorted(iarr())

for i in range(n+1):
    a,b = x-i,x+i
    if not bin(p,a): ans = a; break
    if not bin(p,b): ans = b; break

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

Submission status: Accepted

Solution code:
import bisect
import sys

x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
p.sort()
tmp_ans = 100000
index = bisect.bisect_left(p, x)
if len(p) == 0 or p[index] != x:
  print(x)
else:
  i = index
  cnt = 0
  while True:
    cnt += 1
    if i - cnt < 0:
      tmp_ans = x-cnt
      break
    if p[i-cnt] != x-cnt:
      tmp_ans = x-cnt
      break
  i = index
  cnt = 0
  while True:
    cnt += 1
    if i + cnt >= len(p):
      if abs(tmp_ans-x) > abs(cnt):
        tmp_ans = x+cnt
      break
    if p[i+cnt] != x+cnt:
      if abs(tmp_ans-x) > abs(cnt):
        tmp_ans = x+cnt
      break

  print(tmp_ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
p=[]
for j in range(X*100):
    if j in P:
        a=0
    else:
        p.append(j)
result=1000
answer=1000
for i in range(X*100-N):
    if abs(X-p[i])<result:
        answer=p[i]
        result=abs(X-p[i])
    elif abs(X-p[i])==result and p[i]<=answer:
        answer=p[i]
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

if n != 0:
  p = list(map(int, input().split()))
  lists = []
  for i in range(0, 102):
    if i in p:
      continue
    lists.append(i)

  ans = lists[0]
  mins = abs(lists[0] - x)
  for i in range(1, len(lists)):
    dist = abs(lists[i]-x)
    if mins > dist:
      ans = lists[i]
      mins = dist
      
  print(ans)
else:
  print(x)

Submission status: Accepted

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

if N == 0:
  print(X)
elif N == 100:
  if X > 50:  
    print(101)
  else:
    print(0)
else:
  List = list(map(int,input().split()))
  List.sort()

  c = 10 ** 10
  ans = 1000

  for i in range(-100,200):
    if not i in List:
      if abs(i - X) < c:
        c = abs(i-X)
        ans = i
      
  print(int(ans))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))


            cur = 0
            if x not in p:
                return x
            
            while True:
                if x-cur not in p:
                    return x-cur
                if x+cur not in p:
                    return x+cur

                cur+=1
    print(main())


resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

def ip():
    return sys.stdin.readline()


def ipl():
    return sys.stdin.readline().split()


def solve():
    x, n = map(int, ipl())
    li = list(map(int, ipl()))
    freq = defaultdict(int)
    for i in li:
        freq[i] = 1
    i, j = x, x
    while freq[i]:
        i -= 1
    while freq[j]:
        j += 1
    if abs(i - x) < abs(j - x):
        print(i)
    elif abs(i - x) == abs(j - x):
        print(min(i, j))
    else:
        print(j)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
flag = True
dif = 0
while flag == True:
    flag_m = False
    flag_p = False

    x_m = X - dif
    x_p = X + dif

    for i in range(N):
        if x_m == p[i]:
            flag_m = True
        if x_p == p[i]:
            flag_p = True

    if flag_m == False:
        flag = False
        print(x_m)
    elif flag_p == False:
        flag = False
        print(x_p)

    dif += 1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x, n, *p = map(int, open(0).read().split())
p.sort()
d = 0
while 1:
  if not x-d in p:
    print(x-d)
    break
  elif not x+d in p:
    print(x+d)
    break
  d += 1

Submission status: Accepted

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

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

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

Submission status: Accepted

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

exist = [0] * 102
for pp in p:
    exist[pp] = 1

res = 0
diff = abs(res - x)
for i in range(1, 102):
    if not exist[i] and (d := abs(i - x)) < diff:
        res = i
        diff = d
print(res)

Submission status: Accepted

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

for n in range(100+1):
    if X-n not in P:
        ans = X-n
        break
    elif X+n not in P:
        ans = X+n
        break
print(ans)

Submission status: Accepted

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

y = list(map(int, input().split()))
i = 1
if x not in y:
    print(x)
else:
    while(True):
        if x-i not in y:
            print(x-i)
            break
        elif x+i not in y:
            print(x+i)
            break
        i += 1

Submission status: Accepted

Solution code:
import sys


def solve(x, n):
    if n == 0:
        return x
    ps = set(map(int, input().split()))
    if x not in ps:
        return x
    # 解の候補
    qs = list(set(range(102)) - ps)
    ans = [1000, 1000]  # [距離,解]
    for q in qs:
        if abs(q - x) < ans[0]:
            ans[0] = abs(q - x)
            ans[1] = q
        elif abs(q - x) == ans[0] and q < ans[1]:
            ans[1] = q
    return ans[1]


def main():
    input = sys.stdin.buffer.readline
    x, n = map(int, input().split())
    print(solve(x, n))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if N == 0:
    print(X)
else:
    m = 1000
    n = 1000

    for i in range(102):
        c = i
        d = abs(X - c)
        if c not in p:
            if d < m:
                m = d
                n = c
            elif d == m and c < n:
                n = c
    print(n)

Submission status: Accepted

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

ans = 0
j = 0 
for i in range(-1, 102):
    if j != n and p[j] == i:
        j += 1
        continue
    if abs(i - x) < abs(ans - x):
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import math
x, n = map(int, input().split(' '))
if n == 0:
    input()
    p = []
else:
    p = map(int, input().split(' '))
    p = list(p)

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

# p.sort()
min_dist = 103
min = 0
for i in range(102):
    if i not in p:
        if min_dist > abs(x-i):
            min_dist = abs(x-i)
            min = i

print(min)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    x, n = map(int, readline().split())
    p = list(map(int, readline().split()))
    check = float('inf')
    ans = 0
    for i in range(1000):
        if i not in p:
            if check > abs(x - i):
                ans = i
                check = abs(x - i)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

        if not x+num in p:
            print(x+num)
            break
        num += 1

except:
    print(x)

Submission status: Accepted

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

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

# Xを中心に+1 , -1をそれぞれ実行し、その整数が含まれているかチェック
left = -1
right = 1

lL = []
rL = []
while True:
    if (len(lL) != 0 or len(rL) != 0):
        break
    lX = X + left
    rX = X + right

    if (lX not in P):
        lL.append(lX)
    if (rX not in P):
        rL.append(rX)

    left -= 1
    right += 1

if (len(lL) != 0 and len(rL) == 0):
    print(lL[0])
elif (len(lL) == 0 and len(rL) != 0):
    print(rL[0])
else:
    ml = lL[0]
    mr = rL[0]
    print(min(ml, mr))

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    X, N = [int(item) for item in input().split()]
    if N > 0:
        a_list = [int(item) for item in input().split()]
        

        a = X
        b = X
        is_not_fond = True
        res = X
        while is_not_fond:
            if a in a_list:
                a += 1
            else:
                res = a
                is_not_fond = False
            if b in a_list:
                b -= 1
            else:
                res = b
                is_not_fond = False

        print(res)
    else:
        print(X)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    X, N = read_values()
    if N == 0:
        input()
        print(X)
    else:
        P = set(read_list())
        for d in range(10000):
            if X - d not in P:
                print(X - d)
                return
            elif X + d not in P:
                print(X + d)
                return
        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
X,N=map(int,input().split())
P=[]
if N!=0:
    P=list(map(int,input().split()))
K=[]
for i in range(102):
    if not(i in P):
        K.append(i)

ans=[]

for i in range(len(K)):
    ans.append([abs(X-K[i]),K[i]])

ans.sort()

A=[]

for i in range(len(ans)):
    if ans[i][0]==ans[0][0]:
        A.append(ans[i][1])

print(min(A))

Submission status: Accepted

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

for i in range(0,102):
    if not i in p:
        p2.append(i)

p3 = p2[::-1]
Ans = X
sa = 1000
for j in range(len(p3)):
    if abs(p3[j]-X) <= sa:
        sa = abs(p3[j]-X)
        Ans = p3[j]

print(Ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    a=list(map(int,input().split()))
    for i in range(n//2+1):
        if not(x-i in a):
            print(x-i)
            exit()
        if not(x+i in a):
            print(x+i)
            exit()
    print(x-1-n//2)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
p = [i-x for i in p]
p.sort()
ans = -n
for i in range(n):
  if -i not in p:
    ans = -i
    break
  elif i not in p:
    ans = i
    break
print(x+ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
ans = 0
if n == 0: print(x)
else:
    p_i = list(map(int, input().split()))
    for val in range(101):
        minv = x - val
        maxv = x + val
        if minv not in p_i:
            print(minv)
            break
        elif maxv not in p_i:
            print(maxv)
            break
        else: 
            ans += 1

Submission status: Accepted

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

    c=0
    for i in range(100):
        if X-c not in A:
            print(X-c)
            break
        if X+c not in A:
            print(X+c)
            break
        c += 1
else:
    print(X)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
p=sorted(P)
a=True
if N==0:
    print(X)
    a=False
if (X in p)==False and a==True:
    print(X)
    a=False
if a==True:
    for i in range(1,100):
        if (X-i in p)==False and (X+i in p)==False:
            print(X-i)
            a=False
            break
        elif (X-i in p)==True and (X+i in p)==False:
            print(X+i)
            a=False
            break
        elif (X-i in p)==False and (X+i in p)==True:
            print(X-i)
            a=False
            break

Submission status: Accepted

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

if N > 0:
    p = set(map(int, input().split()))
else:
    print(X)
    exit()

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

i = 0

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

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

Submission status: Accepted

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

P.sort()

if X not in P:
    ans = X
else:
    for i in range(101):
        a = X - i
        b = X + i
        if a not in P:
            ans = a
            break
        elif b not in P:
            ans = b
            break
print(ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque, Counter
from sys import exit
import math
import copy
from bisect import bisect_right

import sys
sys.setrecursionlimit(1000000)
import heapq
INF = 10**10

def dijkstra(graph, start, n):
    h = []
    heapq.heappush(h, (0, start))
    costs = [INF for _ in range(n)]
    while h:
     cost, cur = heapq.heappop(h)
     if costs[cur] != INF:
         continue
     costs[cur] = cost
     for edge in graph[cur]:
         ecost, tgt = edge
         if costs[tgt] == INF:
             heapq.heappush(h, (cost + ecost, tgt))

    return costs

def main():
    x, n = getList()
    nums = getList()
    ans = -1
    tmp = 100000
    for i in range(-200, 201):
        if i not in nums and abs(i - x) < tmp:
            ans = i
            tmp = abs(i - x)

    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

up = x
down = x
ans = 0

while ans == 0:
    if p.count(down) == 0:
        ans = down
        break
    elif p.count(up) == 0:
        ans = up
        break
    else:
        up += 1
        down -= 1

print(ans)

Submission status: Accepted

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

    if x not in ppp:
        print(x)
    else:
        for i in range(120):
            if x - i not in ppp:
                print(x-i)
                break
            if x + i not in ppp:
                print(x+i)
                break
else:
    print(x)

Submission status: Accepted

Solution code:
# coding:utf-8

X, N = list(map(lambda x:int(x), input().split()))
p = list(map(lambda x:int(x), input().split()))

i = 0
while(1):
  if(X-i not in p):
    print(X-i)
    break
  if(X+i not in p):
    print(X+i)
    break
  # 範囲拡大
  i+=1

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if(N==0):
    print(X)
else:
    P = [int(i) for i in input().split()]
    A = []
    for i in range(-100,201):
        if not i in P:
            A.append([abs(X-i),i])

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=sorted(list(map(int,input().split())))
c=sorted([abs(i-x) for i in p])
for i in range(200):
  if c.count(i)==0:
    print(x-i)
    exit()
  elif c.count(i)==1 and i!=0:
    if p.count(x-i)==0:
      print(x-i)
    else:
      print(x+i)
    exit()
  else:
    pass

Submission status: Accepted

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

import numpy as np

all_set = [i for i in range(-1,102)]

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

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

temp_result = list(set(all_set) - set(p))
print(getNearestValue(temp_result, X))

Submission status: Accepted

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

if n > 0:
    p = [int(i) for i in input().split()]
    ps = set(p)
    ans = 0

    c = 0

    
    while(True):
        if (x - c) not in ps:
            ans = x-c
            break
        elif (x + c) not in ps:
            ans = x+c
            break
        else:
            c += 1

    print(ans)
















else:
    print(x)

Submission status: Accepted

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

if n < 1:
  print(x)
  exit()

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

data.sort()

result = [(abs(x - i), i) for i in range(data[0]-1, data[-1]+2) if i not in data]
r = sorted(result, key=lambda x: x[0])

print(r[0][1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
x,n = list(map(int,input().split()))
if n != 0:
  p = list(map(int,input().split()))
  
if n==0:
  print(x)
  
elif x not in p:
  print(x)

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