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 sys
def main():
    x, n = map(int, input().split())
    p = list(map(int,input().split()))
    
    if (n==0):
        print(x)
        sys.exit()

    for i in range(n):
        low = x - i
        if (low not in p):
            print(low)
            sys.exit()
            
        up = x + i
        if (up not in p):
            print(up)
            sys.exit()
    
main()

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(" ")))
  c = -1
  for i in range(100):
    if i+1 not in p:
      if abs(X-(i+1)) < abs(X-c):
        c = i+1
      else:
        print(c)
        exit()

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 1000
l = []
if n == 0:
  print(x)
else:
  for i in range(-100,100):
    if (abs(i - x) < abs(ans - x)) and (i not in p):
      ans = i
  print(ans)

Submission status: Wrong Answer

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

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

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

for i in range(1, 101):
    i1 = x - i
    i2 = x + i
    if i1 not in p:
        print(i1)
        break
    elif i2 not in p:
        print(i2)
        break
    else:
        continue

Submission status: Wrong Answer

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

i = X
ans_small = X
ans_big = X

while(True):
  i = i + 1
  #print("1",i)
  if((i in p_list)==True):
    pass
  else:
    ans_big = i
    break
    
i = X
while(True):
  i = i - 1
  #print("2",i)
  if((i in p_list)==True):
    pass
  else:
    ans_small = i
    break

#print(ans_big,ans_small)
if(abs(X-ans_small)>abs(X-ans_big)):
  print(ans_big)
else:
  print(ans_small)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if(n > 0):
  p = list(map(int, input().split()))
  lists = list(range(101))
  del lists[0]
  sa = []
  for i in lists:
    if(i in p):
      sa.append(999)
    else:
      sa.append(abs(x-i))
    ind = sa.index(min(sa))
    ans = lists[ind]
else :
  ans = x
if (x <= ans - x):
  ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
x,n= map(int, input().split())
if n!=0:
    p = list(map(int, input().split()))
else:
  p=[]
def func(x,n,p):
    if n==0:
        print(x)
        return
    current = x
    for d in range(1,101,1):
        if current-d not in p:
            print(current-d)
            return
        elif current+d not in p:
            print(current+d)
            return
    print(x)
    return
