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:
    print(X)
else:
    P = list(map(int, input().split()))
    for i in range(1,1000):
        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:
"""
6 5
4 7 10 6 
"""
x,n = map(int, raw_input().split(' '))

ais = map(int, raw_input().split(' ')) if n else []
ais.sort()


def f(x, u, v):
	#returns the number thats closest to x within range u,v not including u and v
	if u + 1 == v: return (+float('inf'), +float('inf'))
	if u < x < v: return (0,x) 	
	if x >= v: return (abs(x - (v -1)), v-1)
	if x <= u: return (abs(x - (u +1)), u + 1)
res = (+float('inf'), +float('inf'))
ais = [-1] + ais + [101]
for u,v in zip(ais,ais[1:]):
	res = min(res , f(x,u,v))

print res[1]

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

  p.sort()
  q=list(range(1,max(p)+1))

  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:
X, N = map(int, input().split())
P =  set(map(int, input().split()))
Nums = set(range(0, 101))
Nums = Nums - P
sorted(Nums)
print(P)


minNum = 99999
minIndex = 0
for n in Nums:
    if minNum == abs(X-n):
        break
    if abs(X - n)< minNum:
        minNum = abs(X-n)
        minIndex = n

print(minIndex)

Submission status: Wrong Answer

Solution code:
def main():
    x, n = [int(v) for v in input().split(' ')]
    if n == 0:
        print(int(x))
        return

    lst_p = [int(v) for v in input().split(' ')]
    lst_p.sort()

    d = x
    ans = 0
    continueous_n = 1
    for p in lst_p:
        if p == continueous_n:
            continueous_n = p + 1
            continue
        for i in range(p - continueous_n):
            tmp = abs(x - (continueous_n + i))
            if tmp < d:
                d = tmp
                ans = continueous_n + i
            else:
                print(int(ans))
                return
        continueous_n = p + 1
    print(int(ans))


if __name__ == '__main__':
    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:
    print(x)
    exit()
elif len(m) == 0:
    exit()

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

for l in range(1,100):
    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:
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_ = 50000
    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())
import sys
if n==0:
    _=input()
    print(x)
    sys.exit()
    
p_list=list(map(int,input().split()))
r=list(range(101))
a=list(set(r)-set(p_list))
ans=100000
kkk=100000
for i in a:
    tem=abs(i-x)
    if ans>tem:
        ans=tem
        kkk=i
    
print(kkk)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if (N == 0):
  print(X)
else:
  nums = list(map(int, input().split()))
    
  nums.sort()
  low = nums[0]
  high = nums[-1]
  minDiff = 100000000
  minNum = -1
  for i in range(1, 101):
    if i in nums:
      continue
    else:
      Dif = abs(X-i)
    if (Dif < minDiff):
      minDiff = Dif
      minNum=i

  if (minNum == -1):
    print(X)
  else:
    print(minNum)

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:
        print(ans[max(i-1,0)])
        quit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

best = 100000000
ret = x

if n:
	mn = min(ps)
	mx = max(ps)
	s = set(ps)
	for i in range(mn, mx+1):
		if i not in s:
			d = abs(x-i)
			if d < best:
				best = d
				ret = i
	if ret == x:
		up = abs(mx + 1 - x)
		down = abs(mn - 1 - x)
		ret = mn-1 if down <= up else mx+1

print(ret)

Submission status: Wrong Answer

Solution code:
import math

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



def main(X, N):
  if N == 0:
    print(X)
    return
     
  p = list(map(int, input().strip().split()))
  if not X in p:
    print(X)
    return
    
  for i in range(math.ceil((N-1)/2)):
    a = X-i-1
    b = X+i+1
    if not a in p:
      print(X-i-1)
      return
    if not b in p:
      print(X+i+1)
      return
   
  
main(X, N)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
x,N = map(int, input().split())

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

abs_list = []

for p in P:
  abs_list.append(np.abs(x-p))
  
if len(abs_list) == 0:
  print(x)
  sys.exit()
   
abs_max = max(abs_list)
for i in range(max(abs_list)):
  if abs_list.count(i) == 0:
    print(x-i)
    sys.exit()
  elif abs_list.count(i) == 1 and x+i in P and i !=0:
    print(x-i)
    sys.exit()
  elif abs_list.count(i) == 1 and x-i in P and i != 0:
    print(x+i)
    sys.exit()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    x, n = map(int, input().split())

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

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

    max_p = 100
    not_p_list = []


    flag = False
    for j in range(max_p):
        j1 = j+1
        if j1 in p_list:
            pass
        else:
            not_p_list.append(j1)

    #print(not_p_list)

    min_num = 999
    ans = 0

    for i in not_p_list:

        m = abs(x - i)
        if min_num >= m:
            if min_num == m:
                continue
            min_num = m
            ans = i

    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
