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:
import numpy as np
X,N = map(int, input().split())
p = list(map(int, input().split()))
all_num = list(range(-100,101))

mi = 1000
for i in p:
    all_num.remove(i)

least = []
for i in all_num:
    if abs(X-i) < mi:
        least = []
        mi = abs(X-i)
        least.append(i)
    elif abs(X-i) == mi:
        least.append(i)
if least != []:
    print(sorted(least)[0])
else:
    print()

Submission status: Wrong Answer

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

if N == 100:
    index = 0

elif N != 0:
    p = [int(i) for i in input().split()]
    ary = [i for i in range(1,101)]
    for j in range(N):
        if p[j] in ary:
            ary.remove(p[j])
    min = abs(X-ary[0])
    if ary[0]!=None:
        index = ary[0]
    for j in range(1,len(ary)):
        if min > abs(X-ary[j]):
            min = abs(X-ary[j])
            index = ary[j]

elif N == 0:
    index = X

print(index)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
if a[1] == 0:
    print(a[0])
else:
    b = list(map(int, input().split()))
    b.sort()
    diff = 100000000001
    ans = min(b) + 1
    out = 0
    while (ans < 101):
        if ans not in b:
            if (abs(ans - a[0]) < diff):
                diff = abs(ans - a[0])
                out = ans
        ans += 1        
    print(out)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
al = set(range(101))
not_p = list(set(al) - set(p))

not_p_diff = list(map(lambda n: abs(n - X), not_p))
num = not_p_diff.index(min(not_p_diff))

print(not_p[num])

Submission status: Wrong Answer

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

l = list(range(1, 101))
print(l)

for i in p:
        if i in l:
                l.remove(i)
r = 102
sa = 9999
for j in l:
        if sa > abs(x - j):
                sa = abs(x - j)
                r = j
        elif sa == abs(x - j) and r > j:
                sa = abs(x - j)
                r = j
print(r)

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
nums=[int(x) for x in input().split()]
#print(nums)
if n == 0:
	print(x)
	exit()
if x == 1:
	print(0)
	exit()
min=x
gap=x
#print('Here')
for i in range(-300,300):
	if i in nums:
		continue
	else:
		if abs(x-i) < gap:
			#print("min: ",min)
			#print(x-i)
			gap=x-i
			min = i
print(min)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
ans = 100000000
l = 1000000
for i in range(101):
    if i == 0:
        None
    else:
        if P.count(i) == 0:
            #print(i)
            if abs(i-X) == l:
                ans = min(i,ans)
            elif abs(i - X) < l:
                l = abs(i - X)
                ans = i
                #print(ans,i,l)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
tmp = []
for i in range(-101,101):
    tmp.append(i)

if n == 0:
    print(x)
else:
    for i in p:
        tmp.remove(i)
    
    ans = []
    for i in tmp:
        a = abs(x-i)
        ans.append(a)

    b = min(ans)
    
    c = x+b
    d = x-b

    if c and d in tmp:
        print(d)
    elif c in tmp:
        print(c)
    elif d in tmp:
        print(d)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
m=100
j=0
for i in range(1,101):
    if abs(x-i)<m and str(i) not in str(p):
        m=abs(x-i)
        j=i
print(j)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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

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

    l = bisect_left(p, x)
    #右
    for i in range(0,10**7):
        #print(p[l]+i)
        if p[l]+i in p:
            pass
        else:
            a = p[l]+i
            break

    for i in range(0, 10**7*-1, -1):
        if p[l]-i in p:
            pass
        else:
            b = p[l]-i
            break
    print(min(a,b))
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)
    exit()
res = []
for num in range(-100,101):
    if x!=num and num not in p:
        res.append(abs(x-num))
if x-min(res) not in p and x-min(res)!=0:
    print(x-min(res))
elif x-min(res)==0:
    res.remove(min(res))
    if x-min(res) not in p:
        print(x-min(res))
    else:
        print(x+min(res))
else:
    print(x+min(res))

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
p = list(map(int, input().split()))
ans_s = x
ans_l = x
count_s = 0
count_l = 0

while count_s == 0:
    if ans_s in p:
        ans_s -= 1 
        count_s = 1
        print(ans_s)
    else:
        count_s = 0 

while count_l == 0:
    if ans_l in p:
        ans_l += 1
        count_l = 1
        print(ans_l)
    else:
        count_l = 0
if abs(x - ans_s) < abs(ans_l - x):
    print(ans_s-1)
else:
    print(ans_l+1)

Submission status: Wrong Answer

