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 :
  pn = [int(num) for num in input().split()]
  answers = {}
  for i in range(102):
    if not i in pn:
      answers[i] = abs(i-x)
  print(min(answers, key=answers.get))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
a=[1000]*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())

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

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

for i in range(102):
  a = X + i
  b = X - i
  if b not in p:
    print(b)
    exit(0)
  if a not in p:
    print(a)
    exit()

Submission status: Accepted

Solution code:
def solve(x, ls):
    y = 0
    m = x
    for i in range(1, 102):
        if i in ls:
            continue
        if abs(x - i) < m:
            y = i
            m = abs(x - i)
    return y


def main(istr, ostr):
    x, n = list(map(int, istr.readline().strip().split()))
    ls = list(map(int, istr.readline().strip().split()))
    result = solve(x, ls)
    print(result, file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)

Submission status: Accepted

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

p.sort()

candidates = {}
for i in range(-1, 102):

    if i in p:
        continue

    if not (abs(X-i) in candidates.keys()):
        candidates[abs(X-i)] = [i]
    else:
        candidates[abs(X-i)].append(i)

smallest = min(candidates.keys())

minNum = min(candidates[smallest])

print(minNum)

Submission status: Accepted

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

ans = -1
best = float('inf')
for n in range(102):
    if n in P:
        continue
    a = abs(X - n)
    if best > a:
        ans = n
        best = a

print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
line = list(map(int, input().split()))
notLine = [i for i in range(-100, 201) if i not in line]
left = -1
right = len(notLine)
while abs(right - left) > 1:
    middle = (right + left) // 2
    if notLine[middle] >= X:
        right = middle
    else:
        left = middle
#print(notLine[left], notLine[right])
if X - notLine[left] <= notLine[right] - X:
    print(notLine[left])
else:
    print(notLine[right])

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N:
  P = set(map(int, input().split()))
else:
  P = set()
c = []
for i in range(102):
  if i not in P:
    c.append((abs(i - X), i))
print(min(c)[1])

Submission status: Accepted

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

    if not n:
        print(x)
        return

    ps = list(map(int, input().split()))
    flgs = [1] * 102

    for p in ps:
        flgs[p] = 0

    ansr = 101
    ansl = 101
    index = x
    while 1:
        if flgs[index] == 1:
            ansr = index
            break
        else:
            index += 1

    index = x
    while 1:
        if flgs[index] == 1:
            ansl = index
            break
        else:
            index -= 1

    if abs(ansr - x) >= abs(ansl - x):
        print(ansl)
    else:
        print(ansr)


solve()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=set(map(int,input().split()))
l=set(range(-100,201))-p
ans=0
tmp=1000
for i in l:
    if tmp>abs(x-i):
        ans=i
        tmp=abs(x-i)
print(ans)

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
num_list = list(map(int, input().split()))
if (len(num_list) == 0) or X not in num_list:
    print(X)
else:
    d = 1
    while True:
        if X - d not in num_list:
            print(X -d)
            break
        elif X + d not in num_list:
            print(X + d)
            break
        else:
            d +=1

Submission status: Accepted

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

def main():

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

    for i in range(101):
        if (X - i) not in p:
            ans = X - i
            break

        elif (X + i) not in p:
            ans = X + i
            break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left
def bin(a, x):
    i = bisect_left(a, x) 
    if i != len(a) and a[i] == x: 
        return True
    else: 
        return False

input = sys.stdin.readline

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

lst = sorted(lst)
i = 0
while True:
    if not(bin(lst, x - i)):
        print(x - i)
        break
    elif not(bin(lst, x + i)):
        print(x + i)
        break
    i += 1

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
A=set(map(int,input().split()))
i=0
while True:
  if not X-i in A:
    print(X-i)
    break
  if not X+i in A:
    print(X+i)
    break
  
  i+=1

Submission status: Accepted

Solution code:

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

P.sort()
olp=lowp=min(P)-2
ohp=hip=max(P)+2
l=len(P)-1
for i in range(len(P)):
    if P[i]>x :
        if olp<x :
            lowp=x
        break
    if P[i]-olp>1:
        lowp = P[i]-1
    olp=P[i]

for i in range(len(P)):
    if P[l-i]<x :
        break
    if ohp-P[l-i]>1:
        hip = P[l-i]+1
    ohp=P[l-i]

# print( lowp, hip, x )

ans = lowp
if x-lowp > hip-x :
    ans = hip
print( ans )

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 in p:
        if x + i in p:
            continue
        else:
            print(x + i)
            exit()
    else:
        print(x - i)
        exit()
