Problem:


Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Wrong Answer

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

if N==0:
    _=input()
    print(X)
    
else:
    Ps=list(map(int,input().split()))
    d=0
    while 1:
        d+=1
        if X-d not in  Ps:
            print(X-d)
            break
        elif X+d not in Ps:
            print(X+d)
            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()))
    mylist = list(range(0,101))


    for i in range(N):
        if (p[i] in mylist)==True:
            mylist.remove(p[i])

    mylist2 = list(map(lambda a: abs(a - X), mylist))

    
    p=mylist2.index(min(mylist2))

    print(mylist[p])

Submission status: Wrong Answer

Solution code:
def main():
  X, N = map(int, input().split())
  if N == 0:
    return X
  
  P = list(map(int, input().split()))
  
  delta = []
  for n in range(-1, 102):
    if n in P:
      delta.append(float('inf'))
    else:
      delta.append(abs(X - n))
      
  minD = min(delta)
  for i, d in enumerate(delta):
    if d == minD:
      return i + 1


print(main())

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


ans1=ans2=101
flag=0

for i in range(1,len(p)+1):


    if x+i not in p:
        ans1=x+i
        flag=1
    if x-i not in p:
        ans2=x-i
        flag=1
    if flag==1:
        break


# print(ans1,ans2)
print(min(ans1,ans2))

Submission status: Wrong Answer

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

nyuryoku = []

try:
    while True:
        p = list(map(int,input().split()))
        if p == '':
            break
        nyuryoku.append(p)

except EOFError:
    pass

# for p in nyuryoku:
#     print(p)

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

L = []
for i in range(1, 50):
    for j in ['-', '']:
        # print(j, i)
        a = (j + str(i))
        # print(int(a))
        L.append(a)
# print(L)

if N == 0:
    print(X)
elif X not in p:
    print(X)
else:
    for i in L:
        if (X + int(i)) not in p:
            print(X + int(i))
            break

Submission status: Wrong Answer

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

antip = set(range(-100,101)) - set(p)
dist = 1000
ans = 1000
for v in antip:
    can = abs(v - X)
    if(can < dist):
        dist = can
        ans = v
    if(can == dist):
        ans = min(ans, v)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
X,N=map(int,input().split())
if N==0:
    print(X)
    exit()
P=sorted(list(map(int, input().split())))
key=bisect.bisect_right(P,X)
small=P[-1]
large=P[0]

for i in range(N):
    if P[key-1]-i not in P:
        small=P[key-1]-i
        break
for i in range(N):
    if P[key-1]+i not in P:
        large=P[key-1]+i
        break
print(small if abs(X-small)<=abs(X-large) else large)

Submission status: Wrong Answer

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

else:
    min_abs = 100
    min_abs = min([abs(X-i) for i in range(100) if not i in P])
    min_abs


    ans_candi = [i+X for i in range(-min_abs, min_abs+1) if not i in P]
    ans = min(ans_candi)
    print(ans)

Submission status: Wrong Answer

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

p.sort()
d = 10 ** 9
for i in range(-1000,1000):
    if d > abs(i-x) and i not in p:
        d = abs(i-x)
        ans = i
        print(i)
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
ans = 0
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    s = range(100)
    a = [abs(i + 1 - x) for i in s]
    min_ = x
    for i in range(100):
        if a[i] < min_ and (not i + 1 in p):
            min_ = a[i]
            ans = i + 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() ))

  p.sort()
  q=list(range(-5,101))

  for i in p:
    q.remove(i)

  Z=1000
  ans=-1
  for i in q:
    if( abs(X-i)<Z):
      Z=abs(X-i)
      ans=i
  
  print(ans)

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:
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

  for i in range(1, min(p)):
    if min_abs != 0:
      print(min_e)
      return
    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:
x, n = input().split()
x = int(x)
n = int(n)
m = list(map(int,input().split()))
sa = 999
ans = 0

if x in m == False:
    print(x)
    exit()
elif len(m) == 0:
    print(x)
    exit()

for k in range(1,200):
    if m.count((x - k)) == 0 and x - (x - k) < sa:
        sa =  x - (x - k)
        ans = x - k

for l in range(1,200):
    if m.count((x + l)) == 0 and (x+l) - x < sa:
        sa = (x+l) - x
        ans = x + l

print(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))
print(xdetect)
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:
s = input().split()

x = int(s[0])
n = int(s[1])

s = {i for i in range(-1,102)}

p1 = input().split()

