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())
result = 1000000000000
tmp = 100000000
if N == 0:
    print(X)
    exit()
S = list(map(int,input().split()))
flag = True
S.sort()
max_S = max(S)
for i in range(max_S):
    #含まれていないか確認
    for j in S:
        if i == j:
            flag = False
            break
    if flag == False:
        flag = True
        continue
    #print(i)
    if abs(X - i) < result:
        #print("aa:"+str(abs(X - i)))
        result = abs(X - i)
        tmp = i
print(tmp)

Submission status: Wrong Answer

Solution code:
import numpy as np
X,N = map(int, input().split())
if N != 0:
  p = list(map(int, input().split()))
  min_val = -100
  max_val = 200
  not_p = [i for i in range(min_val,max_val+1,1)]
  
  for i in range(N):
    not_p.remove(p[i])

  min_val = 999
  out_num = 101
  for i in range(len(not_p)):
    if abs(X-not_p[i]) < min_val:
      min_val = abs(X-not_p[i])
      out_num = not_p[i]
else:
  out_num = 0
print(out_num)

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)]

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:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
import pprint



sys.setrecursionlimit(2147483647)
INF = 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


x, n = LI()
P = set(LI())
i = 0
while True:
    if x - i not in P:
        print(x - i)
        break
    elif x + i in P:
        print(x + i)
    i += 1

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
    min = 1000
    result = 1000
    if n == 100:
        result = 0
    else:
        for i in reversed(range(1,101)):
            if a[i] != 1000:
                if min >= abs(x - a[i]):
                    min = abs(x - a[i])
                    result = a[i]

    print(result)

Submission status: Wrong Answer

Solution code:
line = input().split()
X = int(line[0])
N = int(line[1])

if N == 0:
    print(X)

else:
    p_line = input().split()
    p_line = [int(i) for i in p_line]
    num_line = [i for i in range(-100, 101)]
    set_line = list(set(num_line) - set(p_line))

    min = 101
    ans = 0

    if X in set_line:
        print(X)
        exit()

    if len(set_line) == 0:
        print(X)
        exit()
    
    for i in set_line:
        if i <= 0:
            if X+i < min:
                min = X+i
                ans = i
        
        if 0 < i < X:
            if X-i < min:
                min = X-i
                ans = i
        else:
            if i-X < min:
                min = i-X
                ans = i

            if i-X > min:
                break
            
    print(ans)

Submission status: Wrong Answer

Solution code:
def read_input(trans=int):
    return list(map(trans, input().split()))


X, N = read_input()
if N == 0:
    print(X)
else:
    list_p = read_input()

    for i in range(N):
        if X-i in list_p:
            if X+i in list_p:
                continue
            else:
                print(X+i)
                break
        else:
            print(X-i)
            break

Submission status: Wrong Answer

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

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


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)

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

Submission status: Wrong Answer

Solution code:
x,y = [int(x) for x in input().split()]
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

Submission status: Wrong Answer

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

if N == 1:
    if not (X - 1) in P:
        print(X - 1)
        exit()
    if not (X + 1) in P:
        print(X + 1)
        exit()

for n in range(1, N + 1):
    m = X - n
    if m < 0:
        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:
X, Y = map(int, input().split())
p = map(int, input().split())

if Y == 0:
    print(X)
if Y != 0:
    for i in range(1, 100):
        if X-i >= 1:
            if abs(X-i) not in p:
                print(X-i)
                break
        if X+i <= 100:
            if abs(X+i) not in p:
                print(X+i)
                break

Submission status: Wrong Answer

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

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

p.sort()

minp = 999
minv = x
if n == 100:
    print(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:
import sys
x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()

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

for i in range(0, 100):
    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:
import sys

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

x = [X] * N

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

tmp = [i - j for (i, j) in zip(x, p)]

for i in range(N):
    if tmp.count(i) == 0:
        print(X - i)
        sys.exit()
    elif tmp.count(-i) == 0:
        print(X + i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
  print(x)
elif n == 1:
  if x == p:
    print(x-1)
  else:
    print(x)
else:
  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(" ")))
  sa = 1
  ans = -100
else:
  ans = x
    
while True:
  if ans != -100:
    break
  for i in range(N):
    if x-sa == p[i]:
      break
    if i == N-1:
      if x-sa != p[i]:
        ans = x-sa
  if ans != -100:
    break
  for i in range(N):
    if x+sa == p[i]:
      break
    if i == N-1:
      if x+sa != p[i]:
        ans = x+sa
  if ans != -100:
    break
  sa += 1
