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:
# coding: utf-8
# Your code here!

import numpy as np

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

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

m = np.array(list(range(-100,200)))
m = (m-x)**2
for i in (np.argsort(m)-100):
    if p.count(i) == 0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = sorted(list(map(int, input().split())))
    ok = [i for i in range(p[0]-1, p[-1]+1) if i not in p]
    ix = np.argmin(list(map(lambda a: abs(X-a), ok)))
    print(ok[ix])

Submission status: Wrong Answer

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

import numpy as np

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

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

m = np.array(list(range(-100,200)))
m = (m-x)**2
for i in (np.argsort(m)-101):
    if p.count(i) == 0:
        print(i)
        break

Submission status: Wrong Answer

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

import numpy as np

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

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

m = np.array(list(range(-100,200)))
m = (m-x)**2
print(m)
for i in (np.argsort(m)-101):
    if p.count(i) == 0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = sorted(list(map(int, input().split())))
    ok = [i for i in range(p[0]-1, p[-1]+1) if i not in p]
    print(ok)
    ix = np.argmin(list(map(lambda a: abs(X-a), ok)))
    print(ok[ix])

Submission status: Wrong Answer

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

import numpy as np

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

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

m = np.array(list(range(1,101)))
m = (m-x)**2

for i in (np.argsort(m)+1):
    if p.count(i) == 0:
        print(i)
        break

Submission status: Wrong Answer

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

import numpy as np

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

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

m = np.array(list(range(1,101)))
m = (m-x)**2

for i in (np.argsort(m)+1):
    if i not in p:
        print(i)
        break

Submission status: Wrong Answer

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

import numpy as np

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

if n == 0:
    print(x)
    
else:
    p = list(map(int,input().split()))
    
    m = np.array(list(range(1,101)))
    m = (m-x)**2

    for i in (np.argsort(m)+1):
        if i not in p:
            print(i)
            break

Submission status: Wrong Answer

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

import numpy as np

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

if n == 0:
    print(x)
    
else:
    p = list(map(int,input().split()))
    
    m = np.array(list(range(1,101)))
    m = (m-x)**2

    for i in (np.argsort(m)+1):
        if i not in p:
            print(i)

Submission status: Wrong Answer

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

import numpy as np

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

if n == 0:
    print(x)
    
else:
    p = list(map(int,input().split()))
    m = np.array(list(range(1,101)))
    m = (m-x)**2
    
    for i in np.argsort(m):
        if i+1 not in p:
            print(i+1)
            break

Submission status: Wrong Answer

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

import numpy as np

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

if n == 0:
    print(x)
    
else:
    p = list(map(int,input().split()))
    m = np.array(range(1,101))
    m = (m-x)**2
    for i in np.argsort(m)+1:
        if i not in p:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
if N > 0: 
    P = list(map(int,input().split()))
    direction = -1
    i = 1
    while True:
        dist = i * direction
        val = dist+X
        if not (val in P):
            print(val)
            break
        if direction < 0: direction = 1
        else : 
            direction = -1
            i+=1
else: 
    print(X)

Submission status: Wrong Answer

Solution code:
import numpy as np
def getNearestValue(Q, num):
    idx = np.abs(np.asarray(Q) - num).argmin()
    return Q[idx]

XN = list(map(int,input().split()))
X = XN[0]
N = XN[1]
if N == 0:
    print(X)
else:
    P = list(map(int,input().split()))
    Q = list(range(0, 101, 1))
    for i in range(0,N):
        Q.remove(P[i])
    print(getNearestValue(Q,X))

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
p=list(map(int,input().split()))
l=list(range(1,102))
for i in p:
    l.remove(i)
ans=100
min_num=1000
for i in range(len(l)):
    if abs(l[i]-x)<min_num:
        min_num=abs(l[i]-x)
        ans=l[i]
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
pN = [i for i in range(101) if i not in p]
pNm = [abs(i - x) for i in pN]
pmin = min(pNm)
print(pN[pNm.index(pmin)])

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans, mind = -1, 200
for i in range(101):
    if mind > abs(i - X) and i not in P:
        mind = abs(i - X)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N>0:
  P = list(map(int, input().split()))
  P = [i for i in range(-1, 101) if i not in P]
  for i in range(len(P)-1):
    if abs(X-P[i])<=abs(X-P[i+1]):
      print(P[i])
      break
  else:
      print(P[-1])
else:
  print(X)

Submission status: Wrong Answer

Solution code:
X, N = map(int,input().split())
if N == 0:
    print(X)
    exit()