p = set()

for i in p1:
    p.add(int(i))

t = s - p

answer = 20000

for i in t:
    if (x - abs(int(i)) < x - abs(answer)) or (x - abs(int(i)) == x - abs(answer)) and i < answer:
        answer = int(i)

print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = list(map(int,input().split()))
if N == 0:
  input()
  print(X)
else:
  p_arr = list(map(int,input().split()))
  for i in range(101):
    if i == 0:
      if not (X in p_arr):
        print(X)
      else:
          continue
    lower = (X-i in p_arr)
    upper = (X+i in p_arr)
    if not lower:
      print(X-i)
      break
    else:
      if not upper:
        print(X+i)
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    pn = list(map(int, input().split()))
    is_ex_list = [False for i in range(max(pn) + 1)]
    for p in pn:
        is_ex_list[p] = True
    min_v = 101
    min_f = 101
    for i in range(max(pn) + 1):
        if not is_ex_list[i] and abs(x - i) < min_v:
            min_f = i 
            min_v = abs(x - i)
    for i in range(-(max(pn)), 0):
        if abs(x - i) <= min_v:
            if min_v == abs(x - i) and min_f > i:
                min_f = i 
            else:
                min_f = i 
            min_v = abs(x - i)
    print(min_f)

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(100)]
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:
X, N = map(int, input().split())
p_list = list(map(int, input().split()))
all_list = range(-1, 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:
# C - Forbidden List

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

if x==100:
    print(x)
else:
    p = list(map(int, input().split()))
    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 = map(int,input().split())
if n ==0:
  print(x)
  exit()
q = [int(i) for i in input().split()]
for i in range(n):
    if x - i not in q:
        print(x - i)
        exit()
    elif x + i not in q:
        print(x + i)
        exit()

Submission status: Wrong Answer

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

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

    for i in range(n+1):
        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:
import numpy as np
X, N = list(map(int,input().split()))
if N == 0:
  print(X)
else:
  p_arr = list(map(int,input().split()))
  for i in range(101):
    if i == 0:
      if not (X in p_arr):
        print(X)
      else:
          continue
    lower = (X-i in p_arr)
    upper = (X+i in p_arr)
    if not lower:
      print(X-i)
      break
    else:
      if not upper:
        print(X+i)
        break

Submission status: Wrong Answer

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

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	x, n = map(int, sys.stdin.readline().split())
	p = list(map(int, sys.stdin.readline().split()))
	p.sort()
	a = [0]*100
	if n == 0:
		print(x)
		exit()
	if n == 100:
		lower = -1
		upper = 101
		if abs(x - lower) < abs(x - upper):
			print(lower)
		else:
			print(upper)
		exit()
	for i in range(n):
		a[p[i]-1] = 1
	i = x - 1
	log.print(p, i)
	lower = 0
	while i >= 0:
		log.print(i, a[i])
		if a[i] == 0:
			lower = i + 1
			break
		i -= 1
	i = x - 1
	upper = 0
	while i < 100:
		log.print(i, a[i])
		if a[i] == 0:
			upper = i + 1
			break
		i += 1
	if abs(x - lower) == abs(x - upper):
		print(lower)
		exit()
	if abs(x - lower) < abs(x - upper):
		print(lower)
	else:
		print(upper)

main()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
min = 0
min_dis = 10**10
ch = [0 for i in range(101)]
for i in range(len(p)):
    ch[p[i]] = 1
for i in range(1, 101):
    idx = 101-i
    if ch[idx] == 0 and abs(x-idx) <= min_dis :
        min = idx
        min_dis = abs(x-idx)
print(min)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import os
from sys import stdin


def solve(tc):
    x, n = map(int, stdin.readline().split())
    seq = list(map(int, stdin.readline().split()))

    diff = [[0,0] for i in range(100)]
    for num in seq:
        d = x-num
        if d>0:
            diff[d][1] = 1
        else:
            diff[d][0] = 1

    if diff[0][0]==0:
        ans = x
    else:
        for i in range(1,100):
            if not diff[i][0] and x>i:
                ans = x-i
                break
            elif not diff[i][1] and x+i<=100:
                ans = x+i
                break


    print(ans)


tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p=sorted(map(int,input().split()))
diff=101
for i in range(101):
    if i not in p and abs(X-i)<diff:
        diff=abs(X-i)
        ans=i
print(ans)

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 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 = list(map(int,input().split()))
if N == 0:
    print(X)
elif N != 0:
    P = list(map(int,input().split()))
    A = []
    B = []
    a = 1000
    b = 1000
    for i in range(-101,101):
        if i not in P and i <= X:
            A.append(i)
        elif i not in P and i > X:
            B.append(i)
        A = sorted(A,reverse=True)
        B = sorted(B)
    if len(A) != 0:
        a = abs(X - A[0])
    if len(B) != 0:
        b = abs(X - B[0])
    if a < b:
        print(A[0])
    elif b < a:
        print(B[0])
    elif a == b:
        print(A[0])

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=100
                    break
            count1-=1
            count2+=1
        print(ans)

Submission status: Wrong Answer

Solution code:
x,n  = map(int, input().split())
p = list(map(int, input().split()))
if x in p:
    diff = 1000
    index = 0
    for i in range(101):
        if i != x and i not in p:
            if abs(x-i) <diff:
                diff = abs(x-i)
                index = i
    print(index)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

############################

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

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

z=101
p_list = list(map(int,input().split()))
pp_list = [i for i in range(max(p_list)+1)]

for j in p_list:
    pp_list.remove(j)

for k in pp_list:
    zettaiti = abs(x-k)

    if z > zettaiti:
        z = zettaiti
        ans = k

print(ans)

Submission status: Wrong Answer

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

result = 0
if N == 0:
    result = X
else:
    list = [i for i in range(101)]
    for i in P:
        list.remove(i)
    if len(list) == 0:
        result  = 0
    else:
        min = 100
        for i in list:
            if min > abs(X-i):
                min = abs(X - i)
                result = i
print(result)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    X, N = map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    L = []
    for i in range(1, 101):
        if not i in P:
            L.append(i)
    #print(L)
    ans =1000
    ans2 = 0
    for l in L:
        if ans > abs(X-l):
            ans = abs(X-l)
            ans2 = l
    if ans2 <= X:
        print(ans2)
    else:
        print(abs(X-ans2)+X)


if __name__=='__main__':
    main()

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


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

    

    if X+i<=100:
        if l.count(X+i)==0:
         print(X+i)
         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:
#H, W = map(int,input().split())
#N = int(input())
#al = list(map(int,input().split()))
X, N = map(int,input().split())
pl = list(map(int,input().split()))

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

anslst = []
for n in lst:
    if not n in pl:
        anslst.append(n)



an = 101
idx = 0
for i in range(len(anslst)):
    tmp = abs(X - anslst[i])
    if tmp < an:
        an = tmp
        idx = i
    if an == 0:
        ans = anslst[idx]
        print(ans)
        exit()


ans = anslst[idx]
print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
  print(x)
else:
  p.sort()
  m = float("inf")
  if x<int(p[0]) or int(p[n-1])<x:
    print(x)
  else:
    for y in [y for y in range(p[0]-1,p[n-1]) if not y in p]:
      if abs(x-y)<m:
        m = abs(x-y)
        ans_y = y
  print(ans_y)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
ans = 1000
l = []
if n == 0:
  print(x)
else:
  p = list(map(int,input().split()))
  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())
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:
#!/usr/bin/env python3

