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 math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

X, N = na()
p = na()
kouho = []
for i in range(-100, 101):
    if i in p:
        continue
    kouho.append((abs(X - i), i))
print(min(kouho)[1])

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

X, N = na()
p = na()
res = inf
ans = inf
for i in range(1, 101):
    if i in p:
        continue
    kouho = abs(X - i)
    if res <= kouho:
        break
    else:
        res = kouho
        ans = i
print(ans)

Submission status: Wrong Answer

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

a = 100
b = 0
for i in range(0, 101):
    if i not in p and abs(x - i) < a:
        a = abs(x - i)
        b = i

print(b)

Submission status: Wrong Answer

Solution code:
import sys

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

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

if x not in p:
    print(x)
    sys.exit()
    
q=list(i for i in range(p[0]-1,p[-1]+1))

for i in p:
    q.remove(i)

ans=[]
c=x+n
for i in q:
    if c>abs(x-i):
        c=abs(x-i)
        ans.clear()
        ans.append(i)
    if c==abs(x-i):
        ans.append(i)

print(min(ans))

Submission status: Wrong Answer

Solution code:
import sys

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

if n==0:
    print(x)
    sys.exit()
    
q=list(i for i in range(p[0]-1,p[-1]+1))

for i in p:
    q.remove(i)

ans=[]
c=x+n
for i in q:
    if c>abs(x-i):
        c=abs(x-i)
        ans.clear()
        ans.append(i)
    if c==abs(x-i):
        ans.append(i)

print(min(ans))

Submission status: Wrong Answer

Solution code:

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



if l:
    max_n = max(l)
else:
    max_n = 0

result = x
for i in range(100):
    if x in l:
        pass
    else:
        result = x
        break

    if x - i in l:
        pass
    else:
        if x - i >= 0:
            result = x - i
            break

    if x + i in l:
        pass
    else:
        if x + i <= 100:
            result = x + i
            break



print(result)

Submission status: Wrong Answer

Solution code:

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



if l:
    max_n = max(l)
else:
    max_n = 0

result = x
for i in range(101):
    if x in l:
        pass
    else:
        result = x
        break

    if x - i in l:
        pass
    else:
        if x - i >= 0:
            result = x - i
            break

    if x + i in l:
        pass
    else:
        if x + i <= 100:
            result = x + i
            break



print(result)

Submission status: Wrong Answer

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



if l:
    max_n = max(l)
else:
    max_n = 0

result = x
for i in range(max_n):
    if x in l:
        pass
    else:
        result = x
        break

    if x - i in l:
        pass
    else:
        if x - i >= 0:
            result = x - i
            break

    if x + i in l:
        pass
    else:
        if x + i <= max_n:
            result = x + i
            break

    

print(result)

Submission status: Wrong Answer

Solution code:

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



if l:
    max_n = max(l)
else:
    max_n = 0

result = x
for i in range(max_n):
    if x in l:
        pass
    else:
        result = x
        break


    if x + i in l:
        pass
    else:
        if x + i <= max_n:
            result = x + i
            break

    if x - i in l:
        pass
    else:
        if x - i >= 0:
            result = x - i
            break


print(result)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

x, n = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]

tmp = 0
tmp_2 = inf
res = 0

P = deque(sorted(P))
if P:
    tmp = P.popleft()

for i in range(1, 101):
    if i == tmp:
        if P:
            tmp = P.popleft()
    elif abs(i - x) < tmp_2:
        tmp_2 = abs(i - x)
        res = i

print(res)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
try:
  a=sorted([*map(int,input().split())])
except:
  print(x);exit()
if x not in a:
  print(x)
else:
  m,k=x+1,x-1
  m_true,k_true=False,False
  while True:
    if m not in a:
      m_true = True
      break
    else:
      m+=1
    if k not in a:
      k_true = True
      break
    else:
      k-=1
    if m_true or k_true:
      break
  if m_true:
    while True:
      if k not in a:
        k_true = True
        break
      else:
        k-=1
      if k_true:
        break
    print([m,k][abs(x-m)-abs(x-k)>0])
  elif k_true:
    while True:
      if m not in a:
        m_true = True
        break
      else:
        m+=1
      if m_true:
        break
    print([k,m][abs(x-m)-abs(x-k)>0])

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
try:
  a=sorted([*map(int,input().split())])
except:
  print(x);exit()
if x not in a:
  print(x)