a = list(map(int,input().split()))
cnt = 1
while 1:
  b,c = X-cnt,X+cnt
  if b not in a:
    print(b)
    break
  elif c not in a:
    print(c)
    break
  else:
    cnt += 1

Submission status: Wrong Answer

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

	for i in range(n+1):
		if x - i in p:
			print(x-1)
			break
		if x + i in p:
			print(x+1)
			break
else:
	print(x)

Submission status: Wrong Answer

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

X,N = MI()

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

P = LI()

_min = 10**9
ans = []
for p in range(-100,101):
    if p in P:
        continue

    if abs(X-p) == _min:
        ans.append(p)
    elif abs(X-p) < _min:
        _min = abs(X-p)
        ans = []
        ans.append(p)

print(min(ans))

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
a = list(map(int, input().split()))
candicate = []
for i in range(101):
  exist = False
  for d in a:
    if i == d:
      exist = True
      break
  if exist == False:
    candicate.append(i)

for j in range(len(candicate) - 1):
  if candicate[j] == x or candicate[j + 1] == x:
    print(x)
    break
  elif candicate[j] < x and x < candicate[j+1]:
    if abs(candicate[j] - x) <= abs(candicate[j+1] - x):
      print(candicate[j])
    else:
      print(candicate[j+1])

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p = list(map(int,input().split()))
#print(p)
ans = 200
for i in range(1,201):
    #print(i)
    if i not in p:
        #print("False")
        if abs(ans-X) > abs(X-i):
            ans = i
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p_l = list(map(int, input().split()))
    p_x_l = sorted([ abs(i-x) for i in p_l ])
    idx = 0
    for i in p_x_l:
        if i != idx:
            if x-idx not in p_l:
                print(x-idx)
                break
            else:
                print(x+idx)
                break
        idx += 1
    if idx-1 == len(p_x_l):
        print(x)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p_l = list(map(int, input().split()))
p_x_l = [ abs(i-x) for i in p_l ]

idx = 0
for i in p_x_l:
    if i != idx:
        if x-i not in p_l:
            print(x-i)
            break
        else:
            print(x+i)
            break
    idx += 1
if idx-1 == len(p_x_l):
    print(x)

Submission status: Wrong Answer

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

ret = 0
i = 0
if n==0:
    ret = x
else:
    while True:
        i+=1
        ret = x-i
        if( not ret in l):
            break
        ret = x+i
        if( not ret in l):
            break
print(ret)

Submission status: Wrong Answer

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

ret = 0
i = 0
while True:
    i+=1
    ret = x-i
    if( not ret in l):
        break
    ret = x+i
    if( not ret in l):
        break
print(ret)

Submission status: Wrong Answer

Solution code:
import numpy as np
X,N=map(int,input().split())
p=np.array(list(map(int,input().split())))
ans=np.array([X,X])
while True:
  ans+=[-1,1]
  if ans[0] not in p:
    print(ans[0])
    exit()
  if ans[1] not in p:
    print(ans[1])
    exit()

Submission status: Wrong Answer

Solution code:
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    cand = []
    for i in range(101):
        cand.append(i)
    for i in range(len(cand)):
        for j in range(n):
            if cand[i] == p[j]:
                cand[i] = 100000
    mini = 100
    for i, c in enumerate(cand):
        if mini > abs(c-x):
            ans = i
            mini = abs(c-x)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def function(ar1, ar2):
    if ar1[1]==0:
        return 0

    pm=ar1[0]
    nm=ar1[0]
    i=0
    while i<len(ar2)**9:

        pm+=1
        nm-=1
        if pm and nm not in ar2:
            if pm<nm:
                return pm

            else:
                return(nm)
        if pm not in ar2:
            return (pm)

        if nm not in ar2:
            return (nm)
        i+=1



if __name__ == '__main__':
    ar1=list(map(int, input().rstrip().split()))
    x=ar1[0]

    ar2 = list(map(int, input().rstrip().split()))
    print(function(ar1, ar2))

Submission status: Wrong Answer

Solution code:
def function(ar1, ar2):
    if ar1[1]==0:
        return 0

    pm=ar1[0]
    nm=ar1[0]
    i=0
    while i<len(ar2)*2:

        pm+=1
        nm-=1
        if pm and nm not in ar2:
            if pm<nm:
                return pm

            else:
                return(nm)
        if pm not in ar2:
            return (pm)

        if nm not in ar2:
            return (nm)
        i+=1