func(x,n,p)

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(1, 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:
from collections import Counter
x,n = map(int,input().split())
p = list(map(int,input().split()))

num_list = list(range(-101,101))
y = (num_list + p)

counter = Counter(y)
result =  [elem for elem in y if counter[elem] < 2]


ans = 10 *100000000000

for i in result:
    temp = abs(i - x)
    if ans > temp:
        ans = temp
        res = i
print(res)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n == 0:
    print(x)
    exit()
lst = [int(i) for i in input().split()]
n_lst = [int(i) for i in range(1,101)]
mn1 = -1
mn2 = -1
for i in range(x-1,99):
    if not(n_lst[i] in lst):
        mn1 = n_lst[i]
        break
n_lst = n_lst[::-1]
for i in range(100 - x, 99):
    if not(n_lst[i] in lst):
        mn2 = n_lst[i]
        break
if mn1 == -1:
    print(mn2)
    exit()
elif mn2 == -1:
    print(mn1)
    exit()
if abs(mn1-x) >= abs(mn2-x):
    print(mn2)
else:
    print(mn1)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
q = []
saidai = 0
if n > 0:
  p = list(map(int,input().split()))
  if x > max(p):
    saidai = x
  else:
    saidai = max(p)
  for i in range(saidai):
    if i+1 not in p: 
      q.append(i+1)
  for i in range(len(q) - 1):
    if abs(x - q[i + 1]) >= abs(x - q[i]):
      print(q[i])
      break
    if i == len(q) - 2:
        print(q[i + 1])
else:
  print(x)

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 = 101
for candidate in range(minimum + 1, 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())
p=list(map(int, input().split()))

a = 100
num = 0

for i in range(101):
    if i not in p:
        b = i-X
        if abs(b) < a:
            a = abs(b)
            num = i

print(num)

Submission status: Wrong Answer

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

    min_val = 0
    diff = abs(x-min_val)
    for i in range(1, 101):
        if diff > abs(x-i) and not(i in p):
            min_val = i
            diff = abs(x-min_val)
        elif diff < abs(x-i) and not(i in p):
            break

    print(min_val)

Submission status: Wrong Answer

Solution code:
X, N = map(int,input().split())
P = list(map(int,input().split()))
ans = 0
def f(X,N,P):
  if(N==0):
    ans = X
    return ans
  else:
    for i in range(N):
      if(not (X-i in P)):
        ans = X-i
        return ans
      elif(not (X+i in P)):
        ans = X+i
        return ans
print(f(X,N,P))

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    quit()
p=list(map(int,input().split()))
p.sort()
if p[-1]<x:
    print(x)
    quit()
ans=[]
#本題
for i in range(p[0],p[-1]+1):
    if i not in p:
        ans.append(i)
ans.append(101)
for i in range(len(ans)):
    if ans[i]>x:
        if abs(x-ans[max(i-1,0)]) <= abs(x-ans[i]):
            print(ans[max(i-1,0)])
        else:
            print(ans[i])
        quit()

Submission status: Wrong Answer

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

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

  min_abs = 101
  min_e = 0
  for i in p:
    if abs(x-i) < min_abs:
      min_abs = abs(x-i)
      min_e = i

  if min_abs != 0:
      print(min_e)
      return
      
  for i in range(1, 100):
    if min_e - i not in p:
      print(min_e - i)
      return
    elif min_e + i not in p:
      print(min_e + i)
      return
    
main()

Submission status: Wrong Answer

Solution code:
import sys

X, N = map(int, input().split(" "))
if N == 0:
    print(X)
    sys.exit(0)
if N == 100:
    sys.exit(0)

P = list(map(int, input().split(" ")))

l = list(range(1, 101))
for p in P:
    l.pop(l.index(p))

dis_min = 1000
n = 1000
for i in l:
    dis = abs(i - X)
    if dis_min >= dis:
        if dis_min == dis:
            if n > i:
                n = i
        else:
            dis_min = dis
            n = i

print(n)

Submission status: Wrong Answer

Solution code:

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



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




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


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

    

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

Submission status: Wrong Answer

Solution code:
# coding:utf-8
x, n = map(int, input().split())
p = list(map(int, input().split()))


if n == 0:
    print(x)
else:
    ps = sorted(p)
    tmp = list(range(-201, 200))
    ans_list = list(set(tmp) ^ set(ps))
    ans_list = sorted(ans_list)
    # print(tmp, ans_list)
    diff = []

    for i in ans_list:
        diff.append(abs(i - x))

    print(ans_list)
    print(diff)
    print(min(diff))
    print(ans_list[diff.index(min(diff))])

Submission status: Wrong Answer

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

px = x + 1
mx = x - 1
if n == 0:
    print(x)
    exit()

while True:
    if mx not in p:
        print(mx)
        exit()
    elif px not in p:
        print(px)
        exit()
    px += 1
    mx -= 1

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ar1 = list(range(101))
ar2 = list(set(ar1) - set(p))
ar3 = sorted(ar2, reverse = True)
diff = 100
for i in ar3:
  if abs(x - i) <= diff:
    diff = abs(x - i)
    ans = i
  else:
    break

print(ans)

Submission status: Wrong Answer

Solution code:
# C - Forbidden List

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

if n==0:
    print(x)
else:    
    if x not in p:
        p.append(x)
    for i in range(100):
        a = x-(i+1)
        if a not in p:
            print(a)
            break
        b = x+(i+1)
        if b not in p:
            print(b)
            break

Submission status: Wrong Answer

Solution code:
from math import *
from bisect import bisect_left

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def bs(arr, l, r, x): 
    while l <= r: 
        mid = l + (r - l) // 2; 
        if arr[mid] == x: 
            return mid 
        elif arr[mid] < x: 
            l = mid + 1
        else: 
            r = mid - 1
    return -1


def main():
    a,b = cin()
    if b==0:
        c = cino(True)
        print(a)
    else:
        arr = cina()
        arr.sort()
        init = 1
        if bs(arr,0,b-1,a)==-1:
            print(b)
        else:
            o,t = bs(arr,0,b-1,a-init),bs(arr,0,b-1,a+init)
            while o>=0 and t>=0:
                init+=1
                o,t = bs(arr,0,b-1,a-init),bs(arr,0,b-1,a+init)
            if o==-1:
                print(a-init)
            else:
                print(a+init)




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()))
else:
  p=[]
def func(x,n,p):
    if n==0:
        print(x)
        return
    current = x
    for d in range(1,101,1):
        if current-d not in p:
            print(current-d)
            return
        elif current+d not in p:
            print(current+d)
            return
    print(x-101)
    return