def main():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
        exit()
    p = set(map(int,input().split()))
    lst = set(range(1,101)) - p
    tmp = 130
    for s in lst:
        if abs(s - X) >= tmp:
            print(prev)
            exit()
        prev = s
        tmp = abs(s - X)

if __name__ == '__main__':
    main()

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

Submission status: Wrong Answer

Solution code:
x,n=list(map(int,input().split()))
if n==0:
  print(x)
  exit()
P=list(map(int,input().split()))
P.append(x)
PP=sorted(P)
if PP.count(x) >= 2:
  print(x)
else:
  i=PP.index(x)
  k=1
  high=None
  low=None
  while k>0:
    if PP.count(x+k)>0:
      high=x+k
    if PP.count(x-k)>0:
      low=x-k
    k-=1
    if low!=None:
      print(low)
      exit()
    elif high!=None:
      print(high)
      exit()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def main():
    x, n = [int(i) for i in input().split()]
    p = set([int(i) for i in input().split()])

    ans = x
    for i in range(1, 101):
        if i in p:
            continue

        if i <= x:
            ans = i
        else:
            if x - ans > i - x:
                ans = i
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
li1 = list(map(int,input().split()))
if n == 0:
    print(x)
    exit()
b=100
c=0
li = []
li = list(range(min(li1),max(li1)))
for ii in range(n):
    if li1[ii] in li:
        li.remove(li1[ii])