if __name__ == '__main__':
    ar1=list(map(int, input().rstrip().split()))
    x=ar1[0]

    ar2 = list(map(int, input().rstrip().split()))
    print(function(ar1, ar2))

Submission status: Wrong Answer

Solution code:
def function(ar1, ar2):

    pm=ar1[0]
    nm=ar1[0]
    i=0
    while i<len(ar2)*2:
        if ar1[1]==0:
            print(ar1[0])
            break
        pm+=1
        nm-=1
        if pm and nm not in ar2:
            if pm<nm:
                print(pm)
                break
            else:
                print(nm)
                break
        if pm not in ar2:
            print(pm)
            break
        if nm not in ar2:
            print(nm)
            break
        i+=1



if __name__ == '__main__':
    ar1=list(map(int, input().rstrip().split()))
    x=ar1[0]

    ar2 = list(map(int, input().rstrip().split()))
    function(ar1, ar2)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
elif n == 100:
    print(min(abs(101-x),abs(0-x)))
else:
    mp = set(range(1,101))
    p = set(list(map(int,input().split())))
    lp = list(mp-p)
    sub_lp = [abs(i-x) for i in lp]
    print(lp[sub_lp.index(min(sub_lp))])

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
elif n == 100:
    print(min(abs(101-x),abs(-1-x)))
else:
    mp = set(range(1,101))
    p = set(list(map(int,input().split())))
    lp = list(mp-p)
    sub_lp = [abs(i-x) for i in lp]
    print(lp[sub_lp.index(min(sub_lp))])

Submission status: Wrong Answer

Solution code:

def q3():
    x, N = [int(i) for i in input().split(" ")]
    if N != 0:
        P = [int(i) for i in input().split(" ")]
    else:
        P = []

    ans = 100
    for i in range(-1, 100):
        if i in P:
            continue
        if abs(x - i) == abs(x - ans):
            if i < ans:
                ans = i
        if abs(x - i) < abs(x - ans):
            ans = i

    print(ans)


q3()

Submission status: Wrong Answer

Solution code:

def q3():
    x, N = [int(i) for i in input().split(" ")]
    if N != 0:
        P = [int(i) for i in input().split(" ")]
    else:
        P = []

    ans = 100
    for i in range(1, 101):
        if i in P:
            continue
        if abs(x - i) == abs(x - ans):
            if i < ans:
                ans = i
        if abs(x - i) < abs(x - ans):
            ans = i

    print(ans)


q3()

Submission status: Wrong Answer

Solution code:
from sys import stdin
x, n = [int(x) for x in stdin.readline().rstrip().split()]

hundred = [int(s) for s in range(1,101)]

ps = [int(s) for s in stdin.readline().rstrip().split()]
ps.sort()

def answer():
    for i in range(len(ps)):
        hundred[ps[i] - 1] = 100
    for i in range(len(hundred)):
        if hundred[i] - x < 0:
            hundred[i] = (hundred[i] - x) * (-1)
        else:
            hundred[i] -= x
    print(1 + hundred.index(min(hundred)))


#answer()

if n == 0:
    print(x)
else:
    answer()
    #print(hundred)

Submission status: Wrong Answer

Solution code:
from sys import stdin
x, n = [int(x) for x in stdin.readline().rstrip().split()]

hundred = [int(s) for s in range(1,101)]

ps = [int(s) for s in stdin.readline().rstrip().split()]
ps.sort()

def answer():
    for i in range(len(ps)):
        hundred[ps[i] - 1] = 100
    for i in range(len(hundred)):
        if hundred[i] - x < 0:
            hundred[i] = (hundred[i] - x) * (-1)
        else:
            hundred[i] -= x
    print(1 + hundred.index(min(hundred)))


#answer()

if n == 0:
    print(x)
else:
    answer()
    print(hundred)

Submission status: Wrong Answer

Solution code:
from sys import stdin
x, n = [int(x) for x in stdin.readline().rstrip().split()]

hundred = [int(s) for s in range(1,101)]
ps = [int(s) for s in stdin.readline().rstrip().split()]
ps.sort()

def answer():
    for i in range(len(ps)):
        hundred[ps[i] - 1] = 0
    for i in range(len(hundred)):
        if hundred[i] - x < 0:
            hundred[i] = (hundred[i] - x) * (-1)
        else:
            hundred[i] -= x
    print(1 + hundred.index(min(hundred)))
"""
print(hundred)
answer()
"""
if n == 0:
    print(x)
else:
    answer()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 1000