print(ans)

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 = 1000
d = 1000
for i in range(100-n):
   if d != min(d,abs(x - q_list[i])):
       ans = q_list[i]
       d = min(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()))
r = 0
l = 0

for i in range(X + 1, 100 + 10):
  if not i in p:
    l = i
    break
    
for i in range(X - 1, -1, -10):
  if not i in p:
    r = i
    break

dl = abs(X - l)
dr = abs(X - r)

if dr <= dl:
  print(r)
else:
  print(l)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
try:
  p=list(map(int,input().split()))
except:
  print(x)
  exit()
ans=float('inf')
for i in range(1,200):
  if i not in p:
    ans=min(ans,abs(x-i))
    
    
if x-ans not in p :
  print(x-ans)
  
else:
  print(x+ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
else:
    p = set(map(int, input().split()))
q = set(range(min(p)-1,max(p)+2,1))
r = q - p - set([X])
diff = 100
ans = 0
for i in r:
    if diff > abs(X-i):
        diff = abs(X-i)
        ans = 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()))
mind = abs(x - p[0])
pos = [p[0]]
s = set(p)
p = []
for x1 in range(-100, 200):
	if x1 in s:
		continue
	else:
		p.append(x1)
for q in p:
	if abs(x - q) < mind:
		mind = abs(x - q)
		pos = [q]
	elif abs(x - q) == mind:
		pos.append(q)
pos.sort()
print(pos[0])

Submission status: Wrong Answer

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

A = [0]*101

for i in P:
    A[i] = 1

if A[X] == 0:
    print(X)
    exit()

count = 1
while(1):
    if (X - count) >= 0:
        if (X - count) < 101:
            if A[X - count] == 0:
                print(X - count)
                exit()
    else:
        print(-1)
        exit()

    if count > 0:
        count = -count
    else:
        count = -count
        count += 1

Submission status: Wrong Answer

Solution code:

X,N = map(int,input().split())
result = 1000000000000
tmp = 100000000
if N == 0:
    print(X)
    exit()
S = list(map(int,input().split()))
flag = True
S.sort()
max_S = max(S)
for i in range(max_S):
    #含まれていないか確認
    for j in S:
        if i == j:
            flag = False
            break
    if flag == False:
        flag = True
        continue
    print(i)
    if abs(X - i) < result:
        print("aa:"+str(abs(X - i)))
        result = abs(X - i)
        tmp = i
print(tmp)

Submission status: Wrong Answer

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

if N == 0:
    print(X)
    
else:
    for i in range(100):
        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:
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)

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

  n = [x for x in range(101)]

  for i in p:
    n.remove(i)
  ans = 0  
  a = 100
  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 -*-
X, N= map(int, input().split())
if N == 0:
  print(X)
else:
  p = input().split()
  i = 1
  while True:
    if (str(X-i) in p) == False:
      print(X-i)
      break
    elif (str(X+i) in p) == False:
      print(X+i)
      break
    else:
      i += 1

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
import sys
if n==0:
    print(x)
    sys.exit()
if n==100:
    print(0)
    sys.exit()
a=list(map(int,input().split()))
l=0
c=101
d=0

for i in range(1,101):
    for j in range(n):
        if i==a[j]:
            l=1
            break
    if l==1:
        l=0
        continue
    if abs(i-x)<c:
        c=abs(i-x)
        d=i
print(d)

Submission status: Wrong Answer

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

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

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

q = [i for i in range(0, 100+1)]
r = []

for i in q:
    if i not in p:
        r.append(i)

s = [abs(x-i) for i in r]

print(r[s.index(min(s))])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n != 0:
  n = list(map(int, input().split()))
  ans = []
  for i in range(1, 101):
    if n.count(x + i) == 0:
      ans.append(x + i)

    if n.count(x - i) == 0:
      ans.append(x - i)
    
    if ans != []:
      break

  print(min(ans))
else:
  print(x)

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)

    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:
                answer = j
                break
    print(answer)

except:
    print(input_list1_int[0])

Submission status: Wrong Answer

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

if N == 1:
    if not (X - 1) in P:
        print(X - 1)
        exit()
    if not (X + 1) in P:
        print(X + 1)
        exit()

