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())
p_list = list(map(int, input().split()))

p_list = sorted(p_list)
all_range = list(range(101))
A = [i for i in all_range if i not in p_list]
B = [abs(i - X) for i in A]

low = X - min(B)
high = X + min(B)

if high not in all_range:
  high = low

if low not in all_range:
  low = high

if N == 0:
  print(X)
elif high in p_list:
  print(low)
elif low in p_list:
  print(high)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if not N:
    print(X)
    exit()
p = list(map(int, input().split()))
if X not in p:
    print(X)
    exit()
    
p_low = sorted([X - i for i in p if i < X])
p_high = sorted([i - X for i in p if i > X])

if len(p_low) > len(p_high):
    lng = len(p_low)
else:
    lng = len(p_high)

for i in range(1, lng + 1):
    if i not in p_low:
        print(X - i)
        exit()
    elif i not in p_high:
        print(X + i)
        exit()

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
q = set(range(0,101))
q = q - set(p)
q_list = list(q)
ans = 100
d = 100
for i in range(101-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:
x, n = map(int, input().split())

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

p.sort()

if x <= 50:
    minp = abs(-1 - x)
    minv = -1
else:
    minp = abs(101 - x)
    minv = 101
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:
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    p = list(map(int,input().split()))

    num1 = x

    for i in range(n):
        num1 += 1
        if num1 not in p:
            dif1 = num1- x
            break

    num2 = x
    for k in range(n):
        num2 -= 1
        if num2 not in p:
            dif2 = x - num2
            break

    if dif1 > dif2:
        print(num2)
    elif dif1 < dif2:
        print(num1)
    elif dif1 == dif2:
        print(num2)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
nlist=list(map(int,input().split()))
Nlist=[]
if n==0:
    print(x)
    exit(0)
elif x not in nlist:
    print(x)
    exit(0)

for i in range(-x,100):
    if i not in nlist:
        Nlist.append(i)
abslist=[abs(x-i) for i in Nlist]
#print(abslist)
if x-min(abslist)  not in nlist:
    print(x-min(abslist))
else:
    print(x+min(abslist))

Submission status: Wrong Answer

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

if n != 0:
  p = list(map(int, input().split()))
  q = []
  for i in range(101):
    if i in p:
      q.append(150)
    else:
      q.append(abs(i-x))
  list_indexMin = [i for i, v in enumerate(q) if v == min(q)]
  print(min(list_indexMin))
else:
  print(x)

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 = 100
    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:
x, n = map(int, input().split())
p = list(map(int, input().split()))
sa = float("inf")
for i in range(1, 110):
    if i not in p:
        sa = min(sa, abs(i - x))
if x - sa not in p and x + sa not in p:
    print(x - sa)
elif x - sa in p and x + sa not in p:
    print(x + sa)
elif x - sa not in p and x + sa in p:
    print(x - sa)

Submission status: Wrong Answer

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

if N ==0:
    print(X)
    s = input()
else:
      n = input().split()
      n = [int(s) for s in n]
      for i in range(1,N+1):
        if X -i not in n:
            print(X-i)
            break
        elif X + i not in n:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
import sys

a, b = map(int,input().split())
if b == 0:
  print(a)
  sys.exit()
l = set(range(1, 101))
lst = set(map(int,input().split()))



ans = 0
diff = float("Inf")
s = l - lst

for i in s:
  if abs(a - i) == 0:
    ans = i
    break
  if diff > abs(a - i):
    ans = i
    diff = abs(a - 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()))
p.sort()

ans = x
tmp = 1001001001
for i in range(p[0]-1, p[-1]+1):
    if i in p: continue
    if abs(x-i) < tmp:
        tmp = abs(x-i)
        ans = i

print(ans)

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

if len(num) == 0:
    print(X)
else:
    for i in range(X-1, 0, -1):
        if i not in num:
            val1 = i
            break

    for j in range(X+1, 101):
        if j not in num:
            val2 = j
            break

    if abs(val1-X) <= abs(val2-X):
        print(val1)
    else:
        print(val2)

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:
a, b = map(int, input().split())
list2 = set(map(int, input().split()))
list1=list(range(101))
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:
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):
            _near = i
    print(_near)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

if n != 0:
  p = list(map(int, input().split()))
  q = []
  for i in range(101):
    if i in p:
      q.append(150)
    else:
      q.append(abs(i-x))
  list_indexMin = [i for i, v in enumerate(q) if v == min(q)]
  print(q)
  print(min(list_indexMin))