else:
  m,k=x+1,x-1
  m_true,k_true=False,False
  while True:
    if m not in a:
      m_true = True
      break
    else:
      m+=1
    if k not in a:
      k_true = True
      break
    else:
      k-=1
    if m_true or k_true:
      break
  if m_true:
    while True:
      if k not in a:
        k_true = True
        break
      else:
        k-=1
      if k_true:
        break
    print([m,k][abs(x-m)-abs(x-k)>=0])
  elif k_true:
    while True:
      if m not in a:
        m_true = True
        break
      else:
        m+=1
      if m_true:
        break
    print([k,m][abs(x-m)-abs(x-k)>=0])

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
num1=0
num2=0
if(n==0):
    print(x)
    exit()
for i in range(n):
    num1=x-i
    num2=x+i
    if(not num1 in p and not num2 in p):
        print(num1)
        exit()
    elif(num1 in p and not num2 in p):
        print(num2)
        exit()
    elif(not num1 in p and num2 in p):
        print(num1)
        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()))
p.sort()
t=0
while True:
  if x-t in p and x+t in p:
    t+=1
  elif x-t in p and x+t not in p:
    print(x+t)
    exit()
  elif x-t not in p:
    print(x-1)
    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()))
p.sort()
t=0
while True:
  if x-t in p and x+t in p:
    t+=1
  elif x-t in p and x+t not in p:
    print(x+t)
    exit()
  elif x-t not in p and x+t in p:
    print(x-1)
    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()))
p.sort()
#print(p[lb],p[ub])
t=0
while True:
  if x-t in p and x+t in p:
    t+=1
  elif x-t in p and x+t not in p:
    print(x+t)
    exit()
  elif x-t not in p and x+t in p:
    print(x-1)
    exit()
  else:
    print(x-1)
    exit()

Submission status: Wrong Answer

Solution code:
import bisect
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=list(map(int,input().split()))
p.sort()
lb=bisect.bisect_left(p,x)
ub=bisect.bisect_right(p,x)
#print(p[lb],p[ub])
t=0
while True:
  if p[lb]-t in p and p[lb]+t in p:
    t+=1
  elif p[lb]-t in p and p[lb]+t not in p:
    print(p[lb]+t)
    exit()
  elif p[lb]-t not in p and p[lb] in p:
    print(p[lb]-1)
    exit()
  else:
    print(p[lb]-1)
    exit()

Submission status: Wrong Answer

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

Q = [0]*N
R = [0]*N

if N == 0:
    print(X,'d')
    exit()

for i,p in enumerate(P):
    Q[i] = (abs(p - X))
    R[i] = p - X

# print(Q)

flg = 0
key = 0
for i in range(N):
    if i in Q and flg == 0:
        flg = 1
        continue
    elif i in Q and flg == 1:
        continue
    elif i not in Q and flg == 0:
        continue
    else:
        key = i

for i in range(i+1):
    # print(i,'i','',-i,'-i')
    # print('R',R)
    if -i not in R:
        print(X - i)
        exit()
    elif i not in R:
        print(X + i)
        exit()

Submission status: Wrong Answer

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

Q = [0]*N
R = [0]*N

if N == 0:
    print(X,'d')
    exit()

for i,p in enumerate(P):
    Q[i] = (abs(p - X))
    R[i] = p - X

# print(Q)

flg = 0
key = 0
for i in range(N):
    if i in Q and flg == 0:
        flg = 1
        continue
    elif i in Q and flg == 1:
        continue
    elif i not in Q and flg == 0:
        continue
    else:
        key = i

for i in range(1,i+1):
    # print(i,'i','',-i,'-i')
    # print('R',R)
    if -i not in R:
        print(X - i)
        exit()
    elif i not in R:
        print(X + i)
        exit()

Submission status: Wrong Answer

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

min_val = 101
for i in range(101):
    if i not in p:
        if abs(i - x) < min_val:
            min_val = 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()))
ans=0
judge=101
for i in range(-101,101):
  if not i in P:
    if abs(X-i)<judge:
      ans=i
      judge=abs(X-i)

print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
ans=0
judge=101
for i in range(1,101):
  if not i in P:
    if abs(X-i)<judge:
      ans=i
      judge=abs(X-i)

print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
flg=False
i=1

if N==0:
  Ans=X
else:
  S=list(map(int, input().split()))
#  S.sort()
  while not flg:
    if X-i not in S:
      Ans=X-i
      flg=True
      break
    elif X+i not in S:
      Ans=X+i
      flg=True
      break
    else:
      i+=1
      
print(Ans)

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):
    if X - i not in p:
      print(X - i)
      break
    elif X + i not in p:
      print(X + i)
      break
else:
  print(X)

Submission status: Wrong Answer