jugh = 1000
for i in range(0, 150):
    if abs(x-i) <= jugh and i not in p:
        jugh = abs(x-i)
        ans = i
    # print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 1000
jugh = 1000
for i in range(0, 150):
    if abs(x-i) <= jugh and i not in p:
        jugh = abs(x-i)
        ans = i
    # print(ans)
print(jugh)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    # x in [1, 100]
    # n in [0, 100]
    # p_i in [1, 100] 
    x, n = (int(i) for i in input().split())
    if n > 0:
        p = set(int(i) for i in input().split())
    else:
        p = set() 

    b, e = x, x
    while b not in p and e not in p:
        b -= 1
        e += 1

    if b in p:
        print(b)
    else:
        print(e)


main()

Submission status: Wrong Answer

Solution code:
def main():
    # x in [1, 100]
    # n in [0, 100]
    # p_i in [1, 100] 
    x, n = (int(i) for i in input().split())
    if n > 0:
        p = [int(i) for i in input().split()]
    else:
        p = []

    mask = [0] * 101 
    for pe in p:
        mask[pe] = 1

    b, e = x, x

    while True:
        if (b >= 1 and mask[b] == 0) or (e <= 100 and mask[e] == 0):
            break
        b -= 1
        e += 1

    if b >= 1 and mask[b] == 0:
        print(b)
    else:
        print(e)



main()

Submission status: Wrong Answer

Solution code:
def main():
    # x in [1, 100]
    # n in [0, 100]
    # p_i in [1, 100] 
    x, n = (int(i) for i in input().split())
    if n > 0:
        p = [int(i) for i in input().split()]
    else:
        p = []

    mask = [0] * 101 
    for pe in p:
        mask[pe] = 1

    b, e = x, x

    while True:
        if (b >= 0 and mask[b] == 0) or (e <= 100 and mask[e] == 0):
            break
        b -= 1
        e += 1

    if b >= 0 and mask[b] == 0:
        print(b)
    else:
        print(e)



main()

Submission status: Wrong Answer

Solution code:
def main():
    # x in [1, 100]
    # n in [0, 100]
    # p_i in [1, 100] 
    x, n = (int(i) for i in input().split())
    if n > 0:
        p = [int(i) for i in input().split()]
    else:
        p = []

    mask = [0] * 101 
    for pe in p:
        mask[pe] = 1

    b, e = x, x

    # no point in going off the end
    while True:
        if mask[b] == 0 or mask[e] == 0:
            break
        b = max(0, b-1)
        e = min(e+1, 100)

    if mask[b] == 0:
        print(b)
    else:
        print(e)

main()

Submission status: Wrong Answer

Solution code:
def main():
    x, n = (int(i) for i in input().split())
    if n > 0:
        p = [int(i) for i in input().split()]
    else:
        p = []

    mask = [0] * 101 
    for pe in p:
        mask[pe] = 1

    b, e = x, x

    while True:
        if b >= 1 and mask[b] == 0:
            break
        b -= 1
        if e <= 100 and mask[e] == 0:
            break
        e += 1

    if mask[b] == 0:
        print(b)
    else:
        print(e)

main()

Submission status: Wrong Answer

Solution code:
def main():
    x, n = (int(i) for i in input().split())
    if n > 0:
        p = [int(i) for i in input().split()]
    else:
        p = []

    mask = [0] * 101 
    for pe in p:
        mask[pe] = 1

    b, e = x, x
    while mask[b] == 1 and mask[e] == 1:
        b -= 1
        e += 1
        b = max(0, b)
        e = min(100, e)

    if mask[b] == 0:
        print(b)
    else:
        print(e)



main()

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = set(map(int,input().split()))
if not N:
    print(N)
else:
    for i in range(X+1):
        if X-i not in P:
            print(X-i)
            break
        elif X+i not in P:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = set(map(int,input().split()))
if not N:
    print(N)
else:
    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

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = set(map(int,input().split()))
if not N:
    print(N)
else:
    for i in range(1,N):
        if X-i not in P:
            print(X-i)
            break
        elif X+i not in P:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
k,n=map(int,input().split())
if(n==0):
    print(k)