func(x,n,p)

Submission status: Wrong Answer

Solution code:
a=input().split(" ")
b=input().split(" ")
c=0
d=0
e=0
f=int(a[0])
g=int(a[0])
if int(a[1])!=0:
	for i in range(int(a[1])):
		if int(a[0])==int(b[i]):
			c=c+1
elif int(a[1])==0:
	print(a[0])

if c>=1:
	while str(f) in b:
		f=f+1
		d=d+1
	while str(g) in b:
		g=g-1
		e=e+1
	if d>e:
		print(g)
	elif e>d:
		print(f)
	elif e==d:
		print(g)

Submission status: Wrong Answer

Solution code:
def forbidden(x,p):
    res = []
    for num in range(101):
        if num not in p:
            if x!=num:
                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:
x,n = [int(i) for i in input().split()]

p = [int(i) for i in input().split()]
p.sort()

k = 1e10

if n == 0: print(x)
else:
    for i in range(p[0],p[-1]):
        if not i in p:
            if abs(x-i) < k: k=abs(x-i)
    if x-k in p: print(x+k)
    else: print(x-k)

Submission status: Wrong Answer

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

  l100 = list(range(101))
  for i in p:
    if i in l100:
      l100.remove(i)
  sa = []
  for i in l100:
    sa.append(abs(x-i))

  idx = sa.index(min(sa))
  print(l100[idx])

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p_list = list(map(int, input().split()))
all_list = range(0, 101)

not_p_list = list(set(all_list)-set(p_list))
ans_list = []

for i in not_p_list:
    j = abs(i - X)
    ans_list.append(j)

# print(ans_list)

ans = min(ans_list)
minus_ans = -1 * ans

#print(ans, minus_ans)

if (minus_ans + X) in not_p_list:
    print(minus_ans + X)
else:
    print(ans + X)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
x = a[0]
n = a[1]
if n>0:
  b = list(map(int,input().split()))
  c = list(range(0,101))
  for i in range(n):
    if b[i] in c:
      c.remove(b[i])
      k = 1000
      kn = 0
  for i in range(100-n):
    if k>abs(x-c[i]):
      k = x-c[i]
      kn = c[i]
  print(kn)
else:
  print(x)

Submission status: Wrong Answer

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

  for i in range(n-2):
    if x-i not in p:
      ans.append(-i)
      print(x-i)
      break
    elif x+i not in p:
      ans.append(i)
      print(x+i)
      break
  if ans == []:
    print(x-n+2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=list(map(lambda i:abs(x-i),p))
p=p+[100000000]
p.sort()
if n==0:
  print(x)
  sys.exit()
for i in range(len(p)):
  if p[i]!=(i+1)//2:
    if i==0:
      print(x)
      sys.exit()
    elif i==1:
      print(x-1)
      sys.exit()
    elif p[i-1]==p[i-2]:
      print(x-p[i-1]-1)
      sys.exit()
    else:
      if x-p[i-1] in p:
        print(x+p[i-1])
      else:
        print(x-p[i-1])
      sys.exit()
print(x)

Submission status: Wrong Answer

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

if N==0:
    print(X)
for i in range(N):
    ans = int(X)-i

    if str(ans) not in P:
        print(ans)
        break
    ans2 = int(X)+i
    if str(ans2) not in P:
        print(ans2)
        break

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))
if p_.count(X) != 0:
  p_.remove(X)
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:
def readInt():
    return list(map(int,input().split()))
    
x,n = readInt()
p = list()
a = []
if n:
    p = readInt()
    p_r = [int(i) for i in range(1,200)]
    for i in p:
        p_r.remove(i)
    # print(p_r)
    
    
    for i in range(200-len(p)-1):
        dif = abs(p_r[i]-x)
        a.append(dif)
    # print(a)
    print(p_r[a.index(min(a))])
else:
    print(0)

Submission status: Wrong Answer

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

def judge(p_,x_):
    p_d = list(set(sorted(map(lambda y: np.abs(x_-y),p_))))
    if p_d == []:
        return x_
    for delta in range(p_d[-1]):
        if delta == 0:
            continue
        if (x_-delta not in p_):
            return x_-delta
        if (x+delta not in p_):
            return x_+delta
    return x_

