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: Wrong Answer

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

listP.sort()

minD = 200
val = 0
bef = None
for p in listP:
    if bef == None:
        bef = p
    else:
        if p-1 == bef:
            pass
        else:
            if bef < x < p:
                minD = 0
                val = x
            elif x <= bef:
                if abs(bef+1-x) < minD:
                    minD = abs(bef+1-x)
                    val = bef+1
            else:
                if abs(p-1-x) < minD:
                    minD = abs(p-1-x)
                    val = p-1
        bef = p
if bef!= None and abs(bef+1-x) < minD:
    val = bef+1
if not x in listP:
    val = x
elif val == 0:
    if abs(0-x) > abs(101-x):
        val = 101
    else:
        val = 0

print(val)

Submission status: Wrong Answer

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

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

p.sort()

minp = 999
minv = x
if n == 100:
    print()
else:
    for i in range(1, 101):
        if i in p:
            continue
        else:
            if abs(i - x) < minp:
                minp = abs(i - x)
                minv = i
            else:
                break
    print(minv)

Submission status: Wrong Answer

Solution code:
import sys

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

x, n, *p = map(int, read().split())

min_d = 1000000

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

for i in range(101):
    if i in p:
        continue
    d = abs(x - i)
    if d < min_d:
        min_d = d
        ans = i

print(ans)

Submission status: Wrong Answer

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

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

min_diff_val = X
min_val = 0
for y in range(101):
    if not (y in p):
        if min_diff_val > abs(y - X):
            min_val = y
            min_diff_val = abs(y - X)
print(min_val)

Submission status: Wrong Answer

Solution code:
import collections

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

queue = collections.deque([X-1, X+1])

while True:
  cur = queue.popleft()
  if cur in p:
    if cur < X:
    	queue.append(cur-1)
    else:
    	queue.append(cur+1)
  else:
  	print(cur)
  	break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
ps = list(map(int, input().split()))
anss = [101] * 102
for i in range(101):
  if (i not in ps):
    anss[i] = abs(x - i)
m = min(anss)
for i, ans in enumerate(anss):
  if ans == m:
    print(i)
    exit()

Submission status: Wrong Answer

Solution code:
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

X, N = nn()
P = nn()

if N == 0:
    print(X)
else:
    d = 999

    if X <= 50:
        ans = 0
    else:
        ans = 101

    for i in range(101):
        if (i in P):
            continue

        t = abs(X - i)
        if t < d:
            d = t
            ans = i
       

    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
	print(X)
	exit()
p=list(map(int,input().split()))
tmp=100000
for i in range(-100,101):
	if i in p:
		continue
	if tmp>abs(X-i):
		ans=i
		tmp=abs(X-i)
print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n!=0:
  li=list(map(int,input().split()))
  si=list(range(-1,101))

  for k in li:
    si.remove(k)
  li=si  
  li=sorted(li,reverse=True)
  sa=150
  ans=0
  for i in li:
    mi=abs(i-x)
    sa=min(mi,sa)
    if mi==sa:
      ans=i

  print(ans)
else:
  print(x)

Submission status: Wrong Answer

Solution code:
from bisect import bisect

x, n = map(int, input().split())
ls = list(map(int, input().split()))
mx = [True] * 100
for i in ls:
	mx[i - 1] = False
r = x - 1
ans1 = 10000000
ans2 = -10000000
while r < 100:
	if mx[r]:
		ans1 = r + 1
		break
	r += 1
l = x - 1
while l >= 0:
	if mx[l]:
		ans2 = l + 1
		break
	l -= 1
if x - ans2 < ans1 - x:
	print(ans2)
elif x - ans2 > ans1 - x:
	print(ans1)
else:
	print(ans2)

Submission status: Wrong Answer

Solution code:
XN = input().split()

X = int(XN[0])
N = int(XN[1])

ps = input().split()
p = []

for i in range(N):
    p.append(int(ps[i]))

ans = X
ansisfound = False

