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())
A = list(map(int, input().split()))
if N == 0:
    print(X)
else:
    if N == 1:
        if A[0] != X:
            print(X)
        else:
            print(X-1)
    else:
        B = []
        for i in range(N):
            B.append(abs(X-A[i]))
        B.sort()
        t = 0
        for i in range(N-1):
            if (i+1)//2 != B[i]:
                break
            else:
                t = t+1
        if t == N:
            if N%2 == 1:
                print(X-(N+1)//2)
            else:
                k = 0
                for i in range(N):
                    if A[i] == X-(N//2):
                        k = k+1
                if k == 0:
                    print(X-(N//2))
                else:
                    print(X+(N//2))
        else:
            if t%2 == 1:
                print(X-(t+1)//2)
            else:
                k = 0
                for i in range(N):
                    if A[i] == X-(t//2):
                        k = k+1
                if k == 0:
                    print(X-(t//2))
                else:
                    print(X+(t//2))

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(100):
    if a-i in result:
        print(a-i)
        exit()
    elif a+i in result:
        print(a+i)
        exit()

Submission status: Wrong Answer

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

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

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

else:
  P = list(map(int,input().split()))

  P_set = list(set(P))
  #print(P_set)
  #print(P_set[1])
  
  ans_chk = 0
  
  if ( X < P_set[0] or X > P_set[N-1] ):
    print(X)
    ans_chk = 1
  
  if ( ans_chk==0 ):
    for i in range(len(P)):
      if ( P_set[i] == X ):
        X_i = i
        break
      elif ( P_set[i] > X ):
        print(X)
        ans_chk = 1
        break
  
  if ( ans_chk==0 ):
    
    if ( X_i >= N-(X_i+1) ): # 上の数が少ない → 下は1回多くする
      M = N-(X_i+1)
      temp_ans = X + N-(X_i+1) +1
      #print("temp_ans =",temp_ans)
      
      for i in range(1,M+1):
        if ( P_set[ X_i -i ] != X-i ):
          print(X-i)
          ans_chk = 1
          break
        elif ( P_set[ X_i +i ] != X+i ):
          print(X+i)
          ans_chk = 1
          break
      
      if ( ans_chk==0 ):
        if ( P_set[ X_i -(M+1) ] != X-(M+1) ):
          print( X-(M+1) )
          ans_chk = 1
  
  
    else: # 下の数が少ない → そのまま
      M = X_i
      temp_ans = X - X_i -1
      #print("temp_ans =",temp_ans)
    
      for i in range(1,M+1):
        print(i)
        if ( P_set[ X_i -i ] != X-i ):
          print(X-i)
          ans_chk = 1
          break
        elif ( P_set[ X_i +i ] != X+i ):
          print(X+i)
          ans_chk = 1
          break
  
  if ( ans_chk==0 ):
    print(temp_ans)

Submission status: Wrong Answer

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

  if x<a[0]:
    print(x)
  elif x>a[-1]:
    print(x)
  else:
    b=list(range((a[0]),(a[-1]+1)))

    for n in range(n):
      b.remove(a[n])
  
    f=len(b)


    d=abs(x-int(b[0]))
    ans=b[0]

    for n in range(f):
      c=abs(x-int(b[n]))
      if d>c:
        ans=b[n]
        d=c
  
    print(ans)


except:
  print(x)

Submission status: Wrong Answer

Solution code:
def linked_merge_sort(l): #マージソート
    if len(l) == 1:
        return
    q, r = divmod(len(l), 2)
    left = [l.pop() for _ in range(q)]
    right = [l.pop() for _ in range(q + r)]
    
    linked_merge_sort(left)
    linked_merge_sort(right)
    
    left.reverse()
    right.reverse()
    while left and right:
        if left[-1] <= right[-1]:
            l.append(left.pop())
        else:
            l.append(right.pop())
    while left:
        l.append(left.pop())
    while right:
        l.append(right.pop())
    return

x,n=map(int,input().split())
p=list(map(int,input().split()))
if x>50:
    ans = 100
else:
    ans = 0
for i in range(n):
    p[i]=p[i]-x
if n>1:
    linked_merge_sort(p)
    j=n-1
    for i in range(n):
        if p[i]>=0:
            j=i
            break
    for i in range(50):
        if j-i>=0:
            if p[j-i]!=-i:
                ans = x-i
                break
        elif j-i<0:
            ans=x+p[0]-1
            break
        if j+i<n:
            if p[j+i]!=i:
                ans = x+i
                break
        else:
            ans=x+p[n-1]+1
            break
elif n==1:
    if p[0]==0:
        ans=x-1
    else:
        ans=x
elif n==0:
    ans=x
print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
q = set(range(-2,101))
q = q - set(p)
q_list = list(q)
ans = 100
d = 100
for i in range(100-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())
if n > 0:
    P = list(map(int, input().split()))
    Q = sorted(
        [[i, abs(i - x)] for i in range(-100, 101) if i not in P],
        key=lambda x:x[1])
    dist = Q[0][1]
    print(min([q[0] for q in Q if q[1] == dist]))
else:
    print(x)

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:
import numpy as np
X,N = map(int, input().split())
p = list(map(int, input().split()))
p = sorted(p)
lista = list(range(101))
for i in p:
    if i in lista:
        lista.remove(i)
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    print(list[idx])
getNearestValue(lista, X)

Submission status: Wrong Answer

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

if n ==0:
    print(x)
else:
    for j in range(50):
        ll = []
        if x-j in l:
            if not x-j in p:
                ll.append(x-j)
        if len(ll) != 0:
            print(min(ll))
            break
        if x+j in l:
            if not x+j in p:
                ll.append(x+j)
        if len(ll) != 0:
            print(min(ll))
            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))
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)
else:
    li = list(map(int,input().split()))
    for i in range(1, 101):
        up = x + i
        down = x - i
        if down not in li:
            print(down)
            break
        elif up not in li:
            print(up)
            break

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 X not in p:
    print(X)
    
  else:
    n = [x for x in range(101)]

    for i in p:
      n.remove(i)
    ans = 0  
    a = 101
    b = -1
    for j in n:
      b += 1
    
      if abs(j-X) < a:
        a=abs(j-X)
        ans = n[b]
  
    print(ans)

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(num2)

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: 
    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:
x,n = map(int,input().split())
p = list(map(int,input().split()))
q = set(range(-2,101))
q = q - set(p)
q_list = list(q)
ans = 1000
d = 1000
for i in range(100-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())
if N == 0:
    print(X)
    exit()
P = list(map(int, input(). split()))

for n in range(1, N + 1):
    if not (X - n) in P:
        print(X - n)
        exit()
    if not (X + n) in P:
        print(X + n)
        exit()
print(min(P) - 1)

Submission status: Wrong Answer

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

if N == 0:
    print(X)
else:
    for i in range(1,100):
        if i not in P:
            differ.append(abs(X - i))
        else:
            differ.append(1000)
    
    ans = differ.index(min(differ))
    print(ans+1)

Submission status: Wrong Answer

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

lis = [1] * (100+1)
for p in P: lis[p-1] -= 1

for i in range(100+1):
    up = X+i
    down = X-i
    if lis[down-1] == 1 and down >= 0 :
        if abs(X-1) < abs(X-down):
            print(-1)
            exit()
        print(down)
        exit()

    elif lis[up-1] == 1 and up <= 100:
        if abs(X-1) < abs(X-up):
            print(-1)
            exit()
        print(up)
        exit()

Submission status: Wrong Answer

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

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

a = [i for i in range(-100,201)]

for j in p:
    d = a.index(j)
    a.pop(d)

if (x in a):
    pass
else:
    a.append(x)
    a.sort()

idx_x = a.index(x)

if (idx_x == 0):
    print(a[idx_x+1])
    sys.exit()
if (idx_x == len(a)-1):
    print(a[-2])

lesser = a[idx_x-1]
greater = a[idx_x+1]

dl = x - lesser
dg = greater - x

if (dl <= dg):
    print(lesser)
else:
    print(greater)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
X2=X
c=0
d=0
b=0
for i in range(1000):
    if X+i not in P and X+i <= 200 :
        c=X+i
    if X-i not in P and X-i >= -100: 
        d=X-i
    if c!=0:
        if d!=0:
            print(d)
        else:
            print(c)
        break
    if d!=0:
        print(d)
        break

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)

    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:

def main():
	x,n=map(int,input().split())
	p=[]
	try:
		p=list(map(int,input().split()))
	except:
		print(str(x))
		return
	p=set(p)
	ans=0
	ansc=x
	for i in range(1,101):
		if not(i in p):
			a=min(abs(x-i),ansc)
			if(a!=ansc):
				ans=i
				ansc=a
	print(ans)
main()

Submission status: Wrong Answer

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

if N == 0:
    print(X)
else:
    for i in range(1,100):
        if i not in P:
            differ.append(abs(X - i))
        else:
            differ.append(1000)
    
    ans = differ.index(min(differ))

    print(differ)
    print(ans+1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(X: int, N: int, p: "List[int]"):
    ii = [i for i in range(-101,101)]
    iii = sorted(list(set(ii) - set(p)))
    idx = np.abs(np.asarray(iii) - X).argmin()
    print(iii[idx])
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if y != 0: 
    p = [int(x) for x in input().split()] 
    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:
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_p == True & flag_n == False):
        print(abs_num_n)
        break;
    elif(flag_p == False):
        print(abs_num_p)
        break;
    abs_num_p += 1
    abs_num_n -= 1

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 in p and X - j >= 1:
                        print(X + j)
                    else:
                        print(X - j)
                break
            j += 1

Submission status: Wrong Answer

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

list_a = []
for a in range(-101,101):
    if a not in p:
        list_a.append(abs(X-a))

m = X - min(list_a)
l = X + min(list_a)
if m not in p:
    print(m)
else:
    print(l)

Submission status: Wrong Answer

Solution code:
x, n = [int(s) for s in input().split(" ")]
if n == 0:
  print(x)
else:
  plist = [int(s) for s in input().split(" ")]

  dlist = {}
  for p in plist:
    d = abs(p - x)
    if d in dlist or d == 0:
      dlist[d] = (True, None)
    else:
      dlist[d] = (False, p - x)

  sorted_d = sorted(dlist.items(), key=lambda x:x[0])

  ans = 0
  prevk = 0
  flag = False
  for k, v in sorted_d:
    if not flag and prevk == 0 and k >= 1:
      ans = 0
      break
    elif v[0] and k - prevk > 1:
      ans = -(prevk + 1)
      break
    elif not v[0]:
      ans = min(-v[1], v[1])
      break
    flag = True
    prevk = k
    ans = -(k + 1)
  print(x + ans)

Submission status: Wrong Answer

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

mina =101
y = []
minb = 101

for i in range(1,101):
    y.append(i)

if n == 0:
    print(x)
else:
    for j in range(n):
        y.remove(p[j])
    
    for k in range(1,101-n):
        
        if abs(x - y[k-1]) < mina:
            mina = abs(x - y[k-1])
            minb = y[k-1]
    
    print(minb)

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(' ')))

    chk_x = False
    pmax = 0
    pmin = 101
    for pr in p:
        if pmax < pr:
            pmax = pr
        if pmin > pr:
            pmin = pr
        if pr == x:
            chk_x = True

    all_i = list(range(0,102))
    target_i = list(set(all_i)^set(p))

    minsub = abs(target_i[0] - x)
    ans = -1
    for i in target_i:
        if abs(i-x) < minsub:
            minsub = abs(i-x)
            ans = i
    # Xがこの範囲にないが最小だった場合
    if not chk_x:
        print(x)
    else:
        print (ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
xp=[]
xm=[]
if n==0:
    print(x)
else:
    for i in range(1,1000):
        xp.append(x+i)
        xm.append(x-i)
        if len(set(p)-set(xm))==5:
            print(x-i)
            exit()
        elif len(set(p)-set(xp))==5:
            print(x+i)
            exit()
        else:
            xp.pop(0)
            xm.pop(0)

Submission status: Wrong Answer

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

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

d = [0 for _ in range(-1000, 1001)]
for i in range(-1000, 1001):
    d[i] = i+1 

for i in p:
    d.remove(i)

d2 = [0 for _ in range(len(d))]
for i in range(len(d)):
    d2[i] = abs(d[i]-x)

m = 10000
for i in range(len(d2)):
    if d2[i] < m:
        m = d2[i]
        tmpi = i 

print(d[tmpi])

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
print(answer)

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:
    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:
x,n = list(map(int,input().split()))
if n >0 :
  p = list(map(int,input().split()))
#print(x,n)
#print(p)
#print(max(p))
y = 101
ans = x
if n == 0:
  print(x)
else:
  for i in range(0,101):
    if i != x:
      if p.count(i) == 0:
        #print('i=',i,abs(x-i))
        if abs(x-i) < y:
          ans = i
          y = abs(x-i)
  print(ans)

Submission status: Wrong Answer

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

result = X
if p:
    if X not in p:
        result = X
    else:
        for i in range(1, len(p)):
            if X - i not in p:
                result = X - i
                break
            elif X + i not in p:
                result = X + i
                break
    print(result)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split(" "))
if(n==0):
    print(x)
else:
    a=list(map(int,input().split(" ")))
    if(x not in a):
        print(x)
    else:
        a.sort()
        c=a.index(x)
        for i in range(1,n):
            if(c-i<0):
                print(x-i)
                break
            else:
                if(a[c-i]!=x-i):
                    print(x-i)
                    break
                if(c+i==n):
                    print(x+i)
                    break
                else:
                    if(a[c+i]!=x+i):
                        print(x+i)
                        break

Submission status: Wrong Answer

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

def minusx(f):
    return f-x

if n !=0:
    plist =list(map(int,input().split(" ")))
    for i in range(100):
        if x-i >=1 and x-i <=100 and x-i not in plist:
            print(x-i)
            break
        elif x+i >=1 and x+i <=100 and x+i not in plist:
            print(x+i)
            break
else:
    print(x)

Submission status: Wrong Answer

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

if n == 0:
    print(x)

else:
    i = 1
    while True:
        t = x-i
        s = x+i
        if t not in p:
            print(t)
            break
        if s not in p:
            print(s)
            break
        i +=1

Submission status: Wrong Answer

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

for n in range(1, N + 1):
    mi = X - n
    if mi < 0:
        continue

    ma = X + n
    if ma > 100:
        continue

    if not (X - n) in P:
        print(X - n)
        exit()
    if not (X + n) in P:
        print(X + n)
        exit()
if min(P) - 1 < 0:
    print(max(P) + 1)
    exit()
print(min(P) - 1)

Submission status: Wrong Answer

Solution code:
XN = input().split()
X = int(XN[0])
N = int(XN[1])
p = input().split()
A = [None]*N
for i in range(N):
    A[i] = abs(int(p[i])-X)
j = 0
while j in A:
    j += 1
if A.count(j-1) == 2:
    print(X-j)
else:
    if str(X-(j-1)) in p:
        print(X+(j-1))
    else:
        print(X-(j-1))

Submission status: Wrong Answer

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

if (1 <= X <= 100) and (0 <= N <= 100) and ((1 <= len(p) <= 100 ) or N == 0) :
    ans = X-1
    bns = X+1
    if N != 0:
    
        for i in range(10):
            if ans not in p:
                print(ans)
                break
            
            if ans in p:
                ans-=1         
                if ans not in p:
                    print(ans)
                    break
                
            if bns not in p:
                print(bns)
                break
            
            if bns in p:
                bns+=1
                if bns not in p:
                    print(bns)
                    break
    elif N ==0:
        print(X)

Submission status: Wrong Answer

Solution code:
import numpy as np
int_num, length = map(int, input().split())
if length == 0:
    print(int_num)
else:
    num_list = (list(map(int, input().split())))
    num_zettai_list = np.abs(num_list)
    up_int = int_num
    down_int = int_num
    while True:
        up_int += 1
        down_int -= 1
        flg1 = up_int in num_zettai_list
        flg2 = down_int in num_zettai_list
        if not flg1 and not flg2:
            print(down_int)
            break
        elif flg1 and not flg2:
            print(down_int)
            break
        elif flg2 and not flg1:
            print(up_int)
            break

Submission status: Wrong Answer

Solution code:

F = input().split()

X = int(F[0])
N = int(F[1])
k = 0
L = -1

if N == 0:
	q = [N]

else:
	p = list(map(int, input().split()))
	p.sort()
	q = list(set(p))

while k == 0:
	L += 1
	deka = X+L
	tibi = X-L
	for i in range(len(q)):
		if q[i] == deka:
			deka = 0
		if q[i] == tibi:
			tibi = 0
	if deka != 0 or tibi != 0:
		k = 1

if tibi == 0:
	print(deka)

else:
	print(tibi)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
l = list(range(1, 100))
ll = []
if n ==0:
    print(x)
else:
    for j in range(50):
        if x-j in l:
            if not x-j in p:
                ll.append(x-j)
        if len(ll) != 0:
            print(min(ll))
            break
        if x+j in l:
            if not x+j in p:
                ll.append(x+j)
        if len(ll) != 0:
            print(min(ll))
            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()))

for n in range(1, N + 1):
    mi = X - n
    if mi < 1:
        continue

    ma = X + n
    if ma > 100:
        continue

    if not (X - n) in P:
        print(X - n)
        exit()
    if not (X + n) in P:
        print(X + n)
        exit()
if min(P) - 1 < 0:
    print(max(P) + 1)
    exit()
print(min(P) - 1)

Submission status: Wrong Answer

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

import sys

def main():
    numbers=[]
    x,n = map(int,input().split())
    numbers=list(map(int,input().split()))
    if n==0:
        print(x)
        sys.exit()
    dp_list=list(range(1, 101))
    dp_list=set(dp_list)-set(numbers)

    for i in range(101):
        if abs(x-i) in dp_list:
            print(x-i)
            break
        elif abs(x+i) in dp_list:
            print(x+i)
            break

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i in range (-101, 101, 1):
  c_list.append(i)

if n == 0:
  ans = x
else:
  p = list(map(int, input().split()))
  for i in range(len(p)):
    c_list[c_list.index(p[i])] = 250
  # print(c_list)
  diff = 500
  for i in range(len(c_list)):
    if abs(x - c_list[i]) < diff:
      diff = x - c_list[i]
      ans = c_list[i]

print(ans)

Submission status: Wrong Answer

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

mina =101
y = []
minb = 101

for i in range(1,101):
    y.append(i)

if n == 0:
    print(x)
else:
    for j in range(n):
        y.remove(p[j])
    
    for k in range(1,101-n):
        
        if abs(x - y[k-1]) < mina:
            mina = abs(x - y[k-1])
            minb = y[k-1]

print(minb)

Submission status: Wrong Answer

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

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

abs_n = 0
ans = 0

if n == 0:
    print(x)
else:
    #r = max(p)
    #l = min(p)

    for i in range(1,101):
    
        # 配列に含まれていると
        if i in p:
            continue
            
        tmp = abs(x-i)
        #print(i, tmp)

        if i == 1:
            abs_n = tmp
            ans = i
        
        if tmp < abs_n:
            abs_n = tmp
            ans = i
        
    print(ans)

Submission status: Wrong Answer

Solution code:
x,n= map(int,input().split())
u = 100
num_str=input().split()
s=list(map(int, num_str))
m = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100}
for k in s:
    m.remove(k)
for l in m:
    if u >= abs(l - x):
        u = l
print(u)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N > 0:
    l = list(map(int, input().split()))
    A = [0] * N
    for i in range(N):
        A[i] = abs(l[i] - X)
        S = A.count(0)
        if S == 0:
            print(X)
        else:
            for i in range(1, N):
                S = A.count(N)
                if S == 1:
                    if l.count(X - 1) == 0:
                        print(X - 1)
                        break
                    else:
                        print(X + 1)
                        break
                else:
                    pass
else:
    print(X)

Submission status: Wrong Answer

Solution code:
import math
X,N=map(int,input().split())
p = list(map(int,input().split()))
abs_list=[0]*N
for i,a in enumerate(p):
    abs_list[i]=a-X
abs_new=sorted(abs_list, key = abs)
if N==0:
    print(X)
for i,a in enumerate(abs_new):
    if i==0 and a!=0:
        print(X)
        break
    elif i%2==1 and (math.floor((i-1)/2)+1)!=a:
        if (math.floor((i-1)/2)+1)!=(-a):
            print(X-(math.floor((i-1)/2)+1))
            break
        else:
            print(X+math.floor((i-1)/2)+1)
            break
    elif i%2==0 and (math.floor((i-1)/2)+1)!=(-a):
        print(X-(math.floor((i-1)/2)+1))
        break

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import sys
X,N=list(map(int,input().split()))
if N==0:
    print(X)
    sys.exit()
P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if x>=len(P):
    print(X)
    sys.exit()
if P[x]!=X:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)
    if x2==len(P):
        print(B)
        break
        
    if x1<len(P) and P[x1]!=A:
        print(A)
        break
        
    if x2<len(P) and P[x2]!=B:
        print(B)
        break