else:
  print(x)

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(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 bisect
import numpy as np

X, N = map(int, input().split())
p_array = np.array(list(map(int, input().split())))

if N ==0:
    print(X)

else:
    p_array = sorted(p_array)

    left = bisect.bisect_left(p_array, X) - 1
    right = left + 2

    i = left
    left_answer = X - 1
    while True:
        if i <= 0:
            left_answer -= 1
            break

        if p_array[i] == left_answer:
            i -= 1
            left_answer -= 1
        else:
            break

    j = right
    right_answer = X + 1
    while True:
        if j >= N:
            right_answer += 1
            break

        if p_array[j] == right_answer:
            j += 1
            right_answer += 1
        else:
            break

    if X - left_answer <= right_answer - X:
        print(left_answer)
    else:
        print(right_answer)

Submission status: Wrong Answer

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

for i in range(100):
  if i%2==1:
    s = x-((i+1)/2)
    #print(s,"こ")
  else:
    s = x+(i/2)
    #print(s,"ここ")
  if s not in p:
    print(int(s))
    break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
sa = float("inf")
for i in range(1, 102):
    if i not in p:
        sa = min(sa, abs(i - x))
if x - sa not in p and x + sa not in p:
    print(x - sa)
elif x - sa in p and x + sa not in p:
    print(x + sa)
elif x - sa not in p and x + sa in p:
    print(x - sa)

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()
if n == 100:
    if x <= 50:
        print(0)
    else:
        print(101)


nun_list = list(map(int, input().split()))
answer = 0

for i in range(0, 210):
    if nun_list.__contains__(i):
        continue
    else :
        if abs(x - answer) >= abs(x - i):
            if abs(x - answer) == abs(x - i):
                if answer > i:
                    answer = i
            else:
                answer = i
if abs(x - answer) <= abs(x - 0):
    print(answer)
else :
    print(0)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
  quit()
lst=list(map(int,input().split()))
a=list(range(101))
for i in lst:
  if i in a:
    a.remove(i)
if len(a)==0:
  print(x)
  quit()
b=[]
for j in a:
  b.append(abs(j-x))
print(a[b.index(min(b))])

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    X, N = list(map(int, input().split()))
    p = list(map(int, input().split()))
    q = p
    for i in range(N):
        q[i] = abs(X-p[i])
    
    if q.count(0) == 0:
        print(X)
    else:
        j = 1
        while True:
            if q.count(j) != 2:
                if q.count(j) == 0:
                    print(X - j)
                else:
                    if X - j < 1:
                        print(X - j)
                    elif X - j in p:
                        print(X + j)
                    else:
                        print(X - j)
                break
            j += 1

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()))
        
    other_integer = [i for i in range(min(p)-1, max(p)+2)]

    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(' '))
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)
  challenges = {dist_plus: challenge_plus, dist_minus: challenge_minus}
  print(challenges[min((dist_plus, dist_minus))])

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N > 0:
    P = list(map(int, input().split()))
    res = float('Inf')
    A = [0]*100
    for n in range(N):
        A[P[n]-1] += 1
    cnt = 1
    man = float('Inf')
    for a in A:
        if a == 0:
            total = abs(X - cnt)
            if res > total:
                res = total
                man = cnt
        cnt += 1
    if X == 100 and N == 100:
        man = 101
    print(man)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
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:
x,n = map(int, input().split())

ans=0
min_ans=200
t=0

if n==0:
    print(x)
elif n==100:
    print(0)
else:
    p= list(map(int,input().split()))
    for i in range(102):
        if p.count(i)==0:
            ans=abs(x-i)
            if ans<min_ans:
                min_ans=ans
                t=i
        else:
            continue

    print(t)

Submission status: Wrong Answer

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

if N == 0:
    print(X)
    
else:
    for i in range(110):
        if (X-(i+1)) and (X+i+1) in p:
            continue
    
        else:
            if(X-i-1) not in p:
                print(X-i-1)
                break
    
            elif (X+i+1) not in p:
                print(X+i+1)
                break

Submission status: Wrong Answer

Solution code:
X, N = list(map(int, input().split()))
if N > 0:
    P = list(map(int, input().split()))
    L = X - 1
    H = X + 1
    while True:
        if L not in P:
            print(L)
            break
        if H not in P:
            print(H)
            break
        L -= 1
        H += 1
else:
    input()
    print(X)

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 = set(range(1,101)) - p
    if min(lst) >= X:
        print(min(lst))
        exit()
    if max (lst) <= X:
        print(max(lst))
        exit()
    tmp = 130
    prev = 0
    for s in lst:
        if abs(s - X) >= tmp:
            print(prev)
            exit()
        prev = s
        tmp = abs(s - X)
    print(max(lst))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(1, 101):
    if N == 0:
        print(X)
        break
    elif p.count(X-i) == 0:
        print(abs(X-i))
        break
    elif p.count(X+i) == 0:
        print(abs(X+i))
        break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