print(judge(p,x))

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(1, 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 < 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:
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
P = list(map(int, input(). split()))

for n in range(1, (N // 2) + 1):
    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())
p = list(map(int,input().split()))

arr = []
incc = []
for i in range(101):
    for j in range(n):
        incc.append(p[j])
    if i in incc:
        continue
    else:
        arr.append(i)
for i in range(len(arr)):
    if n == 0:
        print(x)
        break
    elif x-i in arr:
        print(x-i)
        break
    elif x+i in arr:
        print(x+i)
        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()))
  absv = x
  value = x
  for i in range(-1, 101):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
    input()
    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
        if up not in li:
            if down == up:
                print(down)
                break
            else:
                print(up)
                break

Submission status: Wrong Answer

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

INF = 999
x_flg = True
x_plus = []
x_minus = []
for i in range(0, n // 2):
    x_plus.append(x+i+1)
    x_minus.append(x-(i+1))

for p_num in p:
    if p_num == x:
        x_flg = False

    if p_num in x_plus:
        x_plus.remove(p_num)

    if p_num in x_minus:
        x_minus.remove(p_num)

if x_flg:
    print(x)
else:
    x_plus_min = min(x_plus) if len(x_plus) > 0 else INF
    x_minus_max = max(x_minus) if len(x_minus) > 0 else INF
    xp = abs(x-x_plus_min)
    xm = abs(x-x_minus_max)
    if xp < xm:
        print(x_plus_min)
    elif xp >= xm:
        print(x_minus_max)

Submission status: Wrong Answer

Solution code:
X, N = map(int,input().split())
P = list(map(int,input().split()))
ans = 0
def f(X,N,P):
  if(N==0):
    ans = X
    return ans
  else:
    for i in range(1,(X+1)//2+1):
      if(not (X-i in P)):
        ans = X-i
        return ans
      elif(not (X+i in P)):
        ans = X+i
        return ans
print(f(X,N,P))

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().strip().split())
s=list(map(int,input().strip().split()))
a=0
b=x-1
c=1
while a==0:
    a=1
    for i in range(n):
        if(b==s[i]):
            a=0
    if(b<x and a==0):
        b+=c*2
    elif(b>x and a==0):
        b-=c
        c+=1
        b-=c
if(len(s)==0):
    print(x)
else:
    print(b)

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 <= 100 :
        c=X+i
    if X-i not in P and X-i >= 1: 
        d=X-i
    if c!=0:
        if d!=0:
            if abs(c-X)==abs(d-X):
                print(min(c,d))
            elif abs(c-X) > abs(d-X):
                print(d)
            else:
                print(c)
        else:
            print(c)
        break
    if d!=0:
        print(c)
        break

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p_d  = [x-int(i) for i in input().split()]
p_sorted = sorted(p_d,key= lambda x: (-x+0.1, x)[x > 0])

l = [x-k for k in range(1,101)]
l_sorted = sorted(l,key= lambda x: (-x+0.1, x)[x > 0])

for i in range(n):
    ans = l_sorted[i]
    if p_sorted[i] != ans:
        print(x-ans)
        break
if n == 0:
    print(x)

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

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

Submission status: Wrong Answer

Solution code:
X,N=map(int, input().split())
ans=0
flag=0
if N!=0:

	P=sorted(list(map(int, input().split())))
	pabs=[]
	for p in P:
		pabs.append(abs(X-p))
	
	pabs.sort()
	
	
	cnt=0
	temp=0
	
	print(pabs)
	if 0 in pabs:
		for i in range(1,max(pabs)+1):
			if i in pabs:
				
				if pabs.count(i)==1:
					if X-i not in P:
						ans=X-i
						flag=1
						break
					else:
						ans=X+i
						flag=1
						break
					
				else:
					continue
				
			else:
				ans=X-1
				flag=1
				break
		
		print(X-max(pabs)-1 if flag==0 else ans)
										
	else:
		print(X)
		
else:
	print(X)

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
valid = [1] *101
p = list(map(int, input().split()))
for i in range(n):
	valid[p[i]] = 0

#print(valid)

for j in range(100):
#	print(x,j,x-j,x+j)
#	print(valid[x-j])
#	print(valid[x+j])
	if((x-j) >= 1):
		if(valid[x-j] == 1):
			print(x-j)
			break
	if((x+j) <= 100):
#		print("aaa")
		if(valid[x+j] == 1):
			print(x+j)

Submission status: Wrong Answer

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

for i in range(100):
  pl = x+i
  mn = x-i
  if x-i>=1 and x-i not in p:
    print(x-i)
    break
  if x+i<=100 and 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()))