Solution code:
if __name__=="__main__":
    # Problem C
    X, N = map(int, (input().split(' ')))
    if N > 0:
        P = sorted(map(int, input().split(' ')))
        P_max = max(P)
        P_min = min(P)
        search = True
        if X in P and search==True:
            for i in range(1, max(P_max-X + 1 , X-P_min +1)):
                if (X-i) not in P:
                    print(X-i)
                    search = False
                    break

                elif (X+i) not in P:
                    print(X+i)
                    search = False
                    break
        else:
            print(" ")
    else:
        print(" ")

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
l=list(map(int,input().split()))
tmp1=X-1
tmp2=X+1
if N==0:
    print(X)
else:
    while True:
        if not tmp1 in l:
            print(tmp1)
            exit()
        else :
            tmp1-=1
        if not tmp2 in l:
            print(tmp2)
            exit()
        else:
            tmp2+=1

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:
x, n = map(int, input().split())
if(n == 0):
    print(x)
elif(n == 100):
    ff = 101-x
    gg = x
    if(ff < gg):
        print(101)
    else:
        print(0)
else:
    p = list(map(int, input().split()))
    m = [i for i in range(1, 1000)]
    for i in range(len(m)):
        if(m[i] in p):
            m[i] = 10000
        else:
            m[i] = abs(x-m[i])
    print(m)
    print(m.index(min(m))+1)

Submission status: Wrong Answer

Solution code:
import collections

x,n=(int(x) for x in input().split())

a=input()

if n==0:
    print(x)

l=[0]*n
l = a.split()
t = [0]*n
for i in range (n):
    l[i]=int(l[i])
    t[i]=abs(x-l[i])
k=list(range(1,101))
#print(k)
c = collections.Counter(t)
j=[i[0] for i in c.items() if i[1] >= 2]
print(j)
for i in range(len(j)):
    k.remove(j[i])
print(k[0])
judge=0
for i in range(n):
    if x-k[0]==l[i]:
        judge=1
if judge==0:
    print(x-k[0])
else :
    print(x+k[0])

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
A=list(map(int,input().split()))
B=[]
 
for i in range(101):
  if i in A:
    pass
  else:
    B.append(i)
 
C=[abs(X-j) for j in B]
y=C.index(min(C))
 
z=B[y]
 
print(z)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
l1 = list(map(int,input().split()))	
l2 = list(range(1, 100))
diff = set(l1) ^ set(l2)
diff = list(diff)
def sorting(numbers_array):
  return sorted(numbers_array, key=abs)

sl = map(lambda a: a - x, diff)
print(sorting(sl)[0]+x)

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 = 1001001
tmp = 1001001
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 = min(ans, i)

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n > 1:
  p = list(map(int, input().split()))
else:
  print(x)
  exit(0)
   
for i in range(n+1):
  if (x-i) not in p:
    print(x-i)
    break
  if (x+i) not in p:
    print(x+i)
    break

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
def test(X, N, P):
  P_int = []
  
  for i in P:
    P_int.append(int(i))

  lis = []
  
  for i in list(range(101)):
    if i not in P_int:
      lis.append(i)
  
  min_adv = 1000
  min_num = 1000

  for i in lis:
    rec_adv = abs(X - i)

    if rec_adv < min_adv:
      min_num = i
      min_adv = rec_adv

  if N != 0:
    print(str(min_num))
  else:
    print('100')
    
X, N = input().split()
P = input().split()

test(int(X), int(N), P)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N != 0:
  P = list(map(int, input().split()))
else:
  print(X)
  exit()
list = []
list2 = []
for i in range(-5,max(P)+50):
  if i not in P and i != X:
    res = abs(X - i)
    list.append(res)
    list2.append(i)
    
maxres = list.index(min(list))
if maxres != 0:
  print(list2[maxres])
else:
  print(-1)
print(maxres)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
n = list(map(int,input().split()))
xn = list(range(1,101))
answer = 0
for i in range(N):
  xn.remove(n[i])
mindis = 100
for i in range(len(xn)):
  dis = abs(X-xn[i])
  if dis < mindis:
    mindis = dis
    answer = xn[i]
print(answer)

Submission status: Wrong Answer

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

p_ = [i for i in range(101)]
p_ = list(set(p_) - set(p))

list = []
list_ = []
for j in p_:
  C = abs(X-j)
  list.append(C)
  list_.append(X-j)
list.sort()

if list_.count(list[0]) == 0:
  print(X+list[0])
else:
  print(X-list[0])