else:
    print(x)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    A=list(map(int,input().split()))
    C=[]
    for i in range(n):
        C.append(abs(A[i]-x))
    C.append(0)
    B=[x for x in set(C) if C.count(x) > 1]
    s=0
    ok=0
    for i in range(len(B)):
        if B[i]-i!=0:
            s=i
            ok=1
            break
    if ok==0:
        s=B[-1]+1
    d=x-s
    for i in range(n):
        if A[i]==d:
            d=x+s
    print(d)

Submission status: Accepted

Solution code:
x=list(map(int, input().split()))
if x[1]==0:
  print(x[0])
else:
  p=list(map(int, input().split()))
  i=0
  while True:
    if p.count(x[0]-i)==0:
      print(x[0]-i)
      break
    elif p.count(x[0]+i)==0:
      print(x[0]+i)
      break
    else:
      i+=1

Submission status: Accepted

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

l = [i for i in range(102)]
l = list(set(l) - set(P))

print(min(l, key=lambda n: abs(X - n)))

Submission status: Accepted

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

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

if M==0:
    print(N)
else:
    check_set=set(map(int, input().split()))
    ans_set = set([i for i in range(-1,102)])
    lst = list(ans_set-check_set)
    sorted_lst=sorted(lst)
    print(getNearestValue(sorted_lst, N))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
X,N=map(int, input().split())
p = list(map(int, input().split()))
a=X
for i in range(0,101):
    if (a-i in p)==False:
        print(a-i)
        sys.exit()
    if (a+i in p)==False:
        print(a+i)
        sys.exit()

Submission status: Accepted

Solution code:
import sys

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

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

sub, up = x, x

while True:
  if sub not in p:
    print(sub)
    sys.exit()
  elif up not in p:
    print(up)
    sys.exit()
  sub -= 1
  up += 1

Submission status: Accepted

Solution code:
x , 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: Accepted

Solution code:
X, N = map(int, input().split())
if N>0:
  P = list(map(int, input().split()))
else:
  P = []
i = 0
while True:
  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:
import sys
X, N = map(int, input().split())
p = list(map(int, input().split()))

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

small = X
while small in p:
    small -= 1

large = X
while large in p:
    large += 1

if X - small <= large - X:
    print(small)
else:
    print(large)

Submission status: Accepted

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

Submission status: Accepted

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

if(N != 0):
    ps = list(map(int, input().split()))
else:
    ps = []



ans_list = []

for i in range(-10,110):
    if i not in ps:
        ans_list.append(i)

#print(ans_list)

initial = 10 ** 4
abs_sabun = abs(initial - X)

for ans in ans_list:
#    print(ans, abs_sabun)
    if(abs(ans - X) < abs_sabun):
        abs_sabun = abs(ans - X)
        initial = ans

print(initial)

Submission status: Accepted

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

for i in range(X+1):
    for s in [-1, 1]:
        a = X + s * i
        if p.count(a) == 0:
            print(a)
            exit()

Submission status: Accepted

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

d = {i: 1 for i in p}
idx = X
while True:
    if d.get(idx) is None:
        ans_plus = idx
        break
    else:
        idx += 1

idx = X
while True:
    if d.get(idx) is None:
        ans_minus = idx
        break
    else:
        idx -= 1

if abs(X - ans_plus) < abs(X - ans_minus):
    print(ans_plus)
else:
    print(ans_minus)

Submission status: Accepted

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

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())
if n!=0: #空行の読み込みを回避、処理を高速化するためにpiを集合型で管理する
 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: #{pi}に含まれる場合は計算を行わない
   continue
 else:
   if abs(x-i)<diff: #Xとの差の絶対値が最小になるものを求める
     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()))
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()))

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

Submission status: Accepted

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

P.sort()

L = []
for p in P:
    L.append(p - X)

Ls = sorted(L, key=abs)

for m in range(100):
    if m*(-1) not in Ls:
        print(X - m)
        break
    elif m not in Ls:
        print(X + m)
        break

Submission status: Accepted

Solution code:
#答えが0や101になりうる点に注意が必要
x,n = map(int,input().split())
if n != 0:
    p = list(map(int,input().split()))
    tmp_p = [0] * 102
if n == 0:
    print(x)
else:
    for i in range(n):
        tmp_p[p[i]] += 1
    if tmp_p[x] == 0:
        print(x)
    else:
        j = 1
        stop_min = 0
        stop_max = 0
        while stop_min == 0 or stop_max == 0:
            if x-j >= 0:
                if tmp_p[x-j] == 0:
                    print(x-j)
                    break
            else:
                stop_min += 1
            if x+j <= 101:
                if tmp_p[x+j] == 0:
                    print(x+j)
                    break
            else:
                stop_max += 1
            j += 1

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n != 0:
    p = list(map(int,input().split()))
    tmp_p = [0] * 102