for i in range(len(li)):
    a=li[i]
    if a<=x:
        c=a
        if b>x-a:
            b=x-a
            c=a
    else:
        if b>a-x:
            b=a-x
            c=a
print(c)

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()
print(min(P) - 1)

Submission status: Wrong Answer

Solution code:
import sys

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

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

all_list = [int(x) for x in range(0, max(list_p) + 1)]
target_list = sorted(list(set(list_p) ^ set(all_list)))

ans = [abs(num - X) for num in target_list]
# print(all_list)
# print(target_list)
# print(min(ans))
# print(ans.index(min(ans)))
print(target_list[ans.index(min(ans))])

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left,bisect

x,N,*p = map(int,open(0).read().split())
dif = 300
near = 300
all_ = set(range(1,101))

for i in p:
    d = abs(i - x)
    if dif > d:
        dif = d
        near = i
left = list(all_ - set(p))        

dif2 = 300
near = 300
for i in left:
    d = abs(x-i)
    if d < near:
        near = d
        dif2 = i
print(dif2)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
#C - Forbidden List
X,N= map(int,input().split())
p= list(map(int,input().split()))
A= list(range(-100,101))
#print(A)
for i in range(N):
    A.remove(p[i])

D = 201
ans = -100
for j in range(len(A)):
    if D > abs(X - A[j]):
        D = abs(X - A[j])
        ans = A[j]

    else:
        pass
print(ans)

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(100):
        if i not in P:
            differ.append(abs(X - i))
        else:
            differ.append(101)
    ans = differ.index(min(differ))
    print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
P = list(map(int, input().split()))
xm, xp = 201, 201
if P == []:
    print(x)
for i in range(n):
    if x - i not in P:
        xm = abs(x - i)
    if x + i not in P:
        xp = abs(x + i)
    if xm < 201 or xp < 201:
        print(min(xm, xp))
        exit()

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[1:]:
    if abs(x-i) < min_abs:
      min_abs = abs(x-i)
      min_e = i

  for i in range(1, min(p)):
    if min_abs != 0:
      print(min_e)
      return
    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())
p = [ int(x) for x in input().split() ]

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

d = 101

for k in p:
    if d > abs(x - k):
        d = abs(x - k)

for i in range(101):
    if (not x - (d + i) in p) and (x - (d + i) != 0):
        print(x - (d + i))
        sys.exit()
    elif not x + (d + i) in p:
        print(x + (d + i))
        sys.exit()

Submission status: Wrong Answer

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

ans=101
flg=False
if X not in p:
    print(X)
    flg = True
else:
    for i in range(-1,102):
        if i not in p and abs(X-i)<abs(X-ans) and i!=X:
            ans=i
        
if flg==False:
    print(ans)

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

Submission status: Wrong Answer

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

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


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


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

    if ans1 <= ans2:
        print(x1)
    else:
        print(x2)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
ps = sorted(list(map(int, input().split())))
if x not in ps:
    print(x)
else:
    not_ps = [i for i in range(ps[0], ps[-1] + 1) if i not in ps]
    ans = 1000
    ans_min = 1000
    for not_p in not_ps:
        if abs(not_p-x) < ans_min:
            ans = not_p
            ans_min = abs(not_p-x)
    print(ans)

Submission status: Wrong Answer

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

p_list = sorted(p_list)
all_range = list(range(101))
A = [i for i in all_range if i not in p_list]
B = [abs(i - X) for i in A]

low = X - min(B)
high = X + min(B)

if N == 0:
  print(X)
elif low in p_list:
  print(high)
else:
  print(low)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
if n == 0:
    ans = x
else:
    p = sorted(p)
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = 0
    if x < min_p:
        ans = x
    elif x > max_p:
        ans = x
    elif x == min_p:
        ans = min_p-1
    elif x == max_p:
        if max_p-1 == p[len(p)-2]:
            ans = max_p+1
        else:
            ans = max_p-1
    else:
        for i in range(min_p+1, max_p):
            if i == p[j+1]:
                j += 1
            else:
                if abs(ans-x) > abs(i-x):
                    ans = i
print(ans)

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(20):
        if i not in P:
            differ.append(abs(X - i))
        else:
            differ.append(101)
    ans = differ.index(min(differ))
    print(ans)

Submission status: Wrong Answer

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

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

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

for i in p:
    d.remove(i)

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

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

print(d[tmpi])