Submission status: Wrong Answer

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

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=list(map(int,input().split()))
arr=list(map(int,input().split()))
if n==0:
  print(x)
else:
  for k in range(1,max(arr)):
    if x-k not in arr:
      print(x-k)
      break
    elif x+k not in arr:
      print(x+k)
      break

Submission status: Wrong Answer

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

result = x
sa = 100
count = 0
a = 0
for l in range(1,101):
    
    if l in p:
        a += 1
        continue
    
    if sa <= abs(x-l):
        result = count
        break

    count = l
    sa = abs(x -l)
else:
    result = count
if a == len(p):
    result = ""
print(result)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))

res = a[0]
j = 0

while a[1] != 0:
    j += 1
    if j == 1:
        res = j
    if j in [b[s] for s in range(a[1])]:
        continue
    if abs((a[0] - res) > abs(a[0] - j)):
        res = j

    if j > a[0] and not(j in [b[s] for s in range(a[1])]):
        if abs((a[0] - res) > abs(a[0] - j)):
            res = j
        break


print(res)

Submission status: Wrong Answer

Solution code:
import bisect

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

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

p.sort()

if x not in p:
    i = bisect.bisect_left(p, x)
    p = p[:i] + [x] + p[i:]
    
for i in range(len(p)):
    #print(p[i])
    if p[i] == x:
        index = i
        break

right = x + 1
for i in p[index + 1:]:
    if i != right:
        break
    right += 1

left = x - 1
for i in reversed(p[:index]):
    if i != left:
        break
    left -= 1

if x - left <= right - x:
    print(left)
else:
    print(right)

Submission status: Wrong Answer

Solution code:

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



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

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

else:
    for i in range(0,101):
        if l.count(int(X))==0:
            print(int(X))
            break 


        elif l.count(int(X-i))==0:
            print(int(X-i))
            break 

    

        if X+i<=100:
            if l.count(int(X+i))==0:
                print(int(X+i))
                break

Submission status: Wrong Answer

Solution code:
import sys

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

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

li.sort()

result1 = 0
counter1 = 1
kekka1 = 0
while(True):

    try:
        result1 = li.index(x+counter1)
        kekka1 = li[result1]
        counter1 = counter1+1
    except ValueError as e:
        break

result2 = 0
counter2 = 1
kekka2 = 0
while(True):
    try:
        result2 = li.index(x-counter2)
        kekka2 = li[result2]
        counter2 = counter2+1
    except ValueError as e:
        break

if counter1 < counter2:
    print(x+counter1)
elif counter1 > counter2:
    print(x-counter2)
elif counter1 == counter2:
    print(x-counter2)

Submission status: Wrong Answer

Solution code:

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

def my_func(a):
    return(int(a) - x)

ps = list(map(my_func, input().split()))
dest = sorted(list(set([i - x for i in range(-1, 101, 1)]) - set(ps)), key=abs)
if dest[0] == dest[1]*(-1):
    print(dest[1] + x)
else:
    print(dest[0] + x)

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(-200,300)]

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[idx_x-1])
    sys.exit()

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

dl = abs(x - lesser)
dg = abs(greater - x)

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

Submission status: Wrong Answer

Solution code:
import sys
x,n =map(int,input().split())
if n == 0:
    print(x)
    sys.exit()
p = list(map(int,input().split()))
p.sort()
wk = 101
an = 0
if n ==100:
    print(0)
    sys.exit()
for i in range(1,101):
    if x!=i:
        if p.count(i)==0:
            if abs(x-i)<=wk:
                an =i
                wk = abs(x-i)
            else:
                print(an)
                sys.exit()
print(an)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N == 0 :
    print(X)
else :
    P = list(map(int,input().split()))
    a = list(range(1000))
    ab = 100
    for i in range(N):
        a.remove(P[i])
    for j in range(100 - N):
        ab = min(ab,abs(X - a[j]))
    if X - ab in a and X + ab in a:
        print(min(X - ab,X + ab))
    elif X - ab in a:
        print(X - ab)
    elif X + ab in a:
        print(X + ab)

Submission status: Wrong Answer

Solution code:
X, N = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    Ps = set([int(i) for i in input().split()])
    if not X in Ps:
        print(X)

    diff = 0
    while True:
        if not X - diff in Ps:
            print(X - diff)
            break
        if (not X + diff in Ps):
            print(X + diff)
            break
        diff += 1

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
n = list(map(int,input().split()))
xn = list(range(1,101))
answer = X
for i in range(N):
  xn.remove(n[i])
mindis = 100
for i in range(len(xn)):
  dis = abs(X-xn[i])
  if dis < mindis:
    mindis = dis
    answer = xn[i]