if n == 0:
    print(x)
else:
    for i in range(n):
        tmp_p[p[i]] += 1
    if tmp_p[x] == 0:
        print(x)
    else:
        j = 1
        stop_min = 0
        stop_max = 0
        while stop_min == 0 or stop_max == 0:
            if x-j >= 0:
                if tmp_p[x-j] == 0:
                    print(x-j)
                    break
            else:
                stop_min += 1
            if x+j <= 101:
                if tmp_p[x+j] == 0:
                    print(x+j)
                    break
            else:
                stop_max += 1
            j += 1

Submission status: Accepted

Solution code:
X,N = list(map(int,input().split()))
if N == 0:
    print(X)
    exit()
p = list(map(int,input().split()))
sorted_p = sorted(p)
minDelta = 1000
minI = 0
for i in range(102):
    if not (i in sorted_p):
        delta = abs(X - i)
        if minDelta > delta:
            minDelta = delta
            minI = i
print(minI)

Submission status: Accepted

Solution code:
M = 201
X, N = map(int, input().split())
A = list(map(int, input().split()))


def solve():
    memo = [0] * M
    for a in A:
        d = a - X
        if d >= 0:
            memo[d*2] = 1
        else:
            memo[-d*2-1] = 1
    for i, m in enumerate(memo):
        if m == 0:
            if i % 2 == 0:
                return i//2 + X
            else:
                return -(i+1)//2 + X

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

Submission status: Accepted

Solution code:
X, N =map(int, input().split())
if N != 0:
  p = list(map(int, input().split()))
  p.sort(reverse=True)
  abs_ans = 1000
  ans = 0
  j = 0
  for i in range(p[0]+1, p[len(p)-1]-2, -1):
    abs_i = abs(X-i)
    if i != p[j] and abs_ans >= abs_i:
      abs_ans = abs_i
      ans = i
    if i <= p[j] and j < len(p) -1:
      j += 1

  print(ans)
  # print(p)
else:
  print(X)

Submission status: Accepted

Solution code:
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(list(dict.fromkeys(ans)))
    if(ans[-1]==n):
        ans = ans[:-1]
    return ans

x,n = map(int, input().split())
nums = sorted(list(map(int, input().split())))
ans = 101
bfnd, ffnd = False, False
s1, s2 = 0,0
a, b = x,x
while(not bfnd):
    if(x-s1 not in nums):
        a = x-s1
        bfnd = True
        break
    else:
        s1+=1
while(not ffnd):
    if(x+s2 not in nums):
        b = x+s2
        ffnd = True
        break
    else:
        s2+=1
ans = 0
if(abs(x-a) <= abs(x-b)):
    ans = a
else:
    ans = b
print(ans)

Submission status: Accepted

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

i = 0
while True:
    left = x - i
    right = x + i
    if left not in p:
        print(left)
        break
    elif right not in p:
        print(right)
        break
    i += 1

Submission status: Accepted

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

i = 0
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:
from sys import stdin
input = stdin.readline


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

  min_ = float('inf')
  for i in range(102):
    if i not in P and abs(X - i) < min_:
      min_ = abs(X - i)

  cand = []

  for i in range(102):
    if i not in P and abs(X - i) == min_:
      cand.append(i)

  print(min(cand))


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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if(n==0):
    print(x)
else:
    ar=list(map(int,input().split()))
    if x not in ar:
        print(x)
    else:           #4 5 6 7 10  {8:2;9:3}
        ar.sort()
        di={}
        for i in range(ar[0]-1,ar[n-1]+2):
            if(i not in ar):
                di[i]=abs(x-i)
        #print(di)
        ans=(2**31)
        for i in di.keys():
            if(di[i]<ans):
                k=i
                ans=di[i]
        print(k)

Submission status: Accepted

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

Submission status: Accepted

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

for d in range(x + 2):
	if x - d not in p:
		print(x-d)
		exit()
	if x + d not in p:
		print(x+d)
		exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
sub_min = 100
P_bar = [x for x in range(102)]

for p in P:  
    P_bar.remove(p)

for p_bar in P_bar:
    sub = abs(X - p_bar)
    if sub < sub_min:
        sub_min = sub
        answer = p_bar

print(answer)

Submission status: Accepted

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

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

for d in range(x + 2):
	for s in [-1, 1]:
		a = x + s * d
		if a not in p:
			print(a)
			exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