X, N = list(map(int, input().split()))
if N != 0:
    P = list(map(int, input().split()))
    ans = 0
    L = X
    H = X
    for _ in range(N // 2):
        L = L - 1
        H = H + 1
        if L not in P:
            print(L)
            break
        if H not in P:
            print(H)
            break
else:
    print(X)

Submission status: Wrong Answer

Solution code:
import sys

x,n = map(int,input().split())
p = list(map(int,input().split()))
pp = [i for i in range(1,103)]
ans = 1000
m = 1000

for j in range(n):
    pp.remove(p[j])

for k in pp:
    if m > abs(x-k):
        m = abs(x-k)
        ans = k

print(ans)

Submission status: Wrong Answer

Solution code:
s = input().split()

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

s = {i for i in range(-100,101)}

p1 = input().split()

p = set()

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

t = s - p

answer = 150

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

print(answer)

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 = sorted(p)
    for i in range(0, 100):
        if X-i not in p:
            print(X-i)
        elif X+i not in p:
            print(X+i)

Submission status: Wrong Answer

Solution code:
lst = []
l = []
str = input()
l = str.split(' ')
n = int(l[0])
no = int(l[1])
if no==0:
  print(n)
  exit(0)
  
str1 = input()
lst = str1.split(' ')
for i in range(0,no):
  lst[i] = int(lst[i])
for i in range(1,100):
  if n-i not in lst and n-i>=0:
    print(n-i)
    break
  if n+i not in lst:
    print(n+i)
    break

Submission status: Wrong Answer

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    X, N = mulinputs()
    ps = set(mulinputs())

    # mins = [ [] for _ in range(100)]
    mins = []
    m = INF
    for p in range(-100,101):
        if p in ps:
            continue
        tmp = abs(X-p)
        if tmp < m:
            m = tmp
            mins = []
            mins.append(p)
        elif tmp == m:
            mins.append(p)

    mins.sort()
    # 出力
    if mins:
        print(mins[0])
    else:
        print(X)
    # if X not in ps:
    #     print(X)
    #     exit()
    # for i in range(X-1,0,-1):
    #     p1, p2 = X-i, X+i
    #     if min(p1, p2) not in ps:
    #         if min(p1, p2) == p1:
    #             print(X-i)
    #             exit()
    #         else:
    #             print(X+i)
    #             exit()

Submission status: Wrong Answer

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

c = collections.Counter(list)
res1=-1000
res2=-1000

for i in range (0, 100):
  if(c[X+i]==0):
    res1=X+i
    if(c[X-i]==0):
      res2=X-i
    break

if(abs(N-res1)<abs(N-res2)):
  print(res1)
else:
  print(res2)

Submission status: Wrong Answer

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

tmp = [(abs(i-x), i) for i in range(0, 101) if i not in ps]
min_d = min(tmp, key=lambda x: x[0])[0]

ans = min(filter(lambda x: x[0] == min_d, tmp), key=lambda x:x[1])

print(ans[1])

Submission status: Wrong Answer

Solution code:
XN = input().split()
P = input().split()
X = int(XN[0])
N = int(XN[1])
pi = [int(a) for a in P]

i = 1
while True:
    koho1 = X + i
    koho2 = X - i
    if not koho2 in pi:
        print(koho2)
        break
    elif not koho1 in pi:
        print(koho1)
        break
    else:
        i = i + 1
        continue

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
a_list=list(map(int,input().split()))
if N==0:
    print(X)
else:
    if X in a_list:
        for i in range(N//2+1):
            if X-i in a_list:
                
                if X+i in a_list:
                    a=1
                else:
                    print(X+i)
                    break
            else:
                print(X-i)    
                break        
    else:
        print(X)

Submission status: Wrong Answer

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

hidden_L = [i+1 for i in range(100)]

for A_i in A_L:
    hidden_L.remove(A_i)

counter = 0

while True:
    minus = X - counter
    plus  = X + counter
    if minus > 0:
        if minus in hidden_L:
            print(str(minus))
            break
    if plus <= 100:
        if plus in  hidden_L:
            print(str(plus))
            break
    counter = counter + 1

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if(n==0):
  print(x)
else:
  l=list(map(int,input().split()))
  d=100
  for i in range(101):
      if(i not in l and (abs(i-x)<d)):
          d=abs(x-i)
          m=i
  print(m)

Submission status: Wrong Answer

Solution code:
import sys
X ,N = map(int,input().split())
p = list(map(int,input().split()))
min_dif = 10000
output = 10000
kari = 10000
for i in range(100):
  if (100 - i in p) == False:
    if abs(X-(100-i)) <= min_dif:
      min_dif = abs(X-(100 - i))
      output =  100 - i
print(output)

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_ = 50000
    for i in range(100):
        if a[i] < min_ and (not i + 1 in p):
            min_ = a[i]
            print(a[i])
            ans = i + 1
    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)
    min = 101
    for i in list:
        if min > abs(X-i):
            min = abs(X - i)
            result = i

print(result)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
p = list(map(int,input().split()))
dif = 2**60
ans = 2**60
for u in range(101):
    if u in p:
        continue
    else:
        tmp = abs(x-u)
        if tmp < dif:
            dif = tmp
            ans = u
for a in range(1,101):
    if a+x == dif:
        ans = -a
        break
print(ans)

Submission status: Wrong Answer

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

X, N = map(int, input().split())
plist = list(map(int, input().split()))
diff = []
for i in range(0, 102):
    if i not in plist:
        diff.append(i)

diff.sort()
diff = [(item, abs(item - X)) for item in diff]

nearest = -1
min_v = 1000
for idx, item in diff:
    if item == 0 and N != 0:
        continue

    if item < min_v:
        min_v = item
        nearest = idx

print(nearest)

Submission status: Wrong Answer

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

for i in range(0, 101):
  if (x-i) not in list:
    print(x-i)
    break
  if (x+i) not in list:
    print(x+i)
    break

Submission status: Wrong Answer

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

	diff_1 = abs(X-p[-1])
	diff_2 = abs(X-p[0])
	diff = max(diff_1,diff_2)

	for x in range(diff+1):
		if X-x not in p:
			print(X-x)
			break
		if X+x not in p:
			print(X+x)
			break

Submission status: Wrong Answer

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

not_in_p = list(range(1,101))
for pn in p:
    if pn in not_in_p:
        not_in_p.remove(pn)

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

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

print(answer)

Submission status: Wrong Answer

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

ans = 10000
ans_diff = 10000

list_100 = [0] * 100
for i in range(100):
  list_100[i] = i+1
 
live_list = list(set(list_100) - set(p))

for i in live_list:
  diff = abs(X - i)
  if diff < ans_diff:
    ans = i
    ans_diff = diff
  if diff == ans_diff:
    ans = min(ans, i)
 
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect as bs

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

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

nums = list(map(int,input().split()))
nums2 = [False]*101
# print(nums)
for p in nums:
    nums2[p] = True

for i in range(50):
    # print(x-i,x+i)
    if x - i < 1:
        print(0)
        exit(0)
    elif x + i > 100:
        print(101)
        exit(0)
    elif nums2[x-i]==False:
        print(x-i)
        exit(0)
    elif nums2[x+i]==False:
        print(x+i)
        exit(0)

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

Submission status: Wrong Answer

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

p = {4,7,10,6,5}
q = set(range(min(p),max(p)+1,1))
r = q-p
diff = 100
ans = 0
for i in r:
    if diff > abs(X-i):
        diff = abs(X-i)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
  anss=x
else:
  p=list(map(int,input().split()))
  pp=list(set(list(range(-100,100)))-set(p))
  ans=1000
  anss=1000
  for j in range(len(pp)):
    if abs(pp[j]-x)<ans:
      ans=abs(pp[j]-x)
      anss=pp[j]
    elif abs(pp[j]-x)==ans and pp[j]<anss:
      ans=abs(pp[j]-x)
      anss=pp[j]
print(anss)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N == 0:
    if(X <= 50):
        print(0)
    else:
        print(100)
else:
    P = list(map(int,input().split()))
    mini = 999
    ANS = 0
    for i in range(102):
        if P.count(i) == 0:
            if mini > abs(X-i):
                mini = 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()))

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