if X not in p:
    ansisfound = False

for i in range(len(p)):
    if ansisfound:
        break
    if X + i not in p:
        ans = X + i
        ansisfound = True
    if X - i not in p:
        ans = X - i
        ansisfound = True

print(ans)

Submission status: Wrong Answer

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

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


a = 1
for m in range(1,100 + 1):
    if m in p:
        continue
    else:
        if abs(x - a) > abs(x - m):
            a = m

print(a)

Submission status: Wrong Answer

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

nota = list()

for i in range(-100, 101):
    if i in a:
        continue
    nota.append(i)

nota.sort()
ans = 1000
minabs = 1000
for i in nota:
    if minabs > abs(i-x):
        minabs = abs(i-x)
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

A = list(map(int,stdin.readline().split()))
B = list(map(int,stdin.readline().split()))
C = [x for x in range(-100,101)]
C = set(C)
B = set(B)
C = C.difference(B)
C = list(C)
X=A[0]
N=A[1]
record=200
number=0
K=0

if N==0:
    print(X)
    K=1

for t in C:
    diff=abs(t-X)
    if diff<record:
        record=diff
        number=t
    elif diff==record:
        number=min(number,t)

if K==0:
   print(number)

Submission status: Wrong Answer

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

if not n:
	print(x)
	exit()

while True:
	if x-v not in p:
		print(x-v)
		break
	elif x+v not in p:
		print(x+v)
		break

	v += 1

Submission status: Wrong Answer

Solution code:
def main():
    x,n = map(int,input().split())
    if n>0:
        p = list(map(int,input().split()))
    else:
        p = []
    d = [i for i in range(0,102)]
    for i in range(len(d)):
        if d[i] in p:
            d[i] = 0
    d = sorted(d)
    m = 10000
    ans = 0
    for i in range(len(d)):
        if d[i]==0:
            continue
        if m>abs(d[i]-x):
            m = abs(d[i]-x)
            ans = d[i]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    x, n = map(int, input().split())
    if n >0:
        a = [int(i) for i in input().split()]
        listN = [i for i in range(-1,100)]
        diffList = list(set(listN) -set(a) )
        ans = 0
        diff = 100
        for i in diffList:
            now = 0
            if i>0:
                now = abs(i-x)
            else:
                now = i+x
            if diff > now:
                diff=now
                ans =i
        print(ans)
    else:
        print(x)

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
if N == 0:
    print(X)
elif N == 100:
    print(0)
else:
    p = list(map(int,input().split()))
    K = X
    L = 0
    for i in range(X,101):
        if i in p:
            continue
        else:
            K = i-X
            L = i
            break
    for i in range(X-K,X):
        if i in p:
            continue
        else:
            L = i
    print(L)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
L = [i+1 for i in range(100)]
for item in p:
    L.pop(L.index(item))

MIN = 10**5
ans = 10**5
for item in L:
    if abs(item-X) < MIN:
        MIN = abs(item-X)
        ans = item

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
msf = 1000
for i in range(100,-101,-1):
    if i not in lis:
        diff = abs(i-x)
        if(min(diff,msf)==diff):
            msf = diff
            ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
def calc():
    x, n, *p = map(int, open(0).read().split())
    h = set(p)
    for i in range(1, n+1):
        a = x - i
        b = x + i
        if a not in h:
            return a
        if b not in h:
            return b
    return x

print(calc())

Submission status: Wrong Answer

Solution code:
import numpy as np
X,N = map(int,input().split())
a = 0
if N != 0:
    P = [int(i) for i in input().split()]
    for p in range(1,len(P)+1):
        if X-p not in P:
            print(X-p)
            break
        elif X+p not in P:
            print(X+p)
            break
else:
    print(X)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N == 0:
    if(X <= 50):
        print("0")
    else:
        print("100")