else:
  l=sorted(list(map(int,input().split())))
  a=[]
  a.append(k)
  for i in range(1,(n//2+1)+1):
        a.append(k-i)
        a.append(k+i)
  sorted(a)
  for i in range(n):
    if(l[i] in a):
        continue
    else:
         if(i!=n-1):
             print(min(a[i],a[i+1]))
             break
         else:
             print(a[i])
             break

Submission status: Wrong Answer

Solution code:
k,n=map(int,input().split())
if(n==0):
    print(k)
else:
  l=sorted(list(map(int,input().split())))
  a=[]
  a.append(k)
  for i in range(1,n):
    a.append(k-i)
    a.append(k+i)
  if(n%2==0):
    a.pop(-1)
  for i in range(n):
    if(l[i] in a):
        continue
    else:
         if(i!=n-1):
             print(min(a[i],a[i+1]))
             break
         else:
             print(a[i])
             break

Submission status: Wrong Answer

Solution code:
# C Forbidden List

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:
tar,n= map(int,input().split(' '))
if(n==0):
    print(tar)
else:
    lis=sorted(list(map(int,input().split(' '))))
    idx=0
    ans=101
    vidx=lis[0]
    m=101
    while(idx<n):
        if(vidx==lis[idx]):
            idx+=1
            vidx+=1
        elif(vidx<lis[idx]):
            if(abs(vidx-tar)<m):
                m=abs(vidx-tar)
                if(ans>vidx):
                    ans=vidx
            vidx+=1
    if(ans==101):
        print(tar)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
tar,n= map(int,input().split(' '))
if(n==0):
    print(tar)
else:
    lis=sorted(list(map(int,input().split(' '))))
    idx=0
    ans=0
    vidx=lis[0]
    m=101
    while(idx<n):
        if(vidx==lis[idx]):
            idx+=1
            vidx+=1
        elif(vidx<lis[idx]):
            if(abs(vidx-tar)<m):
                m=abs(vidx-tar)
                ans=vidx
            vidx+=1
    if(ans==101):
        print(tar)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

x, N = map(int,input().split())
if N != 0:
    P = list(map(int,input().split()))
    L = [i for i in range(-100, 101)]

    l = list(set(P)^set(L))
    dis = 10**9
    
    for a in l:
        dis_ = abs(x-a)
        if dis_ < dis:
            ans = a
            dis = dis_
else:
    ans = x


print(ans)

Submission status: Wrong Answer

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

q = [i for i in Z if i not in p]
t = []

for i in range(0, len(q)):
    t.append(abs(int(X)-q[i]))

print(q[(t.index(min(t)))])

Submission status: Wrong Answer

Solution code:
import math

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

ans = -1
dif = 10000
for i in range(101):
    if i in p:
        continue
    else:
        if abs(x - i) < dif:
            ans = i
            dif = abs(x - i)

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

ans = -1
dif = 10000
for i in range(1,101):
    if i in p:
        continue
    else:
        if abs(x - i) < dif:
            ans = i
            dif = abs(x - i)

print(ans)

Submission status: Wrong Answer

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

min_num = float('inf')
min_diff = float('inf')

for i in inv:
    if abs(X - i) < min_diff:
        min_diff = abs(X - i)
        min_num = i

print(min_num)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
S=map(int, input().split())
K=(list(range(0,101)))
for i in S:
    K.remove(i)
L=[]
for i in K:
    L.append(abs(x-i))
m=min(L)
ind_m=L.index(m)
print(K[ind_m])

Submission status: Wrong Answer

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

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

upper_ans = 0

for i in range(x, 101):
    if not (i in ps):
        upper_ans = i
        break

lower_ans = 0

for j in reversed(range(0, x + 1)):
    if not (j in ps):
        lower_ans = j
        break

if (upper_ans == 0) and (lower_ans == 0):
    ans = 0
elif abs(x - upper_ans) < abs(x - lower_ans):
    ans = upper_ans
elif abs(x - upper_ans) > abs(x - lower_ans):
    ans = lower_ans
else:
    ans = min(upper_ans, lower_ans)

print(ans)

Submission status: Wrong Answer

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

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

upper_ans = x

for i in range(x, 101):
    if not (i in ps):
        upper_ans = i
        break

lower_ans = x

for j in reversed(range(0, x + 1)):
    if not (j in ps):
        lower_ans = j
        break

if lower_ans == 0:
    ans = 0
elif abs(x - upper_ans) < abs(x - lower_ans):
    ans = upper_ans
elif abs(x - upper_ans) > abs(x - lower_ans):
    ans = lower_ans
else:
    ans = min(upper_ans, lower_ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import random

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

P = input().split()
P = [int(c) for c in P]

if len(P) == 0:
    print(X)    
else:
    L = list(range(max(0,X-N),min(101,X+N)))

    if X+N <= 100:
        L.append(X+N)

    for i in range(N):
        if P[i] in L:
            L.remove(P[i])

    while len(L) > 2:
        rand = random.randint(1,len(L)-2)
        if L[rand] == X:
            break
        elif L[rand] > X:
            L = L[0:rand+1]
        else:
            L = L[rand:len(L)]

    if X in L:
        print(X)
    elif len(L) == 1:
        print(L[0])
    else:
        if abs(L[0]-X) > abs(L[1]-X):
            print(L[1])
        else:
            print(L[0])

Submission status: Wrong Answer

Solution code:
X,N=map(int, input().split())
p=list(map(int, input().split()))
 
ans1=100
ans=0
if N==0:
    print(X)
else:
    for i in range(101):
        if i in p:
            continue
        elif abs(X-i)<ans1:
            ans =i
            ans1 = abs(X-i)
    print(ans)

Submission status: Wrong Answer

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

ans1=100
ans=0
if N==0:
    print(X)
else:
    for i in range(100):
        if i in p:
            continue
        elif abs(X-i)<ans1:
            ans =i
            ans1 = abs(X-i)
    print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
tmp = 101
ans = 101
for i in range(-100, 101):
    if i not in p:
        if tmp == abs(X-i):
            if ans > i:
                ans = i
        elif tmp >= abs(X-i):
            ans = i
            tmp = abs(X-i)
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
tmp = 101
ans = 101
for i in range(1, 101):
    if i not in p:
        if tmp == abs(X-i):
            if ans > i:
                ans = i
        elif tmp >= abs(X-i):
            ans = i
            tmp = abs(X-i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
X, N = map(int, input().split(' '))
if N < 1:
    sys.exit()
P = list(map(int, input().split(' ')))
P.sort()
A = X
B = X
CA = -1
CB = -1
while True:
    A += 1
    B -= 1
    try:
        if P.index(A):
            CA = -1
    except:
        CA = A
    try:
        if P.index(B):
            CB = -1
    except:
        CB = B
    if(-1 < CB):
        ans = CB
        break
    if(-1 < CA):
        ans = CA
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import heapq
import math
import random
import sys
input = sys.stdin.readline

x, n = map(int, input().split())
p = set(map(int, input().split()))
res = 100
for i in range(201, -101, -1):
    if i in p:
        continue
    if abs(i - x) < abs(res - x) or (abs(i - x) == abs(res - x) and i < res):
        res = i
print(res)

Submission status: Wrong Answer

Solution code:
import collections
import heapq
import math
import random
import sys
input = sys.stdin.readline

x, n = map(int, input().split())
p = set(map(int, input().split()))
res = 100
for i in range(100, -101, -1):
    if i in p:
        continue
    if abs(i - x) < abs(res - x) or (abs(i - x) == abs(res - x) and i < res):
        res = i
print(res)

Submission status: Wrong Answer

Solution code:
import collections
import heapq
import math
import random
import sys
input = sys.stdin.readline

x, n = map(int, input().split())
p = set(map(int, input().split()))
res = 100
for i in range(100, 0, -1):
    if i in p:
        continue
    if abs(i - x) < abs(res - x) or (abs(i - x) == abs(res - x) and i < res):
        res = i
print(res)

Submission status: Wrong Answer

Solution code:
L, R = map(int,input().split())
huga = list(map(int, input().split()))
han=101
bb=101
print(huga)
for i in huga:
    if abs(L-i)==han and i<bb:
        bb=i
        han=abs(L-1)
    if abs(L-i)<han:

        bb=i

        han=abs(L-i)
print(bb)

Submission status: Wrong Answer

Solution code:
#input from user X and N
#input from user p
#print the number that is nearest to X but not included in p
#if N = 0, p doesn't have to be taken, only X will be printed
#time complexity O(n)

X,N = [int(x) for x in input().split()]
p = [int(x) for x in input().split()[:N]]


a = X + 1
b = X - 1
if a < b :
    if a not in p:
        print(a)

elif b < a:
    if b not in p:
        print(b)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
judge = 102*[1]
if N==0: # if n == 0 exit
	print(X)
	exit()
 
P = list(map(int, input().split())) # peratte the p into a list
for i in range(N):
	judge[P[i]] = 0
 
upcnt = 0 # initalize the count
while judge[X+upcnt]==0:
	upcnt+=1 #increament the count
 
downcnt = 0

# Time complixity O(N)

Submission status: Wrong Answer

Solution code:
def find_smallest_num(lst):
	X=lst[0]
	for i in range(len(lst)):
		if lst[i]<X: X=lst[i]
	return X