print(answer)

Submission status: Wrong Answer

Solution code:
lst = []
l = []
str = input()
l = str.split(' ')
n = int(l[0])
no = int(l[1])
if no==0:
  print(n)
 

else:  
  str1 = input()
  lst = str1.split(' ')
  for i in range(0,no):
    lst[i] = int(lst[i])
  i=1
  while i<101:
    if n-i not in lst:
      print(n-i)
      break
    if n+i not in lst:
      print(n+i)
      break
    i = i+1

Submission status: Wrong Answer

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

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

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

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

if ans == 1000:
    if abs(X - m - 1) <= abs(X + 1):
        ans = m + 1
    else:
        ans = -1

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
nums=[int(x) for x in input().split()]
#print(nums)
if n == 0:
	print(x)
	exit()
if x == 1:
	print(0)
	exit()
min=x
gap=x
#print('Here')
for i in range(1,300):
	if i in nums:
		continue
	else:
		if abs(x-i) < gap:
			#print("min: ",min)
			#print(x-i)
			gap=x-i
			min = i
print(min)

Submission status: Wrong Answer

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

p = set(map(int,input().split()))
not_p = list(set(range(0,100)) - p)

minV = 101
ans = 0
for i in not_p:
    if abs(X - i) < minV:
        minV = abs(X - i)
        ans = i
        
if minV == 101:
    if X < 51:
        ans = 0
    else:
        ans = 101
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np 

X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    l = list(map(int, input().split()))
    l = sorted(l)
    number_list = []
    for i in range(l[-1] * 1000):
        number_list.append(i+1)
    for k in l:
        if k in number_list:
            for num, li in enumerate(number_list):
                if li == k:
                    number_list.pop(num)
    number_list.append(X)
    number_list = sorted(number_list)
    for n,b in enumerate(number_list):
        if b == X:
            if np.abs(number_list[n-1] - X) > np.abs(number_list[n+1] - X):
                print(number_list[n+1])
                
            elif np.abs(number_list[n-1] - X) < np.abs(number_list[n+1] - X):
                print(number_list[n+1])
                
            elif np.abs(number_list[n-1] - X) == np.abs(number_list[n+1] - X):
                if number_list[n-1] > number_list[n+1]:
                    print(number_list[n+1])
                elif number_list[n-1] < number_list[n+1]:
                    print(number_list[n-1])

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 = 101
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(" "))
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,):
            if(c-i<0):
                print(x-i)
                break
            else:
                if(a[c-i]!=x-i):
                    print(x-i)
                    break
                elif(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())
if N == 0:
    print(X)
    exit()
else:
    P = list(map(int,input().split()))
L = [i for i in range(0,101) if i not in P]

if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    l = len(L) - 1


    if (0 < n < l):
        if (L[n+1]-L[n] < L[n] - L[n-1]):
            ANS = L[n+1]
        else:
            ANS = L[n - 1]
    elif (n == l):
        ANS = L[l - 1]

print(ANS)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  p=list(map(int,input().split()))
  c=[0]*100
  for i in p:
    c[i-1]=1
  k=0
  ans=x
  while True:
    if 0<=x-k-1<=99:
      if c[x-k-1]==0:
        ans=x-k
        break
      else:
        if 0<=x+k-1<=99:
          if c[x+k-1]==0:
            ans=x+k
            break
          else:
            k+=1
        else:
          k+=1
    else:
      if 0<=x+k-1<=99:
        if c[x+k-1]==0:
            ans=x+k
            break
        else:
          k+=1
      else:
        ans=x-k
        break
  print(ans)

Submission status: Wrong Answer

Solution code:
X,Y = (map(int, input().split()))
LIST = list(map(int, input().split()))
count=0
for i in range(len(LIST)-1):
    if abs(LIST[i]-LIST[i]) !=1:
        count+=1
print(count)

Submission status: Wrong Answer

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

else:
    p = list(map(int, input().split()))
    abs_list = []
    re_list = []
    min = 1000
    min_index = 0

    for i in range(201):
        abs_list.append(-100+i)
    for j in p:
        abs_list.remove(j)
    for i in range(len(abs_list)):

        re_list.append(abs(abs_list[i] - X))
    for i in range(len(re_list)):
        if min > re_list[i]:
            min = re_list[i]
            min_index = i
    if re_list[min_index] > X:
        print(0)
    else:
        print(abs_list[min_index])

Submission status: Wrong Answer

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

p = set(map(int,input().split()))
not_p = list(set(range(0,100)) - p)