else:
    P = list(map(int,input().split()))
    mini = 100
    ANS = 0
    for i in range(101):
        if P.count(i) == 0:
            if mini > abs(X-i):
                mini = abs(X-i)
                ANS = i
    print(str(ANS))

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
a = list(map(int, input().split()))
if (x not in a):
    print(x)
    exit()


tar1 = x
tar2 = x
ff1 = True
ff2 = True

while True:
    if (ff1 is True):
        tar1 -= 1
        if (tar1 == 0):
            ff1 = False
        else:

            if (tar1 not in a):
                print(tar1)
                exit()

    if (ff2 is True):
        tar2 += 1
        if (tar2 == 100):
            ff1 = False
        else:

            if (tar2 not in a):
                print(tar2)
                exit()

    if ((ff1 is False) and (ff2 is False)):
        break

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = float("inf")
for i in range(-101,101):
    if i not in p:
        ans = min(ans,abs(x-i))
if x - ans not in p:
    print(x-ans)
else:
    print(x+ans)

Submission status: Wrong Answer

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

minv=100
v=0
if P:
  for i in range(101):
    if not(i in P):
      if abs(X-i) < minv:
        minv=abs(X-i)
        v=i
else:
  v=X

print(v)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
ans = 101
for i in range(-1,101):
    if not i in p:
        if abs(i-X) < abs(ans-X):
            ans = i

print(ans)

Submission status: Wrong Answer

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

num = sorted([[abs(X - i),i] for i in range(-100,101) if i not in P],key = lambda x: x[0])

