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:
"""
int #整数
float #小数

#標準入力
a=input()
a,b=map(int,input().split()) #入力は行ごと
#標準出力
print(a)
ptrint("Hello")
#for
for name in fruits: #fruitの頭から操作
    print(name)
#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト内の2の数
abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値

extension_1 = []
for i in range(10):
    extension_1.append(i)
extension_1
#>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

comprehension_1= [i for i in range(10)]
comprehension_1
#>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
import math
import sys
X,N=map(int,input().split())
if N==0:
    print(X)
    sys.exit()
    
number = list(map(int, input().split()))
sa =[0]*100

    
for i in range(100):
    sa[i]=abs(i+1-X)
    
for j in range(N):
    sa[number[j]-1]=101
        
A=min(sa)
    
for k in range(100):
    if sa[k]==A:
        break
    k=k+1
    
print(k+1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if N == 0:
    print(X)

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
q = []
s = 0
if(n == 0):
  print(x)
else:
  p = list(map(int,input().split()))
  p2 = sorted(p)
  for i in range(p2[0],p2[-1]+2):
    q.append(i)
  ans = set(p) ^ set(q)
  ans1 = list(set(ans))
  ans2 = 10000
  for i in range (len(ans1)):
    ans2 = min(ans2,abs(x-ans1[i]))
  if(abs(x-ans1[i]) == ans2 and ans1[i] > 0):
    for i in range (len(ans1)):
      s = ans1[i]
      break
  if(abs(x-ans1[i]) == ans2 and ans1[i] < 0):
    for i in range (len(ans1)):
      s = ans1[i]
  print(s)

Submission status: Wrong Answer

Solution code:
import sys

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

ans1 = int()
ans2 = int()

p.sort()

if x not in p:
    print(x)
    sys.exit()
if x < p[0]:
    print(x - 1)
    sys.exit()

for i in range(n):
    if x == p[i]:
        for j in range(x + 1, 100):
            if j not in p:
                ans1 = j
                break
        for k in reversed(range(x,)):
            if k not in p:
                ans2 = k
                break

if ans1 - x < x - ans2:
    print(ans1)
else:
    print(ans2)

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 != 0:
    p = [int(i) for i in input().split()]
    ary = [i for i in range(1,101)]
    min = abs(X-ary[0])
    index = ary[0]
    for j in range(N):
        try:
            if p[j] in ary:
                ary.remove(p[j])
        except:
            pass
    for j in range(1,len(ary)):
        if min > abs(X-ary[j]):
            min = abs(X-ary[j])
            index = ary[j]
        elif min < abs(X-ary[j]):
            break
    print(ary)
elif N == 0:
    index = X

print(index)

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
wks = 101
an = 0

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = []
p = list(map(int, input().split()))
i = 0
j = 0
ans = 0
if(n == 0):
    print(x)
for i in range(n):
    X = x + ((-1) ** (i)) * int((i + 1) / 2)
    for j in range(n):
        if(X == p[j]):
            ans = 1
            break
        ans = 0
    if(ans == 0):
        print(X)
        break

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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]
    input_set = set(input_list2_int)

    num_min = min(input_set)
    num_max = max(input_set)
    
    if num_min == num_max:
        if num_min == input_list1_int[0]:
            answer = input_list1_int[0] -1
        else:
            answer = input_list1_int[0]
        
    else:
        if num_min > input_list1_int[0]:
            answer = input_list1_int[0]
        
        elif num_max < input_list1_int[0]:
            answer = input_list1_int[0]
        
        else:
            number_list = list(range(num_min,num_max+1))
            pre_abs = 10000000
        
        
            for i in input_set:
                number_list.remove(i)
    
            if input_list1_int[0] in number_list:
                answer = input_list1_int[0]
    
            else:
                for j in number_list:
                    temp1 = abs(j - input_list1_int[0])
                    if temp1 < pre_abs:
                        pre_abs = temp1
                        answer = j
            
                    else:
                        break
    print(answer)

except:
    print(input_list1_int[0])

Submission status: Wrong Answer

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

    o = list(set(m) - set(p))
    ans = 0
    dif = abs(ans - x)
    for i in range(len(o)):
        if(dif > abs(x-o[i])):
            ans = o[i]
            dif = abs(x-o[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
x, n = map(int, input().split())
if n:
  p = sorted(list(map(int, input().split())))
  idx = bisect.bisect_left(p, x)
  lst = p[idx + 1:]
  if lst:
    for i in lst:
      x += 1
      if not x in lst:
        print(x)
        break
  else:
    lst = reversed(p[:idx + 1])
    for j in lst:
      x -= 1
      if not x in lst:
        print(x)
        break
else:
  print(x)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
try:
    in_li = set(map(int, input().split()))
except:
  	in_li = set()
num_li = list({i for i in range(1,101)} - in_li)

num_li.sort()
res = 0

if n == 0:
    print(x)
elif x not in in_li:
    print(x)
else:
    for i in num_li:
        if abs(x-i) < abs(x-res):
            res = i
    print(res)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N > 0:
  p = list(map(int,input().split()))
a = 102
ans = 0
for i in range(-1,101):
  if N == 0:
    ans = X
    break
  if p.count(i) == 0 and a > abs(X - i):
    a = abs(X - i)
    ans = i
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

int_list = [i for i in range(-100,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):
    if forbidden_list[i] < 0:
      a = abs(X + forbidden_list[i])
      b = abs(X + forbidden_list[i + 1])
    else:
      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

Submission status: Wrong Answer

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

not_in_p = list(range(0,102))
for pn in p:
    if pn in not_in_p:
        not_in_p.remove(pn)

diff_p = []
for not_in_pn in not_in_p:
    diff_p.append(abs(not_in_pn - X))
min_value_index =  [j for j, value in enumerate(diff_p) if value == min(diff_p)]

answer = 0
for index in min_value_index:
    if answer == 0:
        answer = not_in_p[index]
    elif answer > not_in_p[index]:
        answer = not_in_p[index]

print(answer)

Submission status: Wrong Answer

Solution code:
a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 1
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) not in number_list and str(num2) not in number_list:
        print(num2)
        break
      if str(num) in number_list:
        print(num2)
      else:
        print(num)
      break
    n += 1

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(100):
  if i not in P:
    res = abs(X - i)
    list.append(res)
    list2.append(i)
    
maxres = list.index(min(list))
print(list2[maxres])

Submission status: Wrong Answer

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

n = range(1,100)
b=10000

for c1 in range(len(p)):
    for c2 in range( len(n) ):
        if(p[c1] !=n[c2] ):
            if(n[c2] != x):
                if(abs(x-b) > abs(x-n[c2])):
                    b=n[c2]
print(b)

Submission status: Wrong Answer

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

P = list(map(int, input().split()))
ans = ''

for i in range(N):
    if X-i not in P:
        ans = X-i
        break
    elif X+i not in P:
        ans = X+i
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import math 
X, N = map(int,input().split())
d = int(999)
d1 = int()
ans = int(999)
if 0 < N:
    P = list(map(int,input().split()))
    for i in range(1,200):
        if P.count(i) == 0:
            d1 = abs(X-i)
            if d1 < d and 0 <= d1:
                d = d1
                ans = i
    print(ans)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = a[0]

retu = []
for i in range(1,101) :
    retu.append(i)
for i in b :
    if i in retu :
        retu.remove(i)
retu.sort()

k = 1000
ans = i
for i in range(0,len(retu)) :
    y = abs(retu[i] - x)
    if y < k :
        k = y
        ans = retu[i]

print(ans)

Submission status: Wrong Answer

Solution code:
[X, N] = list(map(int, input().split()))
A = []
try:
  P = list(map(int, input().split()))
  list_int = [x for x in range(1, 102)]
  list_int_d = list(set(list_int) - set(P))
  list_int_d.sort()
  for i in list_int_d:
    A.append(abs(X - i))
  if 0 in A:
    print(X)
  else:
    Index = A.index(min(A))
    print(list_int_d[Index])
except EOFError:
  print(X)

Submission status: Wrong Answer

Solution code:
import numpy as np
oin = input()
x, n = int(oin.split(" ")[0]), int(oin.split(" ")[1])
if n == 0:
  print(x)
  exit()
p = input().split(" ")
xpo = x+1
xdetect = list(range(-10, 101))
#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:
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])
  for i in range(1,100):
    if n-i not in lst :
      print(n-i)
      break
    if n+i not in lst:
      print(n+i)
      break

Submission status: Wrong Answer

Solution code:
def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    else:
        p = [int(i) for i in input().split()]

    s = []
    for i in range(101):
        if not i in p:
            s.append(i)
    if not x in p:
        print(x)
        return
    
    t = s + [x]
    t.sort()
    pos = t.index(x)
    try:
        if abs(x-t[pos-1]) <= abs(x-t[pos+1]):
            print(t[pos-1])
            return
        else:
            print(t[pos+1])
    except:
        print(s[-1])
        return

resolve()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n:
    p = {int(i) for i in input().split()}
if n == 0:
    print(x)
else:
    if x not in p:
        print(x)
    else:
        flag = True
        abs_diff = 1
        while flag:
            for i in range(1, 3):
                ans = x + (-1)**i * abs_diff
                if ans not in p:
                    flag = False
                    break
            print(ans)
            abs_diff += 1

Submission status: Wrong Answer

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

for i in range(X):
  if X-i not in p:
    print(X-i)
    break
  elif X+i not in p:
    print(X+i)
    break
  else:
    continue

Submission status: Wrong Answer

Solution code:
import numpy as np
x,n = map(int,input(). split ())
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    num = max(p)
    ans = [0]*(100+1)
    temp = -1
    val2 = 100

    for i in range(1+100):
        temp += 1
        ans[i] = temp
    # for i in range(n):
    #     temp1 =p[i]
    #     ans.remove(temp1)
    ans = list(set(ans) ^ set(p))
    ans.sort()
    # print(ans)

    for i in range(1+100-n):
        val1 = abs(ans[i]-x)
        if val1 < val2:
            val2 = val1
            xx = i

    # print(ans)
    # print(min(ans)) 
    # print(min(ans)+x) 
    print(ans[xx])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if N == 0:
    print(X)
else:
    p = set(map(int, input().split()))

    num = set(range(102))

    l = list(num.difference(p))

    ans = 0
    absol = 101

    for i in l:
        a = abs(X - i)
        if a == 0:
            pass
        elif a < absol:
            absol = a
            ans = i
        else:
            pass

    print(ans)

Submission status: Wrong Answer

Solution code:
INF=200

def near_abs(minp,P):
    d=0
    while True:
      val=minp-d
      if 1<=val and val not in P:
        return val
      val=minp+d
      if val<=100 and val not in P:
        return val
      d+=1

X,N=map(int,input().split())
if N==0:
  print(X)
else:
  *p,=map(int,input().split())
  dp = [INF]*N
  dp[0]=abs(p[0]-X)
  minp=p[0]
  for i in range(1,N):
    dp[i]=abs(p[i]-X)
    if dp[i]<dp[i-1]:
      minp=p[i]
  print(near_abs(minp,p))

Submission status: Wrong Answer

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

#if int(n) == 0:
   ## exit()
result = x
sa = 100
count = 0
for l in range(1,101):
    if l in p:
        continue
    
    if sa <= abs(x-l):
        result = count 
        break
    count = l
    sa = abs(x -l)
print(result)

Submission status: Wrong Answer

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

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

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

allList=[]

for i in range(-100,201):
    allList.append(i)

diff = set(allList) ^ set(p)



diff = list(diff)
diff.append(x)
diff = sorted(diff)

# print(diff)

ind = diff.index(x)
# print(ind)

# if x == 100:
    

a = diff[ind-1]
b = diff[ind+1]
# print(a,b)

ax = abs(x-a)
bx = abs(x-b)

# print(ax,bx)

if ax==bx:
    if a < b:
        print(a)
    else:
        print(b)

if ax > bx:
    print(b)
else:
    print(a)

Submission status: Wrong Answer

Solution code:
from sys import stdin
X, N = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
if N == 0 or X not in P:
    ans = X
else:
    i = True
    k = True
    a = X
    b = X
    while i:
        a += 1
        i = a in P
    while k:
        b -= 1
        k = b in P
    if X - a == X - b:
        if a > b:
            ans = b
        else:
            ans = a
    else:
        if  X - a > X - b:
            ans = b
        else:
            ans = a
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()))
    q = list(range(101))
    a = 1000
    aa = 0
    for i in range(x, 0, -1):
        aa = aa + 1
        if p.count(i) == 0:
            a = i
            break

    b = 1000
    bb = 0
    for i in range(x, 101):
        bb = bb + 1
        if p.count(i) == 0:
            b = i
            break
            
    if aa == 1 and bb == 1:
        print(x)
    elif aa <= bb:
        print(a)
    elif bb < aa:
        print(b)
    else:
        print(a)

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)
if c==0:
	print(a[0])

Submission status: Wrong Answer

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

result = X

try:
    p = set(map(int, input().split()))
    if X not in p:
        result = X
    else:
        for i in range(1, len(p)):
            if X - i not in p:
                result = X - i
                break
            elif X + i not in p:
                result = X + i
                break
    print(result)
except:
    print(result)

Submission status: Wrong Answer

Solution code:
import sys
import bisect

def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())


def main():
  X,N = LI()[:]
  if N > 0:
    P = LI()
    P.sort()
  else:
    print(X)
    exit()
    
  index = bisect.bisect_left(P, X)
  #print("index=",index)
  if index >= N :
    print(X)
    exit()
    
  l = index
  r = index
  for i in range(0,200):
    up = X + i
    down = X - i
    
    #print("l=",l,"r=",r)
    
    if l < 0:
      print(down)
      break
    
    if r >= N:
      print(up)
      break
     
    # Left優先
    if P[l] != down:
      print(down)
      break
     
    if P[r] != up:
      print(up)
      break
    
    l -= 1
    r += 1
    
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import os
import sys
from io import BytesIO, IOBase
import math
import bisect

def inputIntArray():
    return list(map(int, input().rstrip().split()))


def inputArray():
    return input().rstrip().split()


def inputVars():
    return map(int, input().rstrip().split())


def inputNum():
    return int(input())


def main():
    x, n = inputVars()
    if n == 0:
        print(x)
        return
    arr = inputIntArray()
    minRes = x
    arr.sort()
    if arr[0] >= x:
        print(x-1)
    else:
        for num in range(-x+1, 2*x):
            pos = bisect.bisect_left(arr, num)
            if pos == len(arr) or arr[pos] != num:
                minRes = min(abs(num-x), minRes)
    print(minRes)


#.........................................FAST INPUT OUTPUT.......................................
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#....................................END OF FAST I/O............................................

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 = sorted(
        [[i, abs(i - x)] for i in range(101) if i not in P],
        key=lambda x:x[1])

else:
    Q = sorted(
        [[i, abs(i - x)] for i in range(101)],
        key=lambda x:x[1])

dist = Q[0][1]
print(min([q[0] for q in Q if q[1] == dist]))

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

    o = list(set(m) - set(p))

    ans = 100000
    dif = abs(ans - x)
    for i in range(len(o)):
        if(dif > abs(x-o[i])):
            ans = o[i]
            dif = abs(x-o[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 10**18
l = []
if n == 0:
  print(x)
elif x not in p:
  print(x)
else:
  for i in range(0,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 = list(map(int, input().split()))
answer = 100
for m in range(0,102):
    if not(m in p) and abs(answer-X) > abs(m-X):
        answer = m
print(answer)

Submission status: Wrong Answer

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

if N == 0:
  print(X)
  sys.exit()
  
if X == 100 and N == 100:
  print(-100)
  sys.exit()
  
  
P = list(map(int, input().split()))

lis = []
for i in range (-100,101,1):
    if i not in P:
        lis.append(i)


        
        
        
ans = 10**18
suzi = 0
lis2 = []
for j in lis:
    num = abs(X-j)
    if num < ans:
        ans = num
        suzi = j

print(suzi)

Submission status: Wrong Answer

Solution code:
import math 
X, N = map(int,input().split())
d = int(999)
d1 = int()
ans = int(999)
if 0 < N:
    P = list(map(int,input().split()))
    for i in range(1,100):
        if P.count(i) == 0:
            d1 = abs(X-i)
            if d1 < d and 0 <= d1:
                d = d1
                ans = i
    print(ans)
else:
    print(X)

Submission status: Wrong Answer

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

def main():
    if len(p) == 0:
        print(x)
        return

    ans_l = list(range(1, 100))

    diff_l = list(set(p) ^ set(ans_l))
    diff_l.sort()

    cnt = 100
    ans = 100
    for i in range(0, len(diff_l)):
        check = abs(diff_l[i]-x)
        if check < cnt:
            cnt = check
            ans = diff_l[i]
    print(ans)
    return

main()

Submission status: Wrong Answer

Solution code:

x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    #for i in range(n):
    #    p.append(input().split())
    #print(p)
    #rint(type(p[0]))
    min = 1e9
    ans = 0
    for i in range(100):
        i = i + 1
        if i in p:
            continue
        sa = abs(x - i)
        #print(sa)
        if min > sa :
            min = sa
            ans = i
if n == 0:
    print(x)
elif n == 100:
    if x >= 51:
        print(101)
    else:
        print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x, n = map(int, readline().split())
if n == 0:
    print(x)
    exit()
p = set(map(int, readline().split()))

l = []
ans = x
tmp = 110
for i in reversed(range(0, 101)):
    if i not in p:
        if tmp >= abs(x - i):
            tmp = abs(x - i)
            l.append(i)
            ans = i
print(min(l))

Submission status: Wrong Answer

Solution code:
a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 1
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) not in number_list and str(num2) not in number_list:
        print(num2)
      if str(num) in number_list:
        print(num2)
      else:
        print(num)
      break
    n += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n == 0:
    print(x)

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

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

    if x not in p:
        print(x)
    else:
        off = -1
        for i in range(200):
            k = x + off
            if k not in p:
                print(k)
                break
            if off < 0:
                off = off * -1 + 1
            else:
                off = off * -1 - 1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = a[0]

retu = []
for i in range(1,101) :
    retu.append(i)
for i in b :
    if i in retu :
        retu.remove(i)
k = 1000
ans = i
for i in range(0,len(retu)) :
    y = abs(retu[i] - x)
    if y < k :
        k = y
        ans = retu[i]

print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
P = list(map(int, input().split()))
sortP = sorted(P)
if N==0:
    print(X)
elif sortP[0]>X:
    print(X)
elif sortP[N-1]<X:
    print(sortP[N-1]+1)
else:
    for n in range(sortP[0]-2,sortP[N-1]+2):
        if n in sortP:
            continue
        if n ==X:
            print(X)
        elif n>X:
            if X-a<=n-X:
                print(a)
                break
            else:
                print(n)
                break
        a = n

Submission status: Wrong Answer

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

def main():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
        exit()
    p = set(map(int,input().split()))
    if N == 100:
        print(0 if X<=50 else 101)
        exit()
    lst = list(set(range(1,101)) - p)
    lst2 = [abs(lst[i] - X) for i in range(len(lst))]
    min_ = min(lst2)
    print(lst[lst2.index(min_)])    



if __name__ == '__main__':
    main()

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

comp = 101
for i in range(100):
    x = abs(X - i)
    if comp > x and i not in p:
        comp = x
        result = i

print(result)

Submission status: Wrong Answer

Solution code:
x, n = [int(x) for x in input().split()]
if n != 0:
    p = sorted([int(x) for x in input().split()])
    if p == list(range(min(p), max(p)+1)) and x in p:
        tn = p[0]
        tp = p[len(p) - 1]
    else:
        tn = x
        tp = x
    while True:
        if tn in p or tp in p:
            tn -= 1
            tp += 1
            if tn not in p:
                print(tn)
                break
            elif tp not in p:
                print(tp)
                break
else:
    print(x)