sa = float("inf")
for i in range(1, 101):
    if i not in p:
        sa = min(sa, abs(i - x))
if x - sa not in p:
    print(x - sa)
else:
    print(x + sa)

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 i in range(101):
    if X + i not in P:
        if X - i not in P:
            print(X - i)
            exit()
        print(X + i)
        exit()

Submission status: Wrong Answer

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

p = list(map(int, input().split()))
pp = set(p)
numlist = [i for i in range(-1000, 1000)]
numlistt = set(numlist)
newlist = numlistt - pp
newlistt = list(newlist)
absn = 1000
ans = 1000
 
for i in newlistt:
    if absn > abs(X-i):
        ans = i
        absn = abs(X-i)
    elif absn == abs(X-i) and i < ans:
        ans = i
        absn = abs(X-i)

print(ans)
print(newlistt)

Submission status: Wrong Answer

Solution code:
kazulist = []
for i in range(100):
    kazulist.append(i+1)
 
a = list(input().split(" "))
target = int(a[0])
syokyo = int(a[1])

if syokyo != 0:
    b = list(input().split(" "))
    for i in b:
        kazulist.remove(int(i))

#print(kazulist)
 
saisyosa = 100
kotae = 0
for i in kazulist:
    sa = target - int(i)
    if sa < 0:
        sa *= -1
    if sa < saisyosa:
        saisyosa = sa
        kotae = i
 
print(kotae)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
num = list(map(int, input().split()))
back, forward, val1, val2 = 0, 0, 0, 0

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

    for i in range(X, 101):
        if i not in num:
            val2 = i
            forward = abs(i - X)
            break

    if back > forward:
        print(val2)
    else:
        print(val1)

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=list(map(lambda i:abs(x-i),p))
p=p+[100000000]
p.sort()
if n==0:
  print(x)
for i in range(len(p)):
  if p[i]!=(i+1)//2:
    if i==0:
      print(x)
      sys.exit()
    elif i==1:
      print(x-1)
      sys.exit()
    elif p[i-1]==p[i-2]:
      print(x-p[i-1]-1)
      sys.exit()
    else:
      if x-p[i-1] in p:
        print(x+p[i-1])
      else:
        print(x-p[i-1])
      sys.exit()
print(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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])
  #print(not_p)

  min_val = 101
  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())
if N==0: print(X)
else:
    p=list(map(int,input().split()))
    m=10000
    ans=0
    for i in range(-100,100):
        if m>abs((i+1)-X) and (not(i+1 in p)):
            m=abs((i+1)-X)
            ans=i+1
    print(ans)

Submission status: Wrong Answer

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

cnt1 = 0
cnt2 = 0
ans1 = 0
ans2 = 0

for i in range(x,101):
    cnt1 += 1
    if not i in p:
        ans1 = i
        break

for i in range(x,-100,-1):
    cnt2 += 1
    if not i in p:
        ans2 = i
        break

if cnt1 < cnt2:
    print(ans1)
elif cnt1> cnt2:
    print(ans2)
else:
    print(ans2)

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 k - prevk > 1:
      ans = -(prevk + 1)
      break
    elif not v[0]:
      ans = v[1]
      break
    flag = True
    prevk = k
  print(x + ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
oin = input()
x, n = int(oin.split(" ")[0]), int(oin.split(" ")[1])
p = input().split(" ")
xpo = x+1
xdetect = list(range(-10, 101))
if n == 0:
  print(x)
  exit()
if x == 1:
  print(0)
  exit()
def closest(lst, K): 
     lst = np.asarray(lst) 
     idx = (np.abs(lst - K)).argmin()
     return lst[idx]
for b in p:
  try:
    xdetect.remove(int(b))
  except ValueError:
    continue
print(closest(xdetect, x))

Submission status: Wrong Answer

Solution code:
# C - Forbidden List

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

if x==100:
    print(x)
else:    
    if x not in p:
        p.append(x)
    for i in range(100):
        a = x-(i+1)
        if a not in p:
            print(a)
            break
        b = x+(i+1)
        if b not in p:
            print(b)
            break

Submission status: Wrong Answer

Solution code:
X,N=list(map(int,input().split()))
src=list(map(int,input().split()))
all_diff_src = [X-n for n in range(0,101) if n not in src]
ans = 100
for s in all_diff_src:
  if ans > abs(s):
    ans = s
print(X-ans)

Submission status: Wrong Answer

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