Solution code:
X,N = (int(x) for x in input().split())
p = sorted(list((int(x) for x in input().split())))
if N == 0:
  print(X)
elif N == 1:
  if p[0] == X:
    print(X-1)
  else:
    print(X)
else:
  ans = float('inf')
  for z in range(0,p[0]):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  for i in range(N-1):
    for z in range(p[i]+1,p[i+1]):
      if (ans-X)**2 > (z-X)**2 :
      	ans = z
  for z in range(p[-1]+1,101):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  print(ans)

Submission status: Wrong Answer

Solution code:
X,N = (int(x) for x in input().split())
p = sorted(list((int(x) for x in input().split())))
if N == 0:
  print(X)
elif N == 1:
  if p[0] == X:
    print(X-1)
  else:
    print(X)
else:
  ans = float('inf')
  for z in range(1,p[0]):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  for i in range(N-1):
    for z in range(p[i]+1,p[i+1]):
      if (ans-X)**2 > (z-X)**2 :
      	ans = z
  for z in range(p[-1]+1,100):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  print(ans)

Submission status: Wrong Answer

Solution code:
X,N = (int(x) for x in input().split())
p = sorted(list((int(x) for x in input().split())))
if N == 0:
  print(X)
elif N == 1:
  if p[0] == X:
    print(X-1)
  else:
    print(X)
else:
  ans = float('inf')
  for z in range(1,p[0]):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  for i in range(N-1):
    for z in range(p[i]+1,p[i+1]):
      if (ans-X)**2 > (z-X)**2 :
      	ans = z
  for z in range(p[-1],100):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  print(ans)

Submission status: Wrong Answer

Solution code:
X,N = (int(x) for x in input().split())
p = sorted(list((int(x) for x in input().split())))
if N == 0:
  print(X)
elif N == 1:
  if p[0] == X:
    print(X-1)
  else:
    print(X)
else:
  ans = float('inf')
  for z in range(1,p[0]):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  for i in range(N-1):
    for z in range(p[i]+1,p[i+1]):
      if (ans-X)**2 > (z-X)**2 :
      	ans = z
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())

