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(' '))
found = False
goal = 0
challenge_plus = X
challenge_minus = X
# そもそもNが0ならXが正解
# Xを基準に大きい方向、小さい方向の両方向へ1づつ数値をずらしていき、
# p_listにヒットしない整数が合ったときに正解となる。
# 同時に大小ヒットした場合は小さいほうが正解

if(N == 0):
  found = True
  goal = X
else:
  p_list = list(map(int, input().split(' ')))
  max_p = max(p_list)
  min_p = min(p_list)
  #print(X,N)
  #print(p_list)
  #print(max_p, min_p)

  for i in range(102):
    tmp_break = False
    challenge_plus += 1
    challenge_minus -= 1
    #print("比較対象は{0}, {1}".format(challenge_plus, challenge_minus))
    if not (challenge_plus in p_list):
      goal = challenge_plus
      found = True
      tmp_break = True
      
    if not(challenge_minus in p_list):
      goal = challenge_minus
      found = True
      break
      
    if(tmp_break):
      break

if(found):
  print(goal)
else:
  #print("foundが最後までfalseだった例")
  challenge_plus += 1
  challenge_minus -= 1
  dist_plus = abs(challenge_plus - X)
  dist_minus = abs(challenge_minus - X)
  if(dist_plus < dist_minus):
    print(challenge_plus)
  else:
    print(challenge_minus)

Submission status: Wrong Answer

Solution code:
import numpy as np

X, N = map(int, input().split())
p_list = set([int(i) for i in input().split()])
set_all = set(np.arange(0, 101))
ex_list = set_all-p_list
ex_list = list(ex_list)
diff_list = [np.abs(i-X) for i in ex_list]
min_index = np.argmin(diff_list)
print(ex_list[min_index])

Submission status: Wrong Answer

Solution code:
input_list1 = input().split()
input_list1_int = [int(x) for x in input_list1]

try:
    input_list2 = input().split()
    input_list2_int = [int(x) for x in input_list2]

    num_min = min(input_list2_int)
    num_max = max(input_list2_int)
    
    if input_list1_int[1] == 1:
        answer = input_list1_int[0] -1
        
    else:
        if num_min > input_list1_int[0]:
            answer = input_list1_int[0]
        
        elif num_max < input_list1_int[0]:
            answer = input_list1_int[0]
        
        else:
            number_list = list(range(num_min,num_max+1))
            pre_abs = 10000000
        
        
            for i in input_list2_int:
                number_list.remove(i)
    
            if input_list1_int[0] in number_list:
                answer = input_list1_int[0]
    
            else:
                for j in number_list:
                    temp1 = abs(j - input_list1_int[0])
                    if temp1 < pre_abs:
                        pre_abs = temp1
                        answer = j
            
                    else:
                        break
    print(answer)

except:
    print(input_list1_int[0])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
x, N = map(int, input().split())

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

min_abs = 100
min_num = -100

for num in range(0, 101):
    if not num_list:
        min_num = x
        break
    elif num in num_list:
        continue
    else:
        b = abs(x-num)
        if b < min_abs:
            min_abs = b
            min_num = num
            
            
print(min_num)

Submission status: Wrong Answer

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

def main():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
        exit()
    p = set(map(int,input().split()))
    if N == 100:
        print(0 if X<=50 else 100)
        exit()
    lst = list(set(range(1,101)) - p)
    lst2 = [abs(lst[i] - X) for i in range(len(lst))]
    min_ = min(lst2)
    print(lst[lst2.index(min_)])    



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
elif n==100 and x==100:
    print(0)
else:
    lst=list(map(int,input().split()))[:n]
    for j in range(1,100000):
        x1=abs(abs(x)+abs(j))
        x2=abs(abs(x)-abs(j))
        if x2 not in lst:
            print(x2)
            break
        elif x1 not in lst:
            print(x1)
            break
        else:
            continue

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
a,b = map(int, input().split()) 

if b==0:
    #print(a)
    exit()
num_list = list(map(int, input().split()))

    

num=[True]*101
#print(num)


for i in range(b):
    num[num_list[i]]=False
#print(num)
    
count=0
min_min=0
min_max=0
i=a
#print()
#print(i)

flag_i=0
frag_j=0
if i==100 and num[100]==True:
    print(100)
    exit()

    
    
while 1:
    if i-1==99:
        flag_i=1
        break
    elif num[i-1]==True:
        min_min=i-a
        break
    i+=1