I=list(map(int,input().split()))
S=[]
T=[]
ans=[]
for i in range(-200,200):
    S.append(i)
    if i in I:
        S.remove(i)
for j in range(len(S)):
    if j==0:
        T.append(S[0])
    elif abs(x-S[j-1])>abs(x-S[j]):
        T.clear()
        T.append(S[j])
print(min(T))

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
X,N = inputlist()
ans = 0
m = 10**9+7
p = inputlist()
for i in range(110):
    flag = 0
    for j in range(N):
        if i == p[j]:
            flag = 1
            break
    if flag:
        continue
    d = abs(X-i)
    if d < m:
        m = d
        ans = i
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(int(N/2)+2):
    if not X-i in p:
        ans = X-i
        break
    if not X+i in p:
        ans = X+i
        break

print(ans)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
if n==0:
  print(x)
  quit()
p = list(map(int, input().split()))
ans = 0
for i in range(x+1):
  x1,x2 = x+i,x-i
  if (x1 in p) and (x2 in p):
    continue
  elif not((x1 in p) or (x2 in p)):
    ans = min(x1,x2)
    break
  elif not(x1 in p):
    ans = x1
    break
  else:
    ans = x2
    break
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=sorted(map(int,input().split()))
ans=x
for i in range(n+1):
    if not (x-i) in p:
        ans=x-i
        break
    elif not (x+i) in p:
        ans=x+i
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in input().split()]

nums = []
min_l = 1000
for i in range(103):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_l:
    min_l = l
    min_num = i
  elif l >= min_l:
    break
print(min_num)

Submission status: Accepted

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

for i in a:
  b.append(abs(i-x))

m=min(b)
  
if m==0:
  for i in range(max(b)+2):
    if a.count(x-i)==0:
      print(x-i)
      exit()
    if a.count(x+i)==0:
      print(x+i)
      exit()
else:
  print(x)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
lst = [0] * 102
p = list(map(int, input().split()))
for i in p:
    lst[i] += 1
if lst[X] == 0:
    print(X)
else:
    up = 1
    dn = 1
    while lst[X+up] == 1:
        up += 1
    while lst[X-dn] == 1:
        dn += 1
    if up >= dn:
        print(X-dn)
    else:
        print(X+up)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
    
p = input().split()
for i in range(100):
    for j in p:
        if int(j) == x - i:
            break
    else:
        print(x - i)
        break
    for j in p:
        if int(j) == x + i:
            break
    else:
        print(x + i)
        break

Submission status: Accepted

Solution code:
xn = input().split()
data_2 = []
x = int(xn[0]) #これに近い値

if int(xn[1]) == 0:
    print(x)
else:
    data_str = input().split()
    data = [int(s) for s in data_str] #data_strをint型に変換
    #data.sort() #小さい順
    #dataにない値が出るまでxから１引き続ける　１引き続けた値をaとする
    a = int(xn[0])
    #check
    while True: #while1
        while True: #while2
            for i in range(len(data)):
                if data[i] != a:
                    continue
                else:
                    a -= 1
                    break #forから抜け出す
            else:
                data_2.append(a)
                break #while2から抜け出す

        if len(data_2) == 1: #リストに１つデータが入っていたら　入ってないならwhile1ループ
            break #while1から抜け出す    


    #dataにない値が出るまでxかに１を足し続ける　１足し続けた値をbとする
    b = int(xn[0])
    while True: #while1
        while True: #while2
            for i in range(len(data)):
                if data[i] != b:
                    continue
                else:
                    b += 1
                    break #forから抜け出す
            else:
                data_2.append(b)
                break #while2から抜け出す

        if len(data_2) == 2: #リストに2つデータが入っていたら　入ってないならwhile1ループ
            break #while1から抜け出す  


    #aとbの小さい方をprint
    if abs(x-a) <= abs(b-x):
        print(a)
    else:
        print(b)

Submission status: Accepted

Solution code:
xn = input().split()
data_2 = []
x = int(xn[0]) #これに近い値

if int(xn[1]) == 0:
    print(x)