print(num[0][1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
import random
from decimal import Decimal


X, N = [int(x) for x in stdin.readline().rstrip().split()]
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

ans = 10**9
ans1 = [0, 10**9]
for i in range(-100, 100):
    if i not in p:

        if ans > abs(X-i):
            ans = X-i
            if ans1[1] == abs(X-i):
                pass
            else:
                ans1[0] = i
            # ans1[1] = abs(X-i)
            # if ans1 > i:
            #     ans1 = i
                # print(i)
print(ans1[0])

Submission status: Wrong Answer

Solution code:
x,n = [int(x) for x in input().split()]
if n == 0:
    print(x)
    exit()
p = [int(x) for x in input().split()]
a = [-1]
for i in range(100):
    if i in p:
        continue
    a.append(i)
for i in range(100,201):
    a.append(i)
b = [0]*len(a)
for i in range(len(a)):
    b[i] = a[i]
for i in range(len(a)):
    a[i] = abs(a[i]-x)
m = min(a)
if x - m in b:
    print(x-m)
else:
    print(x+m)

Submission status: Wrong Answer

Solution code:
X,N=map(int, input().split())
try: 
    p=list(map(int, input().split()))
except:
    print(X)
    exit(0)
c=1
while 1:
    if X-c not in p:
        print(X-c)
        exit(0)
    if X+c not in p:
        print(X+c)
        exit(0)
    c+=1

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
min = 0
i = 0
while True:
    if abs(X - i) == min:
        if i not in p:
            break
        else:
            min += 1
            i = 0
    i += 1

print(i)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
in_1 = [int(x) for x in input().split(' ')]
x = in_1[0]
n = in_1[1]
result = 0

# n=0の場合、resultにxを設定する
if n == 0:
  result = x
# 絶対値が小さい順にin_dataに含まれるか検索し、含まれなければresultにx-i,もしくはx+1を設定する
else:
  in_data = [int(x) for x in input().split(' ')]
  for i in range(100):
    tmp_m = max(x-i,1)
    tmp_p = min(x+i,100)
#    print('tmp_m:{}'.format(tmp_m))
#    print('tmp_p:{}'.format(tmp_p))
    if tmp_m not in in_data:
      result = tmp_m
      break
    if tmp_p not in in_data:
      result = tmp_p
      break

print(result)

Submission status: Wrong Answer

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


for i in range(1,N):
    a = X+i
    b = X-i
    if b>0 and b not in p:
        print(b)
        break
    elif a>0 and a not in p:
        print(a)
        break

if N==0:
    print(X)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = [int(x) for x in input().split()]
cand = 1000
ans = -100
for t in range(-100, 101):
    if not(t in P):
        if abs(t-X) < cand:
            cand = abs(t-X)
            ans = t
print(ans)

Submission status: Wrong Answer

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

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

for i in range(-100, 101):
    if(not i in p):
        if((abs(x-ans) > abs(x-i)) or(abs(x - ans) == abs(x - i) and i < ans)):
            ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P = list(map(int,input().split()))
value = float('inf')
if(N==0):
    print(X)
    exit()
P.append(X)
ans_value= 100
for i in range(-1,101):
    if (i not in P):
        if(abs(X-i)<value):
            value=abs(X-i)
            ans_value=i
print(ans_value)

Submission status: Wrong Answer

Solution code:
import numpy as np

a = input()
a, b = a.split()
a = int(a)
if int(b) == 0:
  print(a)
  exit()
n = input()
n = [int(i) for i in n.split()]
li = list(range(min(n), max(n) + 1))
for i in n:
  li.remove(i)
mini = [np.inf, 0]
for i in li:
  if abs(i - a) == mini[0]:
    if i < mini[1]:
      mini = [abs(i - a), i]
  elif abs(i - a) < mini[0]:
    mini = [abs(i - a), i]
print(mini[1])

Submission status: Wrong Answer

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

min_p = 200
for i in range(-100,101):
    if not (i in p):
        min_p = min(min_p, abs(i-x))
if x-min_p > 0 or x + min_p > 0:
    if not (x-min_p in p):
        print(x-min_p)
    else:
        print(x+min_p)
else:
    if not (x+min_p in p):
        print(x+min_p)
    else:
        print(x-min_p)

Submission status: Wrong Answer

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

if n == 0:
    print(x)
    exit()
if n == 100:
    if x >= 51:
        print(101)
    else:
        print(-1)
    exit()

alist = list(range(1,101))
for i in plist:
    alist.remove(i)

alist.sort()
alist.reverse()
ans = 0
count = 1000
for j in alist:
    if count >= abs(x - j):
        count = abs(x-j)
        ans = j

print(ans)

Submission status: Wrong Answer

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

for i in range(n+1):
    if x-i not in p:
        print(x-i)
        break
    elif x+i not in p:
        print(x+i)
        break
    else:
        continue
if not p:
    print(x)

Submission status: Wrong Answer

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    x, n = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    if n == 0:
        print(x)
    else:
        P = list(map(int, input().split()))
        P.sort()
        #B = [i for i in range(102)]

        if x not in P:
            print(x)
        else:
            xindex = P.index(x)

            for j in range(1,100):
                if xindex - j >= 0:
                    if P[xindex - j] != x-j:
                        print(x-j)
                        break
                else:
                    print(x-j)
                if xindex + j <= n-1:
                    if P[xindex + j] != x+j:
                        print(x+j)
                        break
                else:
                    print(x-j)

resolve()

Submission status: Wrong Answer

Solution code:
X,N= map(int,input().split())
p = list(map(int, input().split()))
p = sorted(p)
ans_tmp = 10**9+7
ans = 0
if len(p)==0:
    print(X)
else:
    for i in range(-1000,1000):
        if i in p:
            continue
        else:
            tmp = abs(i-X)
            if tmp <ans_tmp:
                ans = i
            ans_tmp= min(tmp,ans_tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N>0:
    p=list(map(int,input().split()))
else:
    print(X)
    exit()
Y=X
Z=X
s=0
t=0
while s==0:
    Y+=1
    if Y not in p:
        break
while t==0:
    Z-=1
    if Z not in p:
        break
if abs(X-Y)<abs(X-Z):
    print(Y)
elif abs(X-Y)>abs(X-Z):
    print(Z)    
else:
    print(Z)

Submission status: Wrong Answer

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

if N == 0:
    print(X)
else:
    for i in range(1, 100):
        # 左からと右からを交互に計算
        left = X - i
        right = X + i

        if left not in p:
            print(left)
            break
        if right not in p:
            print(right)
            break

Submission status: Wrong Answer

Solution code:
import numpy as np
# スペース区切りの整数の入力
X, N = map(int, input().split())

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

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

## sec2
for i in range(100):
    if sum(P == X - i) == 0:
        print(X - i)
        exit(0)
    if sum(P == X + i) == 0:
        print(X + i)
        exit(0)

Submission status: Wrong Answer

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

min_val = -1
for i in range(-100, 101):
    if i in P:
        continue
    if abs(min_val - X) > abs(X - i):
        min_val = i
if len(P) == 0:
    print(X)
else:
    print(min_val)

Submission status: Wrong Answer

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

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

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

set = {i for i in range(-100, 100)}
for i in li:
    if i in set:
        set.remove(i)

min = 1000
for i in set:
    if abs(x - i) < min:
        min = abs(x - i)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
tmp=0
if n==0:
    print(x)
    sys.exit()
for i in range(1,101):
    ans=x-i
    if not ans in p:
        print(ans)
        sys.exit()
    ans=x+i
    if not ans in p:
        print(ans)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

X, N = nn()
P = nn()

if N == 0:
    print(X)
else:
    d = 999
    ans = -1
    for i in range(101):
        if (i in P):
            continue

        t = abs(X - i)
        if t < d:
            d = t
            ans = i
    else:
        if X <= 50:
            ans = 0
        else:
            ans = 101

    print(ans)

Submission status: Wrong Answer

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

listP.sort()

minD = 200
val = 0
bef = None
for p in listP:
    if bef == None:
        bef = p
    else:
        if p-1 == bef:
            pass
        else:
            if bef < x < p:
                minD = 0
                val = x
            elif x <= bef:
                if abs(bef+1-x) < minD:
                    minD = abs(bef+1-x)
                    val = bef+1
            else:
                if abs(p-1-x) < minD:
                    minD = abs(p-1-x)
                    val = p-1
        bef = p
if bef!= None and abs(bef+1-x) < minD:
    val = bef+1
elif not x in listP:
    val = x
elif val == 0:
    if abs(0-x) > abs(101-x):
        val = 101
    else:
        val = 0

print(val)

Submission status: Wrong Answer

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

if len(P) == 0:
    print(X)
    sys.exit()

flg = 1000
ans = 1000
m = max(P)
itera = list(range(m + 1))
itera.reverse()

for i in itera:
    if not i in P and flg > abs(X - i):
        flg = abs(X - i)
        ans = min(ans, i)

if ans == 1000:
    ans = m + 1

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect

X, N = [int(n) for n in input().split()]
if N==0:
    print(X)
else:
    P = sorted([int(n) for n in input().split()])
    idx = bisect(P, X)
    ans_r = 10**9
    ans_l = 10**9*(-1)
    for i in range(P[idx-1], 101):
        if i not in P:
            ans_r = i
            break
    for j in range(1, P[idx-1]):
        if j not in P:
            ans_l = j
    if abs(X-ans_l) == abs(ans_r-X):
        print(min(ans_l, ans_r))
    else:
        print(ans_l if abs(X-ans_l) < abs(ans_r-X) else ans_r)

Submission status: Wrong Answer

Solution code:
import os

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

n_list = []
for i in range(101):
    n_list.append(i)
p.sort()

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

for i in range(n):
    del n_list[p[i]-i]

mini = 0
min = 1000
for b in n_list:
    if min>abs(x-b):
        min = abs(x-b)
        mini = b

print(mini)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
p_bar=[]
for i in range(0,101):
  if i not in p:
    p_bar.append(i)

d_min=1000
i_min = 0
for i in p_bar:
  d = abs(X-i)
  if d < d_min:
    d_min = d
    i_min = i
print(i_min)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    X, N = map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    L = []
    for i in range(1, 101):
        if not i in P:
            L.append(i)
    #print(L)
    ans = 1000
    for l in L:
        ans = min(ans, abs(X-l))
    
    if X-ans>=0:
        if (X-ans) in P:
            print(X+ans)
        else:
            print(X-ans)
    else:
        if (ans-X) in P:
            print(ans +X)
        else:
            print(ans-X)




if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

num = sorted([[abs(X - i),i] for i in range(-100,101) if i not in P],key = lambda x: x[0])

print(num)

Submission status: Wrong Answer

Solution code:
from bisect import bisect

x, n = map(int, input().split())
ls = list(map(int, input().split()))
mx = [True] * 100
for i in ls:
	mx[i - 1] = False
r = x - 1
ans1 = 10000000
ans2 = 10000000
while r < 100:
	if mx[r]:
		ans1 = r + 1
		break
	r += 1
l = x - 1
while l >= 0:
	if mx[l]:
		ans2 = l + 1
		break
	l -= 1
if x - ans2 < ans1 - x:
	print(ans2)
elif x - ans2 > ans1 - x:
	print(ans1)
else:
	print(ans2)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N >0:
  p = list(map(int,input().split()))
a = 100
ans = []
for i in range(-101,101):
  if N == 0:
    ans = X
    break
  if p.count(i) == 0 and a >= abs(X - i):
    a = abs(X - i)
    ans = i
if N > 0:
  for i in range(-101,101):
    if abs(X-i) == abs(X-ans) and p.count(i) == 0:
      ans = i
      break
print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
p = input().split()
for i in range(len(p)):
    p[i] = int(p[i])
index = 1
while True:
    if p == []:
        print(x)
        break
    try:
        a = p.index(x-index)
    except ValueError:
        print(x-index)
        break

    try:
        b = p.index(x+index)
    except ValueError:
        print(x+index)
        break

    index += 1

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  a = 100
  ans = 0
  for i in range(1,101):
    if i not in p:
      b = abs(x - i)
      if a == b:
        if ans > i:
          ans = i
      if b < a:
        a = b
        ans = i
    else:
      pass
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
if n==0:
    print(x)
    sys.exit()
else:
    p=list(map(int,input().split()))
    res=1000
    ans=0
    for i in range(1,101):
        p.append(i)
        if len(p)==len(set(p)):
            if res>=abs(x-i):
                res=abs(x-i)
                ans=i
        del p[-1]
    for i in range(n):
        if x+(x-ans)!=p[i]:
            print(x+(x-ans))
            sys.exit()
    print(ans)

Submission status: Wrong Answer

Solution code:
x, n, *P = map(int, open(0).read().split())
A = list(range(102))
P = set(P)
B = []
m = 10**4
for a in A:
    if a not in P:
        if abs(x-a) < m:
            m = abs(x-a)
            B.append((m, a))
print(min([k for v, k in B if v == B[0][0]]))

Submission status: Wrong Answer

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

result = 0
if N == 0:
    result = X
else:
    list = [i for i in range(-100,101)]
    for i in P:
        list.remove(i)
    min = 100
    for i in list:
        if min > abs(X-i):
            min = abs(X - i)
            result = i

print(result)

Submission status: Wrong Answer

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

minv=100
v=0
if P:
  for i in range(100):
    if not(i in P):
      if abs(X-i) < minv:
        minv=abs(X-i)
        v=i
else:
  v=X

print(v)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

anskouho = []
if p:
    val = []
    for i in range(-100,101):
        if i not in p:
            anskouho.append(i)
    for i in anskouho:
        val.append(abs(x - i))
    if x - min(val) not in p:
        print(x - min(val))
    else:
        print(x + min(val))
else:
    print(x)

Submission status: Wrong Answer

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

if N==0:
    print(X)
else:
    Q = [i-1 for i in range(102)]
    for a in P:
        Q.remove(a)
    Q1 = [abs(b - X) for b in Q]
    print(Q[Q1.index(min(Q1))])

Submission status: Wrong Answer

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