j=a
#print(j)
count=0
while 1:
    if j-1==0:
        flag_j=1
        break
    elif num[j-1]==True:
        min_max=a-j
    j-=1
    
#print(i)
if min_min<min_max:
    print(i-1)
    
else:
#   if flag_j==1:
#       j=j+1
    print(j-1)

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    _near = 0
    for i in range(101):
        if i in p:
            continue
        if abs(_near - x) > abs(i - x):
            if _near > i:
                _near = i
    print(_near)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math 
X, N = map(int,input().split())
d = int(999)
d1 = int()
ans = int(999)
if 1 < N:
    P = list(map(int,input().split()))
    for i in range(1,max(P)):
        if P.count(i) == 0:
            d1 = abs(X-i)
            if d1 < d and 0 <= d1 :
                d = d1
                ans = i
    print(ans)
else:
    print(X)

Submission status: Wrong Answer

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

def main():
    if len(p) == 0:
        print(x)
        return

    ans_l = list(range(x-10, x+10))

    diff_l = list(set(p) ^ set(ans_l))
    diff_l.sort()

    cnt = 100
    ans = 100
    for i in range(0, len(diff_l)):
        check = abs(diff_l[i]-x)
        # print(check)
        if check < cnt:
            cnt = check
            ans = diff_l[i]
    print(ans)
    return

main()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
seisulist = list(map(int, input().split()))
if n != 0 and max(seisulist) > x:
    size = max(seisulist) + 1
else:
    size = x + 1
numlist = [i for i in range(-1*size,size) if i not in seisulist]
xretu = [x]*len(numlist)
hikizan = [abs(s-t) for (s, t) in zip(numlist, xretu)]
sa = min(hikizan)
if x-sa not in seisulist:
    print(x-sa)
else:
    print(x+sa)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
d = list(a*0 for a in range(n))

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

Submission status: Wrong Answer

Solution code:
x, n = input().split()
pn = map(int,input().split())
ints = [i for i in range(101)]
for p in pn:
  ints[p] = -200

x = int(x)
_min = 200
argmin = -100
for _int in ints:
  if abs(_int - x) < _min:
    _min = abs(_int - x)
    argmin = _int

print(argmin)

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 = list(range(0,101))
    ab = 100
    an = []
    for i in range(N):
        a.remove(P[i])
    for j in range(100 - N):
        ab = min(ab,abs(X - a[j]))
    if X - ab in a :
        print(X - ab)
    elif X + ab in a:
        print(X + ab)

Submission status: Wrong Answer

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

k=100
for i in range(0,101):
    d=abs(X-i)
    if d<k and(i not in list1):
        k=d
        A=i
print(A)

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
ans_y = None
if n == 0:
  print(x)
elif n == 1:
  p = list(map(int, input().split()))
  if x == p[0]:
    print(x-1)
  else:
    print(x)
else:
  p = list(map(int, input().split()))
  p.sort()
  m = float("inf")
  if x<p[0] or p[n-1]<x:
    print(x)
  else:
    for y in [y for y in range(p[0]-1,p[n-1]) if not y in p]:
      if abs(x-y)<m:
        m = abs(x-y)
        ans_y = y
  if ans_y != None:
    print(ans_y)

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input(). split())
l = [0]*n
m = [0]*100
p = list()
if n > 0:
  p = list(map(int, input(). split()))
else:
  print(x)
  sys.exit()
for i in range(n):
  l[i] = abs(x-p[i])
  m[l[i]] += 1
if m[0] == 0:
  print(x)
for j in range(1, 100):
  if m[j] == 0:
    a = x-j
    A = x+j
    if a > 0:
      print(a)
      sys.exit()
    else:
      print(A)
      sys.exit()
  if m[j] == 1:
    a = x-j
    A = x+j
    b = p.count(a)
    B = p.count(b)
    if b == 0:
      print(a)
    else:
      print(A)
    break

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = list(map(int, input().split()))
try:
	p = np.array(list(map(int, input().split())))
except EOFError:
    print(X)
    exit()
I = np.arange(1, 101)
idx = np.argsort(np.abs(I - X)) + 1
for i in idx:
    if i not in p:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
#C
X,N = map(int,input().split())
p = list(map(int,input().split()))
if N == 0:
    p = [-1]
else:
    pass