for n in range(1, (N // 2) + 1):
    m = X - n
    if m < 0:
        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:
X, N = map(int, input().split())
ps = list(map(int, input().split()))
 
pset = set([abs(X-p) for p in ps])
 
for i in range(50):
  if i not in pset:
    if X-i >= 0:
      print(X-i)
    else:
      print(X+i)
    break

Submission status: Wrong Answer

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

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

f = [1]*100
sa = 101
ans = 0

for i in p:
    f[i-1] = 0

for i in range(100):
    if f[i] == 1 and sa > abs(i+1-x):
        sa = abs(i+1-x)
        ans = i+1

if sum(f) == 0:
    print(0)
elif sa >= x:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
xp=[]
xm=[]
for i in range(0,100):
    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:
X, N = input().split()
p = input().split()
X = int(X)
N = int(N)
min = 101
ans = 0
for i in range(-101, 101):
    if str(i) in p:
        continue
    a = abs(i - X)
    if a < min:
        min = a
        ans = i
print(ans)

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(" ")))
    # print(x,n)
    # print(plist)
    plistx = list(map(minusx,plist))
    # print(plistx)
    plisty = list(map(abs,plistx))
    # print(plisty)
    plisty_max = max(plisty)
    print(plisty_max)

    if plisty_max == 0:
        plisty_max =1
    
    print(plisty_max)

    newlist = list(range(x-plisty_max,x+plisty_max+1))
    print(newlist)
    pset_diff = set(plist) ^ set(newlist)
    plist_diff = list(pset_diff)
    print(plist_diff)
    plist_plus = [i for i in plist_diff if i>0 and i<=100]
    print(plist_plus)

    for i in range(202):
        if x-i in plist_plus:
            print(x-i)
            break
        elif x+i in plist_plus:
            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()))