arr = [0]*101

for i in range(len(P)):
  target=P[i]
  arr[target]=1

near=float('inf')
idx =0
for i in range(len(arr)):
  if arr[i] == 0 and i != 0 and i != 100:
    if near > abs(X-i):
      near = abs(X-i)
      idx = i
print(idx)

Submission status: Wrong Answer

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

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

if N == 0:print(X)
else:
    for i in range(1,100):
        if not X-i in L:
            print(X-i)
            break
        if not X+i in L:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
"""AtCoder Beginner Contest 170: C - Forbidden List
https://atcoder.jp/contests/abc170/tasks/abc170_c
"""


def main():
    X, N = list(map(int, input().split()))
    Ps = list(map(int, input().split()))

    ans = X
    min_diff = float('inf')
    for d in range(1, 101):  # 1-100
        if d in Ps:
            continue

        v = X - d
        # print('d({}), v({})'.format(d, v))
        if abs(v) < min_diff:
            min_diff = abs(v)
            ans = d

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if n == 0:
    p = input()
    print(x)
else:
    p = list(map(int, input().split()))
    max_p = max(p)
    ans = 0
    tmp = 1000

    for i in range(1, max_p+1):
        diff = abs(x - i)
        if i not in p and tmp > diff:
            ans = i
            tmp = diff

    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()
    if X in p:
        index = p.index(X)
        c = 1
        while True:
            if index - c >= 0 and p[index - c] != X - c:
                print(X - c)
                break
            elif index - c < 0:
                print(X - c)
                break
            elif index + c < N and p[index + c] != X + c:
                print(X + c)
                break
            else:
                c += 1

    else: print(X)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  a = 100
  ans = 0
  for i in range(1,101):
    if i not in p:
      b = abs(x - i)
      if a == b and i < ans:
        ans = i
      elif b < a:
        a = b
        ans = i
    else:
      pass
  print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

    p.sort()
    q = p
    ans = list(map(lambda _: abs(_ - x), q))

    cnt = 0
    while cnt <= 101:
        if ans.count(cnt) == 2 and cnt != 0:
            pass
        elif ans.count(cnt) == 1 and cnt == 0:
            pass
        else:
            if (x - cnt) in ans:
                return x + cnt
            else:
                return x - cnt

        cnt += 1    
    