mx = max(100,max(p),abs(min(p)))
mi = min(-1,min(p)-1)
for i in range(mx,mi,-1):
    if i in p:
        pass
    else:
        if abs(mx-X) >= abs(i-X):
            mx = i
        else:
            pass
print(mx)

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    _near = 0
    for i in range(101):
        if i in p:
            continue
        if abs(_near - x) > abs(i - x):
            if _near < i:
                _near = i
    print(_near)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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


if x <= 50:
    minp = abs(-1 - x)
    minv = -1
    p.sort()
else:
    minp = abs(101 - x)
    minv = 101
    p.sort(reverse=True)

if n == 0:
    print(x)
elif n == 100:
    if abs(-1 - x) <= abs(101 - x):
        print(-1)
    else:
        print(101)
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:
n,m = [int(i) for i in input().split()]
k = [int(i) for i in input().split()]

k.sort()
minimo = 1e10

if m == 0: print(n)

else:
    for i in range(k[0],k[-1]):
        if not i in k:
            if minimo > abs(n-i): minimo = abs(n-i)
    #print(minimo)
    if n-minimo in k: print(n+minimo)
    else: print(n-minimo)

Submission status: Wrong Answer

Solution code:
def readInt():
    return list(map(int,input().split()))
    
x,n = readInt()
a = []
if n:
    p = readInt()
    p_r = [int(i) for i in range(101) if i not in p]
    # print(p_r)
    for i in p_r:
        dif = abs(x-i)
        a.append(dif)
    # print(a)
    print(p_r[a.index(min(a))])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def do():
    n,m=map(int,input().split())
    l=list(map(int,input().split()))
    k1 = 0
    k2 = 0
    v1 =0
    v2=0
    for i in range(n,0,-1):
        k2+=1
        if i not in l:
            k1=i
            break

    for j in range(n,100+1):
        v2+=1
        if j not in l:
            v1=j
            break
    if k2>v2:
        return v1
    elif k2==v2:
        return min(v1,k1)
    else:
        return k1



print(do())

Submission status: Wrong Answer

Solution code:
X,N=map(int, input().split())
p=list(map(int, input().split()))
seisuu=[0 for i in range(0,101)]
if N==0:
    print(X)
else:
    for i in range(0,N):
        seisuu[p[i]]=1
    count1=X
    count2=X
    ans=0
    if seisuu[X]==0:
        print(X)
    else:
        while True:
            if count1>0 and count2<=100:
                if seisuu[count1]==0:
                    ans=count1
                    break
                elif seisuu[count2]==0:
                    ans=count2
                    break
            else:
                if count1<=0:
                    ans=0
                    break
                elif count2>100:
                    ans=101
                    break
            count1-=1
            count2+=1
        print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  *p,=map(int,input().split())
  INF=10**9-7
  dp = [INF]*(N)

  def near_abs(minp,P):
    d=0
    while True:
      val=minp-d
      if val not in P:
        return val
      val=minp+d
      if val not in P:
        return val
      d+=1

  dp[0]=abs(p[0]-X)
  minp=p[0]
  for i in range(1,N):
    dp[i]=abs(p[i]-X)
    if dp[i]<dp[i-1]:
      minp=p[i]
  print(near_abs(minp,p))

Submission status: Wrong Answer