def main():
    X, N = i_map()
    if N == 0:
        print(X)
        exit()
    P = i_list()
    p = list(map(lambda x: abs(x - X), P))
    p.sort()
    for i, j in enumerate(p, 1):
        if i // 2 != j:
            ans = X - (i // 2)
            if ans in P:
                ans = X + (i // 2)
            break
    else:
        if N % 2 == 1:
            ans = X - ((N - 1) // 2)
        else:
            ans = X - (N // 2)
            if ans in P:
                ans = X + (N // 2)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

count = 0

flg = False

result=0

while True:
    
    down = X+count
    
    up = X-count
    
    lis = [0]
    
    if p.count(down) ==0:
        lis[0] = down
        flg = True
    
    if p.count(up)==0:
        lis.append(up)
        flg = True
        
    
    if flg ==True:
        break
    else:
        count+=1
        

if len(lis)>=2:
    lis.sort()
    result = lis[0]
else:
    result = lis[0]
        
    
print(result)

Submission status: Wrong Answer

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

sa_min=100

"""
sa=[]
for i in range(N):
    sa.append(p[i]-X)
"""

for i in range(101):
    if sa_min>abs(i-X) and (not i in p):
        sa_min=abs(i-X)
        ans=i

if N==0:ans=X

print(ans)

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(1,101):
    if x-i not in p:
      print(x-i)
      break
    elif x+i not in p:
      print(x+i)
      break
else:
  print(x)

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(1,100):
    if x-i not in p:
      print(x-i)
      break
    elif x+i not in p:
      print(x+i)
      break
else:
  print(x)

Submission status: Wrong Answer

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

if N ==0 or X < min(p) or X > max(p):
    print(X)
else:
    for n in range(N):
        if not X - n in p:
            print(X - n)
            break
        elif not X + n in p:
            print(X + n)
            break

Submission status: Wrong Answer

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


for i in range (50):
  for j in p:
    if j == x-i:
      dc+=1
    if j == x+i:
      pc+=1
  if dc == 0:
    print(x-i)
    exit()
  elif pc == 0:
    print(x+i)
    exit()

Submission status: Wrong Answer

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


for i in range (50):
  pc = 0
  dc = 0
  for j in p:
    if j == x-i:
      dc+=1
    if j == x+i:
      pc+=1
  if dc == 0:
    print(x-i)
    exit()
  elif pc == 0:
    print(x+i)
    exit()

Submission status: Wrong Answer

Solution code:
#C問題

#ループ処理をスキップするコード→break,continue,return(関数方式)
x, n = map(int, input().split())
P = list(map(int, input().split()))
xm = x 
xM = x

for i in range(0,50):
    if n == 0:
        print(x)
        break
    xm = x - i
    xM = x + i
    mcounter = 0
    Mcounter = 0
    for j in range(len(P)):
        if xm == P[j]:
            mcounter += 1000
        if xM == P[j]:
            Mcounter += 1000
    if mcounter < 1000:
        print(xm)
        break
    if Mcounter < 1000:
        print(xM)
        break

Submission status: Wrong Answer

Solution code:
#C問題

#ループ処理をスキップするコード→break,continue,return(関数方式)
x, n = map(int, input().split())
P = list(map(int, input().split()))
xm = x 
xM = x

for i in range(0,3):
    if n == 0:
        print(x)
        break
    xm = x - i
    xM = x + i
    mcounter = 0
    Mcounter = 0
    for j in range(len(P)):
        if xm == P[j]:
            mcounter += 1000
        if xM == P[j]:
            Mcounter += 1000
    if mcounter < 1000:
        print(xm)
        break
    if Mcounter < 1000:
        print(xM)
        break

Submission status: Wrong Answer

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

min =10000
temp = 0

for i in range(-1000, 1000):
  temp = abs(x- i)
  
  if temp < min and i not in p:
    min = temp
    
print(min)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
    print (x)
else:
    p = [int(v) for v in input().split()]
    if len(p) == 1:
        if p[0] < x:
            print (p[0] + 1)
        elif p[0] == x:
            print (p[0] - 1)
        else:
            print (p[0] - 1)
    else:
        pmax = max(p)
        pmin = min(p)
        maxV = pmax + 1
        minV = pmin - 1
        for i in range(x + 1, pmax + 1):
            if i not in p:
                # print(i)
                maxV = i
                break
        for j in range(x - 1, pmin - 1, -1):
            if j not in p:
                minV = j
                break
        if abs(x - (minV)) < abs(maxV - x):
            print (minV)
        elif abs(x - (minV)) == abs(maxV - x):
            print (minV)
        else:
            print(maxV)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = [int(v) for v in input().split()]
    pmax = max(p)
    pmin = min(p)
    maxV = pmax + 1
    minV = pmin - 1
    for i in range(x + 1, pmax + 1):
        if i not in p:
            # print(i)
            maxV = i
            break
    for j in range(x - 1, pmin - 1, -1):
        if j not in p:
            minV = j
            break
    if abs(x - (minV)) < abs(maxV - x):
        print (minV)
    elif abs(x - (minV)) == abs(maxV - x):
        print (minV)
    else:
        print(maxV)

Submission status: Wrong Answer

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

p.sort()

def main():

    if len(p) == 0:
        print(X)
        return

    if X < p[0] and p[-1] < X:
        print(X)

    keep = True
    i = 1
    while keep:
        left_found = (X - i) not in p
        right_found = (X + i) not in p

        if left_found and right_found:
            print(X-i)
            keep = False
        elif left_found:
            print(X-i)
            keep = False
        elif right_found:
            print(X+i)
            keep = False


        i += 1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if n == 0:
    print(m)
    exit()
else:
    pp = list(range(0, max(p)+1))
    ppp = list(filter(lambda x: x not in p, pp))
    pppp = list(map(lambda x: abs(x-m), ppp))
    print(ppp[pppp.index(min(pppp))])

Submission status: Wrong Answer

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

for d in range(m+1):
    for i in [-1,1]:
        a = m + i*d
        if p.count(a==0):
            print(a)
            exit()

Submission status: Wrong Answer

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

if n == 0:
    print(m)
    exit()
else:
    pp = list(range(min(p)-1, max(p)+1))
    ppp = list(filter(lambda x: x not in p, pp))
    pppp = list(map(lambda x: abs(x-m), ppp))
    print(ppp[pppp.index(min(pppp))])

Submission status: Wrong Answer

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

if n == 0:
    print(m)
    exit()
else:
    pp = list(range(0, max(p)+1))
    ppp = list(filter(lambda x: x not in p, pp))
    print(ppp)
    pppp = list(map(lambda x: abs(x-m), ppp))
    print(ppp[pppp.index(min(pppp))])

Submission status: Wrong Answer

Solution code:
x ,n = map(int,input().split())
p = list(map(int,input().split()))
mylist = []
anslist = []
for i in range(100):
    if i in p:
        pass
    else:
        mylist.append(i)
test = sorted(mylist)
for i in mylist:
    ans = abs(x - i)
    anslist.append(ans)
if p == []:
    print(x)
else:
    num = anslist.index(min(anslist))
    print(test[num])

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())))
#print(p)
m=min(p)-1
M=max(p)+1
#for i in range(m,M+1):
#  p.append(i)
#p=sorted(p)
m=X;i=0
for i in range(m,min(p)-2,-1):
  if i not in p:break
M=X;j=0
for j in range(M,max(p)+2):
  if j not in p:break

print(min(i,j))

Submission status: Wrong Answer

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

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

    P_exist = [False] * (101)
    for p in P:
        P_exist[p] = True

    if not P_exist[X]:
        print(X)
        return
    
    for i in range(1, 10000):
        if X-i >= 0 and (not P_exist[X-i]):
            print(X-i)
            return
        if X+i <= 100 and (not P_exist[X+i]):
            print(X+i)
            return

main()

Submission status: Wrong Answer

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

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

    P_exist = [False] * (101)
    for p in P:
        P_exist[p] = True

    if not P_exist[X]:
        print(X)
        return
    
    for i in range(1, 200):
        # if X-i >= 0 and X+i <= 100 and (not P_exist[X-i]) and (not P_exist[X+i]):
        #     print(X-i)
        #     return
        if X-i >= 0 and (not P_exist[X-i]):
            print(X-i)
            return
        if X+i <= 100 and (not P_exist[X+i]):
            print(X+i)
            return

main()

Submission status: Wrong Answer

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

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

    P_exist = [False] * (101)
    for p in P:
        P_exist[p] = True

    if not P_exist[X]:
        print(X)
        return
    
    for i in range(1, 200):
        if X-i >= 0 and X+i <= 100 and (not P_exist[X-i]) and (not P_exist[X+i]):
            print(X-i)
            return
        if X-i >= 0 and (not P_exist[X-i]):
            print(X-i)
            return
        if X+i <= 100 and (not P_exist[X+i]):
            print(X+i)
            return

main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    X,N=MI()
    P=set(LI())

    for i in range(N):
        if(X-i not in P):
            print(X-i)
            return 
        if(X+i not in P):
            print(X+i)
            return
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
y=x
z=x
if x not in p:
    print(x)
    exit()
for i in range(2*len(p)):
    y-=1
    z+=1
    if y not in p:
        print(y)
        print('owari')
        exit()
    if z not in p:
        print(z)
        print('owari')
        exit()

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
if N == 0:
    print(X)
else:
    count = 0
    ans = 0
    while True:
        count +=1
        if X-count not in p:
            ans = X-count
            break
        elif X+count not in p:
            ans = X+count
            break
    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()))
    count = 0
    ans = 0
    while True:
        count +=1
        if X-count not in p:
            ans = X-count
            break
        elif X+count not in p:
            ans = X+count
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=[int(y) for y in input().split()]
a=0
for i in range(101):
  if x-a not in p and x-a>0:
    print(x-a)
    break
  elif x+a not in p and x-a<101:
    print(x+a)
    break
  a+=1

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
nums = list(map(int,input().split()))
cnt =0
while True:
  cnt +=1
  if x-cnt not in nums:
    print(x-cnt)
    break
  if x+cnt not in nums:
    print(x+cnt)
    break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