else:
    data_str = input().split()
    data = [int(s) for s in data_str] #data_strをint型に変換
    data.sort() #小さい順
    #dataにない値が出るまでxから１引き続ける　１引き続けた値をaとする
    a = int(xn[0])
    #check
    while True: #while1
        while True: #while2
            for i in range(len(data)):
                if data[i] != a:
                    continue
                else:
                    a -= 1
                    break #forから抜け出す
            else:
                data_2.append(a)
                break #while2から抜け出す

        if len(data_2) == 1: #リストに１つデータが入っていたら　入ってないならwhile1ループ
            break #while1から抜け出す    


    #dataにない値が出るまでxかに１を足し続ける　１足し続けた値をbとする
    b = int(xn[0])
    while True: #while1
        while True: #while2
            for i in range(len(data)):
                if data[i] != b:
                    continue
                else:
                    b += 1
                    break #forから抜け出す
            else:
                data_2.append(b)
                break #while2から抜け出す

        if len(data_2) == 2: #リストに2つデータが入っていたら　入ってないならwhile1ループ
            break #while1から抜け出す  


    #aとbの小さい方をprint
    if abs(x-a) <= abs(b-x):
        print(a)
    else:
        print(b)

Submission status: Accepted

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

    ans = 0
    for i in range(102):
        if i in p:
            continue
        if abs(x - ans) > abs(x - i):
            ans = i
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
xn=input().split()
x=int(xn[0])

data=input().split()
for i in range(100):
    for d in data:
        if int(d) == x-i:
            break
    else:
        print(x-i)
        break
    
    for d in data:
        if int(d) == x+i:
            break
    else:
        print(x+i)
        break

Submission status: Accepted

Solution code:
def forbidden_list():
    # 入力
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    # 初期処理
    min_abs_list = list()
    # N = 0 の場合
    if N == 0:
        return X
    # X + i
    i = 0
    while True:
        if X + i in P:
            i += 1
        else:
            min_abs_list.append(X + i)
            break
    # X - i
    i = 0
    while True:
        if X + i in P:
            i -= 1
        else:
            min_abs_list.append(X + i)
            break
    # X との絶対値が最小のもの
    if abs(X - min_abs_list[0]) > abs(X - min_abs_list[1]):
        return min_abs_list[1]
    elif abs(X - min_abs_list[0]) == abs(X - min_abs_list[1]):
        return min(min_abs_list)
    elif abs(X - min_abs_list[0]) < abs(X - min_abs_list[1]):
        return min_abs_list[0]

result = forbidden_list()
print(result)

Submission status: Accepted

Solution code:
# abc170_c.py
# https://atcoder.jp/contests/abc170/tasks/abc170_c

# C - Forbidden List /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 整数 Xと、長さ N の整数列 p1,…,pNが与えられます。
# 整数列 p1,…,pNに含まれない整数 (正とは限らない) のうち X に最も近いもの、
# つまり Xとの差の絶対値が最小のものを求めてください。そのような整数が複数存在する場合は、そのうち最も小さいものを答えてください。

# 制約
#     1≤X≤100
#     0≤N≤100
#     1≤pi≤100
#     p1,…,pNはすべて異なる。
#     入力中のすべての値は整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# X N
# p1 ... pN

# 出力
# 答えを出力せよ。

# 入力例 1
# 6 5
# 4 7 10 6 5

# 出力例 1
# 8

# 整数列 4,7,10,6,5に含まれない整数のうち、最も 6 に近いものは 8です。

# 入力例 2
# 10 5
# 4 7 10 6 5

# 出力例 2
# 9

# 整数列 4,7,10,6,5に含まれない整数のうち、最も 10 に近いものは 9 と 11 です。このうち小さい方である 9を出力します。

# 入力例 3
# 100 0

# 出力例 3
# 100

# N=0の場合、入力の 2 行目は空行となります。また、この場合のように、X 自身も答えとなりえます。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    X, N = list(map(int, lines[0].split()))
    if N == 0:
        return [X]
    else:
        values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    mi = min(values)
    ma = max(values)

    distance = None
    # for i in [8]:
    for i in range(mi-1, ma+2):
        if i not in values:
            tmp = abs(X-i)
            if distance is None:
                result = i
                distance = tmp
            elif distance > tmp:
                result = i
                distance = tmp

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['6 5', '4 7 10 6 5']
        lines_export = [8]
    if pattern == 2:
        lines_input = ['10 5', ' 4 7 10 6 5']
        lines_export = [9]
    if pattern == 3:
        lines_input = ['100 0', '']
        lines_export = [100]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
Q = [i for i in range(-150, 150)]
P = list(set(Q) - set(P))
P.sort()
dif = 100
for p in P:
    if abs(X-p) < dif:
        dif = abs(X-p)
        ans = p
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

exist_P = defaultdict(int)

for p in P:
    exist_P[p] = 1

diff = X + 1
ans = -1
for i in range(0, 102):
    if exist_P[i] == 0:
        if abs(X - i) < diff:
            ans = i
            diff = abs(X - i)
print(ans)