num, i = map(int, input().split())
if(i != 0):
  s = set(map(int, input().split()))
else:
  s = set()
m = set(range(101))
o = list(m-s)
o2 = list(map(lambda x: abs(x - num), o))
print(o[o2.index(min(o2))])

Submission status: Wrong Answer

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

    min_num = sorted_p[0]
    max_num = sorted_p[-1]

    candidate_list = []
    no_flag = 0
    candidate_num = -1
    distance = 10000

    for cnt in range(min_num + 1, max_num):
        no_flag = 0
        for nums in range(n):
            if cnt == sorted_p[nums]:
                no_flag = 1

        if no_flag == 0:
            candidate_list.append(cnt)
    
    if len(candidate_list) == 0:
        print(x)
    else:
        for cnt in range(len(candidate_list)):
            if abs(x - candidate_list[cnt]) < distance:
                candidate_num = candidate_list[cnt]
                distance = abs(x - candidate_num)

        print(candidate_num)

else:
    print(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

p = [int(i) for i in input().split()] if N > 0 else [-10**9]

p = sorted(p, key=lambda x: x)

minDistance = 10**9
minNum = -10**9
for i in range(min(p), max(p)+1, 1):
  if (i not in p) and minDistance > abs(X - i) and i != X:
     minNum = i 
     minDistance = abs(X - i)

print(minNum if minNum > -10**9 else X )

Submission status: Wrong Answer

Solution code:
import numpy as np
x, n = map(int, input().split())
if n==0:
  print(x)
else:
  P = np.array(list(map(int, input().split())))
  Q = P - x
  W = [abs(i) for i in Q]
  W.sort()
  print(W[0])

Submission status: Wrong Answer

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

  for i in range(n):
    plus = (x+i)  in li
    minus = (x-i)  in li
  
    if plus == 1 and minus == 1:
      pass  
    elif plus == 1 and minus == 0:
      print(x-i)
      break
    elif plus == 0 and minus == 1:
      print(x+i)
      break
    else:
      print(x-i)
      break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
p = list(map(int, input().split()))
unique = set(range(-100, 101)) - set(p)
ans = {}
ans2 = []
for i in unique:
  calc = abs(x-i)
  if calc in ans.keys():
    ans[calc] = min(ans[calc], i)
  else:
    ans[calc] = i
  ans2.append(calc)
print(ans[min(ans2)])

Submission status: Wrong Answer

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

try:
    mx = max(P)
    li = []

    for i in range(1, mx + 1):
        if i not in P:
            li.append(i)

    li1 = []
    for j in li:
        ans = abs(j - X)
        li1.append(ans)
    indx = li1.index(min(li1))
    f = li[indx]
    print(f)
    
except:
    print(X)

Submission status: Wrong Answer

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

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

p.sort()

if x <= 50:
    minp = abs(-1 - x)
    minv = -1
else:
    minp = abs(101 - x)
    minv = 101
if 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:
# x,n = map(int, input().split())
x,n = map(int, "100 0".split())
# line = list(map(int, input().split()))
line = list(map(int, "".split()))

plus = x
minus = x

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

while True:

    if plus <= 100:
        plus += 1

    if minus >= 0:
        minus -=1


    if not minus in line:
        print(minus)
        exit()

    if not plus in line:
        print(plus)
        exit()

    if plus > 100 and minus < 0:
      exit()

Submission status: Wrong Answer

Solution code:
data = input().split()
x = int(data[0])
n = int(data[1])

p = input().split()
for i in range(n):
	p[i] = int(p[i])

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

for i in range(101)[1:]:
	if not (x-i) in p:
		print(x-i)
		exit()
	elif not (x+i) in p:
		print(x+i)
		exit()

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
if not a[1] ==0:
  b = list(map(int,input().split()))
  b2 = sorted(b)##小さい順に並べる
  if abs(a[0]-b2[0]) <= abs(a[0]-b2[a[1]-1]):#bがすべて連続の場合の対策
    c = b2[0]-a[0]
  else:
    c = b2[a[1]-1]-a[0] 
  if a[0] < b2[0]:
    print(a[0])
  elif a[0] > b2[a[1]-1]:
    print(a[0])
  else:
    for i in range(a[1]-1):
      if abs(b2[i+1]-b[i])>1:
        for j in range(b2[i+1]-b2[i]-1):##差分が1より大きい場合ソート
          if abs(c) > abs(b2[i]-a[0]+j+1):
            c = b2[i]-a[0]+j+1
    print(c+a[0])
else:
  print(a[0])

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 = 0
    for i in range(x, 0, -1):
        if p.count(i) == 0:
            a = i
            break

    b = 0
    for i in range(x, 101):
        if p.count(i) == 0:
            b = i
            break

    if 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())