minV = 101
ans = 0
for i in not_p:
    if abs(X - i) < minV:
        minV = abs(X - i)
        
if minV == 101:
    if X < 51:
        ans = 0
    else:
        ans = 101
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P=list(map(int, input().split()))
A=[]
A.append(X)
if N==0:
   print(X)
else:
   for i in range(N):
      A.append(X+(1+(i//2))*(-1)**(i+1))
   for i in range(N):
      if A[i] not in P:
         ans=A[i]
         print(ans)
         break

Submission status: Wrong Answer

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

li = list(map(int, input().split()))
maimai = False
purapura = False
for j in range(n):
    mai = abs(x - j)
    pura = abs(x + j)
    if x - j not in li:
        ans = x - j
        maimai = True

    if x + j not in li:
        ans = x + j
        purapura = True

    if maimai and purapura:
        if mai < pura:
            ans = x - j
            print(ans)
            exit()
        else:
            ans = x + j
            print(ans)
            exit()
    elif maimai or purapura:
        print(ans)
        exit()


print(x)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

l=list(map(int, input().split()))
a = x
b = x

if not x in l:
  print(x)
else:
  for i in range((len(l)-1)//2):
    a -= 1
    b += 1
    if not a in l and not b in l:
      print(a)
      break
    elif a in l and not b in l:
      print(b)
      break
    elif not a in l and b in l:
      print(a)
      break
    else:
      pass
      if i == (len(l)-1)//2 - 1:
        print(a - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np 

X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    l = list(map(int, input().split()))
    l = sorted(l)
    number_list = []
    for i in range(l[-1] * 100):
        number_list.append(i+1)
    for k in l:
        if k in number_list:
            for num, li in enumerate(number_list):
                if li == k:
                    number_list.pop(num)
    number_list.append(X)
    number_list = sorted(number_list)
    for n,b in enumerate(number_list):
        if b == X:
            if np.abs(number_list[n-1] - X) > np.abs(number_list[n+1] - X):
                print(number_list[n+1])
                
            elif np.abs(number_list[n-1] - X) < np.abs(number_list[n+1] - X):
                print(number_list[n+1])
                
            elif np.abs(number_list[n-1] - X) == np.abs(number_list[n+1] - X):
                if number_list[n-1] > number_list[n+1]:
                    print(number_list[n+1])
                elif number_list[n-1] < number_list[n+1]:
                    print(number_list[n-1])

Submission status: Wrong Answer

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

S=[i for i in range(-1,101)]

for j in range(N):
    S.remove(A[j])
    
n=1000  
x=0
for k in S:
    if abs(k - X) < n:
        n=abs(k - X)
        x=k
    elif n == abs(k - X):
        x=min(x,k)
print(x)

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
nums=[int(x) for x in input().split()]
#print(nums)
if n == 0:
	print(x)
	exit()
if x == 1:
	print(0)
	exit()
min=x
gap=x
#print('Here')
for i in range(1,200):
	if i in nums:
		continue
	else:
		if abs(x-i) < gap:
			#print("min: ",min)
			#print(x-i)
			gap=x-i
			min = i
print(min)

Submission status: Wrong Answer

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

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

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

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

if ans == 1000:
    if abs(X - m - 1) <= abs(X + 1):
        ans = m + 1
    else:
        ans = -1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math

x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()

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

p_list.sort()

if p_list[0] > x:
    print(x)
    sys.exit()
elif p_list[0] == x:
    print(x -1)
    sys.exit()

if p_list[-1] < x:
    print(x)
    sys.exit()
elif p_list[-1] == x:
    if p_list[-2] == x-1:
        print(x +1)
    else:
        print(x -1)
    sys.exit()


for i in range(n):
    if p_list[i] == x:
        j = i
        k = 1
        while j <= n-1:
            if p_list[i-k] != x-k and i != 0:
                print(x-k)
                sys.exit()
            elif p_list[i+k] != x+k and i != n-1:
                print(x+k)
                sys.exit()
            
            if p_list[i+k] == p_list[-1]:
                break
            elif p_list[i-k] == p_list[0]:
                break
            j += 1
            k += 1
            
    if p_list[i] > x:
        print(x)
        sys.exit()


#sub = min(abs(p_list[j] - x), abs(p_list[j-1] -x))

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n > 1:
  list = list(map(int, input().split()))
else:
  print(x)
  exit(0)
   
for i in range(n+1):
  if (x-i) not in list:
    print(x-i)
    break
  if (x+i) not in list:
    print(x+i)
    break