if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

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

check = float("inf")
ans = float("inf")
for p in range(100,-101,-1):
    if p in p_lst:
        continue
    else:
        #print(p)
        if check >= abs(p-x):
            check = abs(p-x)
            ans = p
            
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    ans = float("inf")
    numlist = [i for i in range(101)]
    for i in range(100):
        if numlist[i] in p:
            numlist[i] = -1
    cnt = 0
    for i, numele in enumerate(numlist):
        if numele == -1:
            continue
        if ans > abs(x - i):
            ans = abs(x - i)
            cnt = numele
    print(cnt)
            
    

if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

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

num_set = set(range(0, 101))

ans_list = list(num_set - p)
min_diff = None
min_ans = None
for ans in reversed(ans_list):
    diff = abs(ans - X)
    if min_diff is None or diff <= min_diff:
        min_diff = diff
        min_ans = ans

print(min_ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

a = input()
a, b = a.split()
a = int(a)
if int(b) == 0:
  print(a)
  exit()
n = input()
n = [int(i) for i in n.split()]
li = list(range(1, 101))
for i in n:
  li.remove(i)
mini = [np.inf, 0]
for i in li:
  if abs(i - a) == mini[0]:
    if i < mini[1]:
      mini = [abs(i - a), i]
  elif abs(i - a) < mini[0]:
    mini = [abs(i - a), i]
print(mini[1])

Submission status: Wrong Answer

Solution code:
def forbidden(x,p):
    temp = 100
    for num in range(101):
        if num not in p:
            if abs(x-num) <= temp and x!=num:
                temp = abs(x-num)
                res = num
    if x <= abs(x-res):
        return 0
    return res

if __name__ == "__main__":
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    if n==0:
        print(x)
        exit()
    print(forbidden(x,p))

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
v = list(map(int, input().split()))
for i in range(204):
    if x not in v:
        print(x)
        exit()
    else:
        if ((x - i) >= 0) and ((x - i) <= 100) and (x - i) not in v:
            print(x-i)
            exit()
        elif ((x + i) >= 0) and ((x + i) <= 100) and (x + i) not in v:
            print(x+i)
            exit()

Submission status: Wrong Answer

Solution code:
import sys

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

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

for i in range(10):
    m = X - ((i//2 +1) * (-1)**i)
    if m not in p:
        print(m)
        break