s = []
if n == 0:
  print(x)
else:
  a = sorted(list(map(int, input().split())))
  for i in range(n):
    s.append(abs(a[i] - x))
  b = a[s.index(min(s))]
  print(b)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
s = []
if n == 0:
  print(x)
else:
  a = list(map(int, input().split()))
  for i in range(n):
    s.append(abs(a[i] - x))
  print(min(s))

Submission status: Wrong Answer

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

max_num = max(p)
lst = []
for i in range(max_num+2):
  if i not in p:
    lst.append(i)
tmp = float("inf")
for j in lst:
  if tmp > abs(X-j):
    tmp = abs(X-j)
    ans = j
print(ans)

Submission status: Wrong Answer

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

max_num = max(p)
lst = []
for i in range(max_num+2):
  if i not in p:
    lst.append(i)
tmp = float("inf")
print(lst)
for j in lst:
  if tmp > abs(X-j):
    tmp = abs(X-j)
    ans = j
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int,input().split())
P = list(map(int,input().split()))
list = [0] * 101
res = X
dist = 102
for p in P:
    list[p] = 1
for i in range(101):
    if list[i] == 0:
        if abs(i - X) < dist:
            dist = abs(i - X)
            res = i
        elif abs(i - X) == dist:
            res = min(res,i)
print(res)