q = set(range(1,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 = min(d,abs(x - q_list[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
def forbidden(x,p):
    res = []
    for num in range(101):
        if x!=num and num not in p:
            res.append(abs(x-num))
    if x-min(res) not in p:
        return x-min(res)
    return x+min(res)

if __name__ == "__main__":
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    if n==0:
        print(x)
        exit()
    print(forbidden(x,p))

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input(). split())
l = [0]*n
m = [0]*100
p = []
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] != 2:
    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 sys

def Forbidden_List():
    X ,N = map(int, input().split())
    
    if N == 0:
        return X
    
    p = list(map(int, input().split()))

    if min(p) == 0:
        j = 0
    else:
        j = min(p)-1
        
    other_integer = [i for i in range(j, 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:
from sys import stdin
x, n = map(int, stdin.readline().rstrip().split())
if n ==0:
    print(x)
else:
    data = list(map(int, stdin.readline().rstrip().split()))

    data_sorted = sorted(data)

    abs_min = 100000000
    res = 0
    for i in range(data_sorted[0]-1, data_sorted[-1]+1):
        if (i in data_sorted) == False and abs_min > abs(i-x):
            abs_min = abs(i-x)
            res = i
    print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np

def ForbiddenList():

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

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

    if len(NumB) != 0:
        result = list(range(min(NumB)-1, max(NumB)+1, 1))

        for data in NumB:
            result.remove(data)

        idx = np.abs(np.asarray(result) - NumA[0]).argmin()

        print(result[idx])

    else:
        print(NumA[0])
    

if __name__ == '__main__':
    ForbiddenList()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
num, i = map(int, input().split())
s = set(map(int, input().split()))
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:
    print(x)
else:
    pn = list(map(int, input().split()))
    is_ex_list = [False for i in range(max(pn) + 1)]
    for p in pn:
        is_ex_list[p] = True
    min_v = 101
    min_f = 101
    for i in range(-100, 101):
        if len(is_ex_list) > i and i >= 0:
            if not is_ex_list[i] and abs(x - i) < min_v:
                min_f = i 
                min_v = abs(x - i)
        elif abs(x - i) < min_v:
                min_f = i 
                min_v = abs(x - i)
    print(min_f)

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)

answer = min(X - minimum - 1, 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 = list(map(int, input().split()))
if N == 0:
    print(X)
else:
    p = list(map(int, input().split()))
    not_p = set(range(101)) - set(p)

    arg_min = 10000
    value_min = 10000
    for i in not_p:
        tmp = abs(X - i)
        if tmp < value_min or (tmp == value_min and i < arg_min):
            value_min = tmp
            arg_min = i
    print(arg_min)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p_list = list(map(int,input().split()))
for i in range(1,100):
    if N == 0:
        print(X)
        break
    elif len(p_list) == 100:
        print(-1)
        break
    elif not X-i in p_list:
        print(X-i)
        break
    elif not X+i in p_list:
        print(X+i)
        break

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

p = list(map(int, input().split()))
l = []
for i in range(-100,101):
  l.append(i)

L = []
for i in l:
  if i not in p:
    L.append(i)

l = []
for i in L:
  l.append([i, abs(x-i)])
a = min(l, key = lambda t: t[1])
print(list(a)[0])

Submission status: Wrong Answer

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

import sys
X = int(X)
N = int(N)


if N ==0:
    print(X)
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:
XN = list(map(int, input().split()))
 
if XN[1] == 0:
  print(XN[0])
else:
  p = list(map(int, input().split()))
  for d in range(XN[1] + 1):
    if not XN[0] - d in p:
      print(XN[0] - d)
    elif not XN[0] + d in p:
      print(XN[0] + d)

Submission status: Wrong Answer

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

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


n = 0
ans = 0

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

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

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

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_)


# print(abs (x - min_))
# print(abs (x - max_))

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

print(ans)

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 a[0] < b2[0]:
    print(a[0])
  else:
    c = abs(b2[0]-1-a[0])
    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:
  p = list(map(int, input().split()))
else:
  p = [x - 1]
pl = sorted(p)
xn = []
mp = max(pl)
for i in range(101):
  if i not in pl:
    if i <= (mp + 1):
      xn.append(i)
dxn = []
for i in range(len(xn)):
  da = abs(x - xn[i])
  dxn.append(da)
minidx = [i for i, x in enumerate(dxn) if x == min(dxn)]
print(xn[minidx[0]])

Submission status: Wrong Answer

Solution code:
x_n = input()
x_n_list = x_n.split()
x = int(x_n_list[0])
n = int(x_n_list[1])
if n == 0:
  print(x)
else:
  allp = input()
  p_list = allp.split()
  p_l = [int(n) for n in p_list]
  if x not in p_l:
    print(x)
  else:
    for i in range(len(p_l)):
      if x - i in p_l:
        print(x - i - 1)
        break
      elif x + i in p_l:
        print(x + i + 1)
        break
      else:
        pass

Submission status: Wrong Answer

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

if n>=1:
    p=list(map(int,input().split()))
else:
    print(x)
    sys.exit()
s=[]
d={}
l={}
for i in range(101):
    if i not in p:
        s.append(i)


for k in s:

    d[k]=abs(x-k)


l=[m[0] for m in d.items() if m[1]==min(d.values())]
print(min(l))

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
X, N = np.array(list(map(int, input().split())))
if N == 0:
    print(X)
    sys.exit()
p = np.array(list(map(int, input().split())))
p = np.sort(p)
a = np.ones(304, dtype = np.int)
a[p+102] = 0
m = X+1000
n = 0
for i in range(304):
    if a[i] == 1:
        if m>abs(i-X-102):
            if i-X-102 != 0:
                m = abs(i-X-102)
                n = i-102
print(int(n))

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split(' '))
if n > 0:
    p = list(map(int, input().split(' ')))
    r = x + 1
    l = x - 1
    ansr = 0
    ansl = 0
    for i in range(102):
        if r not in p:
            ansr = r
            break
        r += 1
    for i in range(102):
        if l not in p:
            ansl = l
            break
        l -= 1
    vr = ansr - x
    vl = x - ansl
    if vr == vl:
        ans = ansl if ansl < ansr else ansr
    else:
        ans = ansl if vl < vr else ansr
else:
    ans = x
print(ans)

Submission status: Wrong Answer

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

def minus(num):
    return int(num) - 1


def plus(num):
    return int(num) + 1


if n != 0:
    lst = list(map(int, input().split()))
    for j in range(5):
        count = 0
        for i in lst:
            if x1 == i:
                x1 = minus(x1)
                break
            count += 1
        if count == 5:
            break
    for j in range(5):
        count = 0
        for i in lst:
            if x2 == i:
                x2 = plus(x2)
                break
            count += 1
        if count == 5:
            break

    if x >= 0:
        ans1 = x - x1
        ans2 = x2 - x
        if ans1 <= ans2:
            print(x1)
        else:
            print(x2)
    else:
        ans1 = (x - x1) * (-1)
        ans2 = (x2 - x) * (-1)
        if ans1 >= ans2:
            print(x1)
        else:
            print(x2)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    ans = x
    absol = 1000

    for i in range(-100, 101):
        if i not in p:
            if abs(i - x) < absol:
                absol = abs(i - x)
                ans = i
    print(ans)

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(101)
    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:
import math
input_a= input().split(" ")
X=int(input_a[0])
N=int(input_a[1])

if N!=0:
  array= input().split(" ")
else:
  array=[0,0]

num=X
num2=-100
for i in range(101-X):

  
  if str(num) not in array:
    dis=abs(X-num)
    num2=X-dis
    if str(num2) not in array:
    	print(min([num,num2]))
    else:
      print(num)
    break
  num=num+1
    
if num2==-100:
  num=X
  i=0
  for i in range(X+3):
    num=num-1
    if "num" not in array:
      print(num)
      break