Solution code:
import re

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

  def dfs1(a):
    match1 = re.findall(f'{a}',p)
    if match1 == []:
      return a
    else:
      return dfs1(str(int(a)-1))

  def dfs2(b):
    match2 = re.findall(f'{b}',p)
    if match2 == []:
      return b
    else:
      return dfs2(str(int(b)+1))

  hiku = int(x)-int(dfs1(x))
  tasu = int(dfs2(x))-int(x)

  if hiku <= tasu:
    print(int(dfs1(x)))
  else:
    print(int(dfs2(x)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007
INF = float('inf')

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x
    
def main():
    x,n = [int(x) for x in stdin.readline().rstrip().split()]
    
    if n == 0:
        print(x)
    else:
        table = [i - 1 for i in range(102)]
        target = INF
        p = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
        for i in range(len(p)):
            table.remove(p[i])
        for i in range(len(table)):
            target = min(target,abs(x-table[i]))
        ans_a = x-int(target)
        ans_b = x+int(target)
        if ans_a in table:
            print(ans_a)
        else:
            print(ans_b)
main()

Submission status: Wrong Answer

Solution code:
import sys

def Forbidden_List():
    X ,N = map(int, input().split())
    
    if N == 0:
        return X
    
    p = list(map(int, input().split()))
        
    if min(p) <= X and X <= max(p):
        other_integer = [i for i in range(min(p)-1, max(p)+2)]
    else:
        return X

    other_integer = set(other_integer) - set(p)

    min_abs = sys.maxsize
    for i in other_integer:
        next_min = abs(i - X)
        #print(next_min, min_abs)
        if next_min < min_abs:
            min_num = i
            min_abs = next_min
        else:
            break
    return min_num

print(Forbidden_List())

Submission status: Wrong Answer

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

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

for i in range(N):
    if X-i not in P:
        ans = X-i
        break
    elif X+i not in P:
        ans = X+i
        break

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  X, N = map(int, input().split())
  if N == 0:
    print(X)
    return
  p = tuple(map(int, input().split()))  
  if X not in p:
    print(X)
  
  not_p = list(set([i for i in range(1,max(p)+2)]) - set(p))
  not_p_X = [abs(i - X) for i in not_p]
  print(not_p[not_p_X.index(min(not_p_X))])
    
main()

Submission status: Wrong Answer

Solution code:
import sys
import math

A = list(map(int, input().split()))
if A[1] > 0:
    num_list = (map(int, input().split()))
else :
    num_list=[]

while True:
    if A[0] in num_list:
       Max_A = A[0] + 1
       Min_A = A[0] - 1
    else:
        print(A[0])
        break

    if Min_A in num_list:
        Min_A = A[0] - 1
    else:
        print(Min_A)
        break


    if Max_A in num_list:
        Max_A = A[0] + 1
    else:
        print(Max_A)
        break

Submission status: Wrong Answer

Solution code:
def resolve():
    X, N = [int(i) for i in input().split()]
    if N == 0:
        print(X)
        return
    p_list = [int(i) for i in input().split()]
    min_len_with_X = 200
    min_len_i = 0
    for i in range(101):
        if i in p_list:
            continue
        if abs(i - X) < min_len_with_X:
            min_len_with_X = abs(i - X)
            min_len_i = i
    print(min_len_i)

resolve()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

Ans = X

for i in range(N // 2 + 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: Wrong Answer

Solution code:
a, b = map(int, input().split())
list2 = set(map(int, input().split()))
list1=list(range(1,101,1))
result = list(set(list1) - set(list2))
for i in range(110):
    if a-i in result:
        print(a-i)
        exit()
    elif a+i in result:
        print(a+i)
        exit()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
not_p = []
if n != 0:
    p = list(map(int, input().split()))
    not_p = [i for i in range(101) if i not in p]
else:
    not_p = [i for i in range(101)]

not_p.sort()
mn = 101
ans = 100
for i in not_p:
    d = abs(x - i)
    if mn > d:
        mn = d
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n ==0:
    print(x)
else:
    p = list(map(int, input().split()))
    q = list(range(101))
    a = 1000
    for i in range(x, 0, -1):
        if p.count(i) == 0:
            a = i
            break

    b = 1000
    for i in range(x, 101):
        if p.count(i) == 0:
            b = i
            break
    if a == 1000:
        print(b)
    elif b == 1000:
        print(a)
    elif abs(x-a) > abs(x-b):
        print(b)
    else:
        print(a)

Submission status: Wrong Answer

Solution code:
x, n = [int(x) for x in input().split()]
if n != 0:
    p = sorted([int(x) for x in input().split()])
    if sorted(p) == list(range(min(p), max(p)+1)):
        tn = p[0]
        tp = p[len(p) - 1]
    else:
        tn = x
        tp = x
    while True:
        if tn in p or tp in p:
            tn -= 1
            tp += 1
            if tn not in p:
                print(tn)
                break
            elif tp not in p:
                print(tp)
                break
else:
    print(x)

Submission status: Wrong Answer

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

while X+i<=200:
    if X+i not in P:
        ans1 = X+i
        break
    i += 1
while X-i>=-100:
    if X-i not in P:
        ans2 = X-i
        break
    i += 1
if ans1-X>=X-ans2:
    print(ans2)
else:
    print(ans1)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().strip().split())
list = []
list1 = []
if n==0:
    print(x)
else:
    dic = {}
    a = input().split()
    for i in range(0, len(a)):
        list.append(int(a[i]))
    for i in range(0, 100):
        b = abs(i - x)
        dic[i] = b
    min1 = min(dic, key=dic.get)
    i = 0
    for i in range(0, 101):
        if (list.__contains__(min1)):
            del dic[min1]
            min1 = min(dic, key=dic.get)
    print(min1)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
answer = 100
for m in range(1,101):
    if not(m in p) and abs(answer-X) > abs(m-X):
        answer = m
print(answer)

Submission status: Wrong Answer

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

def main():
    if len(p) == 0:
        print(x)
        return

    ans_l = list(range(x-10, x+10))
    print(ans_l)

    diff_l = list(set(p) ^ set(ans_l))
    print(diff_l)

    cnt = 100
    ans = 100
    for i in range(0, len(diff_l)):
        check = abs(diff_l[i]-x)
        # print(check)
        if check < cnt:
            cnt = check
            ans = diff_l[i]
    print(ans)
    return

main()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split(' '))
found = False
goal = 0
challenge_plus = X
challenge_minus = X
# そもそもNが0ならXが正解
# Xを基準に大きい方向、小さい方向の両方向へ1づつ数値をずらしていき、
# p_listにヒットしない整数が合ったときに正解となる。
# 同時に大小ヒットした場合は小さいほうが正解

if(N == 0):
  found = True
  goal = X
else:
  p_list = list(map(int, input().split(' ')))
  max_p = max(p_list)
  min_p = min(p_list)
  #print(X,N)
  #print(p_list)
  #print(max_p, min_p)

  for i in range(101):
    tmp_break = False
    challenge_plus += 1
    challenge_minus -= 1
    #print("比較対象は{0}, {1}".format(challenge_plus, challenge_minus))
    if not (challenge_plus in p_list):
      goal = challenge_plus
      found = True
      tmp_break = True
      
    if not(challenge_minus in p_list):
      goal = challenge_minus
      found = True
      break
      
    if(tmp_break):
      break

if(found):
  print(goal)
else:
  challenge_plus += 1
  challenge_minus -= 1
  dist_plus = abs(challenge_plus - X)
  dist_minus = abs(challenge_minus - X)
  if(dist_plus < dist_minus):
    print(challenge_plus)
  else:
    print(challenge_minus)

Submission status: Wrong Answer

Solution code:
import math 
X, N = map(int,input().split())
d = int(999)
d1 = int()
ans = int(999)
if 1 < N:
    P = list(map(int,input().split()))
    for i in range(1,max(P)):
        if P.count(i) == 0:
            d1 = abs(X-i)
            if d1 < d and 0 < d1 :
                d = d1
                ans = i
    print(ans)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  numbers=list(range(102))
  ans=0

  for i in range(len(p)):
    numbers.remove(p[i])

  if numbers.count(X)==1:
    print(X)
  else:
    for j in range(100):
      if numbers.count(X-j)==1:
        ans=X-j
        break
      elif numbers.count(X+j)==1:
        ans=X+j
        break
  print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    _near = 0
    for i in range(101):
        if i in p:
            continue
        if abs(abs(_near)) - x > abs(abs(i)-x):
            _near = i
    print(_near)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

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

allList=[]

for i in range(-200,301):
    allList.append(i)

diff = set(allList) ^ set(p)



diff = list(diff)
diff.append(x)
diff = sorted(diff)

# print(diff)

ind = diff.index(x)
# print(ind)

# if x == 100:
    

a = diff[ind-1]
b = diff[ind+1]

ax = abs(a-x)
bx = abs(b-x)

# print(ax,bx)

if ax==bx:
    if a < b:
        print(a)
    else:
        print(b)

if ax > bx:
    print(b)
    exit()

Submission status: Wrong Answer

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

if y != 0 and x not in p: 
    l_num = x - 1
    r_num = x + 1 
    while l_num < x and r_num > x:
      if l_num not in p and r_num not in p:
        print(l_num)
        break
      elif l_num not in p:
        print(l_num)
        break
      elif r_num not in p:
        print(r_num)
        break
      l_num -= 1
      r_num += 1
else:
    print(x)

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

def solve():
    i = 1
    if N == 0:
        print(X)
        return
    if not X in p:
        print(X)
        return
    while i < 10:
        if not X-i in p:
            print(X-i)
            return
        if not X+i in p:
            print(X+i)
            return
        i += 1

solve()

Submission status: Wrong Answer

Solution code:
str1 = input()
str2 = input()

A = str1.split(" ")
B = str2

res = 0
#print(A[1])
if A[1] == "0":
    res = A[0]
else:
#    print("A[1]!=0")
    B = B.split(" ")
    intB = []
    for i in B:
        intB.append(int(i))
    intB.sort(reverse=True)

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

    res = 0
    diff = 999999

    # 1~100の配列を作る
    l = list(range(1, 101))

#    print(intB)
    # 入力内容を削る
    for i in range(0, N):
        l.pop(intB[i]-1)

#    print(l)
    for i in l:
        if 0 == abs(X - int(i)):
            diff = 0
            res = i
            break
        elif diff > abs(X - int(i)):
            diff = abs(X - int(i))
            res = i
#            print(diff, res)


print(res)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    a = x - 1
    b = x + 1
    if a not in p and b not in p:
        if a > b:
            print(b)
        else:
            print(a)
    elif a not in p and b in p:
        print(a)
    elif a in p and b not in p:
        print(b)
    else:
        while a in p or b in p:
            if a not in p:
                c = abs(a - x)
            else:
                c = 0
            if b not in p:
                d = abs(b -x)
            else:
                d = 0
            if c != 0 and d == 0:
                print(a)
                quit()
            elif c == 0 and d != 0:
                print(b)
                quit()
            elif c != 0 and d != 0:
                print(a)
                quit()
            else:
                a -= 1
                b += 1

Submission status: Wrong Answer

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

int_list = [i for i in range(101)]
forbidden_list = list(set(int_list) - set(p))
num_X = int_list.index(X)
c = 10000000

if X in forbidden_list:
  print(X)
elif X == 0:
  print(-1)
else:
  for i in range(len(forbidden_list) - 1):
    a = abs(X - forbidden_list[i])
    b = abs(X - forbidden_list[i + 1])
    if a == b:
      print(forbidden_list[i])
      break
    elif c > a:
      c = a
    elif c <= a and b > a:
      print(forbidden_list[i - 1])
      break
    else:
      print(forbidden_list[i])
      break

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
q = set(range(-1,101))
q = q - set(p)
q_list = list(q)
ans = 100
d = 100
for i in range(102-n):
   if d != min(d,abs(x - q_list[i])):
       ans = q_list[i]
       d = abs(x - q_list[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
x,n = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
li = []
ans = []
Min_sa = 9999999999
for i in range(-100,101):
    if i not in p:
        li.append(i)
for i in li:
     Min_sa = min(Min_sa,abs(x-i))
for i in li:
    if abs(x-i) == Min_sa:
        ans.append(i)
print(min(ans))

Submission status: Wrong Answer

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

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

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


flag_p = True
flag_n = True

abs_num = 0
abs_num_p = X + 1
abs_num_n = X - 1
while True:

    if abs_num_p in P:
        flag_p = True
    else:
        flag_p = False

    if abs_num_n in P:
        flag_n = True
    else:
        flag_n = False

    if(flag_p == True & flag_n == True):
        abs_num_p += 1
        abs_num_n -= 1
        continue;
    elif(flag_n == True & flag_p == False):
        print(abs_num_p)
        break;
    elif(flag_n == False):
        print(abs_num_n)
        break;
    abs_num_p += 1
    abs_num_n -= 1

Submission status: Wrong Answer

Solution code:
a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 1
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) in number_list:
        print(num2)
      else:
        print(num)
      break
    n += 1

Submission status: Wrong Answer

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

#pset = set([abs(X-p) for p in ps])
#print(pset)

for i in range(50):
  if X-i not in ps:
    print(X-i)
    break
  elif X+i not in ps:
    print(X+i)
    break

Submission status: Wrong Answer

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

    a = [i for i in range(101)]
    for i in range(n):
        a[p[i]] = 1000
    minimum = 1000
    result = 1000
    if n == 100:
        result = min(abs(101-x),abs(x))
    else:
        for i in reversed(range(1,101)):
            if a[i] != 1000:
                if minimum >= abs(x - a[i]):
                    minimum = abs(x - a[i])
                    result = a[i]

    print(result)

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
P = list(map(int, input().split()))
maxP = 0 if P == [] else max(P)
le = 1000
for k in reversed(range(X+1)):
  if k not in P:
    le = X-k
    ans = k
    break
for k in range(X,maxP+1):
  if k not in P:
    if le > k-X:
      ans = k
      break
print(ans)