p_list = list(map(int, input().split()))

ans = 0

max_ = 0
min_ = 0

# 増える側
for i in range(x, 100, 1) :

    # print('i+')
    # print(i)

    if i not in p_list:
        # print('確定')
        max_ = i
        break

# 減る側
for j in reversed(range(x + 1)) :

    # print('j-')
    # print(j)

    if j not in p_list:
        # print('確定')
        min_ = j
        break

# print('min')
# print(min_)
# print('max')
# print(max_)

if 0 in p_list and min_ == 0 :
    ans = max_
else :   

    if abs (min_ - x) <= abs(max_ - x) :
        ans = min_
    else : 
        ans = max_

print(ans)

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)
    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())
ps = list(map(int,input().split()))
mtmp = x
ptmp = x
rt = True
r = []
if len(ps) == 0:
  print(x)
else:
  while True:
    if mtmp+1 not in ps:
      r.append(mtmp+1)
      rt = False
    if ptmp-1 not in ps:
      r.append(ptmp-1)
      rt = False
    mtmp = mtmp+1
    ptmp = ptmp-1
    if rt:
      continue
    else:
      break
  print(min(r))

Submission status: Wrong Answer

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

for i in range(1, 101):
    if N == 0:
        print(X)
        break
    elif p.count(X-i) == 0:
        print(abs(X-1))
        break
    elif p.count(X+i) == 0:
        print(abs(X+i))
        break

Submission status: Wrong Answer

Solution code:
import math

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

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

p.sort()

minimum = p[0]
maximum = p[len(p) - 1]
# print(minimum, maximum)

if X < minimum or maximum < X:
    print(X)
    exit()

# answer = min(abs(X - minimum - 1), abs(X - maximum + 1))
answer = 9999
for candidate in range(minimum, maximum):
    if candidate in p: continue

    diff_answer = abs(X - answer)
    diff_candidate = abs(X - candidate)
    # print(candidate, diff, answer)
    answer = candidate if diff_candidate < diff_answer else answer

print(answer)

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(-100,201):
    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:
#C
import numpy as np
x, n = map(int, input().split())

if n!=0:
    p_list = list(map(int, input().split()))
    
    if n%2==0:
        kouho = list(range((x-n//2-1),(x+n//2)))
    else:
        kouho = list(range((x-n//2-1),(x+n//2+1)))
        
    kouho2 = set(kouho) - set(p_list)
    ans = [j for i, j in enumerate(list(kouho2)) if abs(j-x) == min(abs(np.array(list(kouho2)) - x))]
    ans = min(ans)

else:
    ans = x

print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
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
  print(ans_y)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
num1 = []
num1 = input().split(" ")
ans=int(num1[0])
count=int(num1[1])
#print(count)

if count != 0 and count != 1:
    num2 = []
    num2 = input().split(" ")
#print(num2)

    num3 = []
    for i in range(count):
        num3.append(int(num2[i]))
    num3.sort()
#print(num3)
#print(ans)
    up=1
    down=1
    for i in range(count//2+2):
        if up == 1 and down == 1:
            num_up=ans+i
            num_down=ans-i
            up=0
            down=0
        elif up ==1:
            print(num_down)
            break
        elif down == 1:
            print(num_up)
            break
        else:
            print(num_down)
            break
        
        for k in range(count):
            if num_up == num3[k]:
                up=1
            #print("up")
            if num_down == num3[k]:
                down=1
                #print("down")
elif count ==0:
    print(ans)
elif count ==1:
    num2=int(input())
    #print(num2)
    if ans == num2:
        print(num2-1)
    else:
        print(ans)

Submission status: Wrong Answer

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

num = []
for i in range(102):
    num.append(i)
for j in range(n):
    num.remove(p[j])

a = 1000000000000
b = 0
for k in range(102-n):
    if(abs(x-num[k]) < a):
        a = abs(x-num[k])
        b = num[k]

print(b)

print(num)

Submission status: Wrong Answer

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

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

min = 100
min_i = x
douti = 0

for i in range(102):
    z = abs(x-(i-1))
    if z < min:

        for j in range(n):
            if i-1 == p[j]:
                douti = 1

        if douti != 1:
            min = z
            min_i = i-1
    douti = 0


print(min_i)

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)
elif X==100:
    print(X)
else:
    for i in range(0,N):
        seisuu[p[i]]=1
    count1=X-1
    count2=X+1
    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:
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 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])