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

  p.sort()
  q=list(range(1,101))

  for i in p:
    q.remove(i)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def linked_merge_sort(l): #マージソート
    if len(l) == 1:
        return
    q, r = divmod(len(l), 2)
    left = [l.pop() for _ in range(q)]
    right = [l.pop() for _ in range(q + r)]
    
    linked_merge_sort(left)
    linked_merge_sort(right)
    
    left.reverse()
    right.reverse()
    while left and right:
        if left[-1] <= right[-1]:
            l.append(left.pop())
        else:
            l.append(right.pop())
    while left:
        l.append(left.pop())
    while right:
        l.append(right.pop())
    return

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

if x>50:
    ans = 100
else:
    ans = 0
for i in range(n):
    p[i]=p[i]-x
if n>1:
    linked_merge_sort(p)
    j=n-1
    for i in range(n):
        if p[i]>=0:
            j=i
            break
    for i in range(50):
        if j-i>=0:
            if p[j-i]!=-i:
                ans = x-i
                break
        else:
            ans=x+p[0]-1
            break
        if j+i<n:
            if p[j+i]!=i:
                ans = x+i
                break
        else:
            ans=x+p[n-1]+1
elif n==1:
    if p[0]==x:
        ans=x-1
    else:
        ans=x
else:
    ans=x
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int,input().split())
P = list(map(int,input().split()))
ans = 0
def f(X,N,P):
  if(N==0):
    ans = X
    return ans
  else:
    for i in range((X+1)//2+1):
      if(not (X-i in P)):
        ans = X-i
        return ans
      elif(not (X+i in P)):
        ans = X+i
        return ans
print(f(X,N,P))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
x, N = map(int, input().split())

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

min_abs = 100
min_num = 0

for num in range(1, 101):
    if not num_list:
        min_num = x
        break
    if num in num_list:
        continue
    else:
        b = abs(num-x)
        if b < min_abs:
            min_abs = b
            min_num = num
            
print(min_num)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n==0:
    print(x)
else:
    p = list(map(int,input().split()))
    ans,ans_x = 101,101
    for i in range(x,101):
        if i not in p:
            ans = i
            ans_x = abs(x-i)
            break
    for i in range(x,-101,-1):
        if i not in p:
            if ans >= i and ans_x >= abs(x-i):
                ans = i
                break
    print(ans)

Submission status: Wrong Answer

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

p1 = [abs(i-x) for i in p]

p = set(p)
p1.sort()
if len(p1) ==0:
    print(x)
else:
    if p1[0] != 0:
        print(x)
    else:
        cnt = 1
        while(cnt < len(p1)):
            if p1[cnt] != 1+ int(cnt/2):
                break
            else:
                cnt +=1
        if x-cnt in p:
            print(x+cnt)
        else:
            print(x-cnt)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p_list = list(map(int,input().split()))
for i in range(1,100):
    if N == 0:
        print(X)
        break
    elif not X-i in p_list:
        print(X-i)
        break
    elif not X+i in p_list:
        print(X+i)
        break

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p_list=list(map(int,input().split()))
ans=0
f_list=list(range(101))
for i in p_list:
    f_list.remove(i)
for i in f_list:
    if abs(X-ans)>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=list(map(int,input().split()))
  numbers=list(range(102))
  ans=0

  for i in range(len(p)):
    numbers.remove(p[i])

    for j in range(100):
      for k in range(len(numbers)):
        if abs(X-numbers[k]) == 100-j:
          ans=numbers[k]
          break
  print(ans)

Submission status: Wrong Answer

Solution code:
def forbidden(x,p):
    temp = 100
    res = []
    for num in range(101):
        if num not in p:
            if abs(x-num) <= temp and x!=num:
                temp = abs(x-num)
                res.append(temp)
    if x-min(res) not in p:
        return x-min(res)
    return x+min(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 = input().split()

x = int(x)
n = int(n)

def check(x,n):
    # そもそも配列の数が0の場合はだめ
    if int(n) == 0:
        print(x)
        return

    # 与えられた変数の配列
    p_list = input().split()

    # 差数を１ずつ上昇させていってみる
    for i in range(0, 50):
        min_x = str(x - int(i))
        max_x = str(x + int(i))

        # 両方とも含まれない
        if min_x not in p_list or max_x not in p_list:
            if min_x not in p_list:
                print(min_x)
                return
            
            if max_x not in p_list:
                print(max_x)
                return
check(x,n)

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_set = set(p_list)
    new_list = []
    new_list.append(0)
    for i in range(1, 101):
        if i in p_set:
            pass
        else:
            new_list.append(i)

#    print(new_list)

    min_x = 100 #絶対値の最小
    min_diff = 100
    for x in new_list:
        if abs(x - X) <= min_diff:
            if min_diff == abs(x - X):
                if x < min_x:
                    min_x = x
            else:
                min_x = x
                min_diff = abs(x - X)
            
        else:
            pass
    print(min_x)

Submission status: Wrong Answer

Solution code:
line = input().split()
X = int(line[0])
N = int(line[1])

if N == 0:
    print(X)

else:
    p_line = input().split()
    p_line = [int(i) for i in p_line]
    num_line = [i for i in range(1, 101)]
    set_line = list(set(num_line) - set(p_line))

    min = 101
    ans = 0

    if X in set_line:
        print(X)
        exit()

    for i in set_line:
        if i < X:
            if X-i < min:
                min = X-i
                ans = i
        else:
            if i-X < min:
                min = i-X
                ans = i

            if i-X > min:
                break
            
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x,length = map(int, input().split())
if length != 0:
  l = list(map(int, input().split()))
  l_b = list(range(1,100))
  diff = list(set(l) ^ set(l_b))
  sa = []
  for i in range(len(diff)):
    sa.append(abs(diff[i]-x))
  index = sa.index(min(sa))
  print(diff[index])
else:
  print(x)

Submission status: Wrong Answer

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

if n>0:
    a=list(map(int,input().split()))
    a.sort
    x_p=x
    x_n=x
    
    while True:
        x_n-=1
        x_p+=1
        if all(elem != x_p for elem in a) and all(elem != x_n for elem in a):
            if abs(x_p)>abs(x_n):
                print(x_n)
                break;
            else:
                print(x_p)
                break;
        elif all(elem != x_p for elem in a):
            print(x_p)
            break;
        elif all(elem != x_n for elem in a):
            print(x_n)
            break;
            
else:
  print(x)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
cnt = 0
s = 0
o = 0
while True:
    if not(x - cnt in p):
        s = x - cnt
    if not(x + cnt in p):
        o = x + cnt
    if s >= 1 or o >= 1:
        break
    cnt += 1
if s >= 1 and o >= 1:
    if s < o:
        print(s)
    else:
        print(o)
elif s >= 1:
    print(s)
elif o >= 1:
    print(o)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
min = 0
i = 0
count = 0
while True:
    if abs(X - i) == min:
        if i not in p:
            break
        elif i in p and min != 0:
            count += 1
            if count == 2:
                min += 1
                count = 0
                i = 0
        else:
            min += 1
            i = 0
    i += 1

print(i)

Submission status: Wrong Answer

Solution code:
X,N = input().split()
 
import sys
X = int(X)
N = int(N)
 
if N ==0:
    print(X)
    sys.exit()
    
n = input().split()
n = [int(s) for s in n]
 
for i in range(1,N+1):
    if X -i not in n:
        print(X-i)
        break
    elif X + i not in n:
        print(X+i)
        break

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
 
p = list(map(int, input().split()))
pp = set(p)
numlist = [i for i in range(-100, 101)]
numlistt = set(numlist)
newlist = numlistt - pp
newlistt = list(newlist)
newlisttt = newlistt.sort()
absn = 1000
ans = 1000
 
for i in newlistt:
    if absn > abs(X-i):
        ans = i
        absn = abs(X-i)
    elif absn == abs(X-i) and i < ans:
        ans = i
        absn = abs(X-i)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
m=100
ans=0
lis=list(range(100,0,-1))
for k in lis:
    for l in range(N):
        if k==P[l]:
            lis[100-k]=0
for i in lis:
    if abs(i-X)<=m:
        m=abs(i-X)
        ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
q = []
if n > 0:
  p = list(map(int,input().split()))
  for i in range(max(p)):
    if i+1 not in p: 
      q.append(i+1)
  for i in range(len(q) - 1):
    if abs(x - q[i + 1]) >= abs(x - q[i]):
      print(q[i])
      break
    if i == len(q) - 2:
        print(q[i + 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()))
  p.sort()
  m = float("inf")
  if x<int(p[0]) or int(p[n-1])<x:
    print(x)
  else:
    for y in [y for y in range(p[0]-1,p[n-1]) if not y in p]:
      if abs(x-y)<m:
        m = abs(x-y)
        ans_y = y
  print(ans_y)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = []
sortlist = []
if n == 0:
    print(x)
else:
    p.sort()
    p1 = p[0]
    pn = p[n-1]
    new = [i for i in range(0, 101)]
    nolist = set(new) ^ set(p)
    nolist = list(nolist)

    for i in range(0, len(nolist)):
        d = abs(nolist[i] - x)
        sortlist.append(d)

        k = sortlist.index(min(sortlist))
    print(nolist[k])

Submission status: Wrong Answer

Solution code:
import math

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

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

p.sort()

minimum = p[0]
maximum = p[len(p) - 1]
# print(minimum, maximum)

answer = 101
for candidate in range(minimum + 1, maximum):
    diff = abs(X - candidate)
    answer = candidate if diff < answer else answer

print(answer)

Submission status: Wrong Answer

Solution code:
def fun(x):
  var=1
  first=0
  while True:
     if (x-var) not in n:
        first +=(x-var)
        # print("var is",var)
        return var
    
     var +=1

def funco(x):
  var=1
  first=0
  while True:
     if (x-var) not in n:
        first +=(x-var)
        # print("var is",var)
        return first
    
     var +=1
      
      

    

def fun2(x):
  var=1
  second=0
  while True:
    if (x+var) not in n:
       second +=(x+var)
      #  print("var is",var)
       return var

    var +=1

def fun2co(x):
  var=1
  second=0
  while True:
    if (x+var) not in n:
       second +=(x+var)
      #  print("var is",var)
       return second

    var +=1

x=list(map(int,input().split()))
n=list(map(int,input().split()))
s=(fun(x[0]))
t=(fun2(x[0]))
# print(s)
# print(t)
if s>t:
  print(fun2co(x[0]))
else:
  print(funco(x[0]))

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
nump = list(map(int,input().split()))
nump.sort()
x_ind = -1
nump_io = [0]*103
for i in range(n):
    nump_io[nump[i]-1] = 1
    if(nump[i]==x):
        x_ind = i
if(x_ind == -1):
    print(x)
else:            
    for i in range(1,50):
        if(nump_io[(x-1)-i] == 0):
            print(x-i)
            break
        if(nump_io[(x-1)+i] == 0):
            print(x+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(1,X):
        p1, p2 = X-i, X+i
        if p1 not in ps:
            print(X-i)
            exit()
        if p2 not in ps:
            print(X+i)
            exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


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


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

ans1 = x - x1
ans2 = x2 - x

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

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-1, 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 = map(int,input().split())
p = list(map(int,input().split()))

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

f = [1]*100
sa = 101
ans = 0

for i in p:
    f[i-1] = 0

for i in range(100):
    if f[i] == 1 and sa > abs(i+1-x):
        sa = abs(i+1-x)
        ans = i+1

if ans == 0:
    print(0)
elif sa >= x:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

syou = 1000
kouho = 1000

for i in range(0, 101):
    flag = 0
    for j in range(n):
        if i == p[j]:
            flag = 1

    if flag == 1:
        continue

    if syou > abs(x-i):
        kouho = i
        syou = abs(x-i)
        continue
    elif syou == abs(x-i):
        kouho = min([kouho, i])
        continue

for k in range(n):
    if p[k] > 0:
        print(kouho)
        exit()

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

print(max(p))

Submission status: Wrong Answer

Solution code:

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



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

l.sort() 
l.sort() 



for i in range(0,100):
    if l.count(X)==0:
        print(X)
        break 


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

    

    if X+i<=100:
        if l.count(X+i)==0:
         print(X+i)
         break

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
# p = [i+1 for i in range(99)]
L = [i-99 for i in range(200)]
# L = [i for i in range(101)]
for item in p:
    L.pop(L.index(item))

MIN = 10**5
ans = 10**5
for item in L:
    if abs(item-X) < MIN:
        MIN = abs(item-X)
        ans = item

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split(" "))
if(n==0):
    print(x)
else:
    a=list(map(int,input().split(" ")))
    if(x not in a):
        print(x)
    else:
        a.sort()
        c=a.index(x)
        for i in range(1,n):
            if(c-i<0):
                print(x-i)
                break
            else:
                if(a[c-i]!=x-i):
                    print(x-i)
                    break
            if(c+i==n):
                print(x+i)
                break
            else:
                if(a[c+i]!=x+i):
                    print(x+i)
                    break

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()
mi=1000
cotae=1000
for i in range(1,100):
  if(i in P):
    continue
  if(abs(X-i)<mi):
    mi=abs(X-i)
    cotae=i
print(cotae)

Submission status: Wrong Answer

Solution code:
# coding:utf-8
x, n = map(int, input().split())
p = list(map(int, input().split()))


if n == 0:
    print(x)
else:
    ps = sorted(p)
    tmp = list(range(-101, 101))
    ans_list = list(set(tmp) ^ set(ps))
    ans_list = sorted(ans_list)
    # print(tmp, ans_list)
    diff = []

    for i in ans_list:
        diff.append(abs(i - x))

    print(ans_list[diff.index(min(diff))])

Submission status: Wrong Answer

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

for i in range(0,101):
    if (i in p):
        continue
    else:
        tmp=(x-i)**2
        if tmp<ans:
            ans=tmp
            c=i
print(c)

Submission status: Wrong Answer

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

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

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

p1 = input().split()

p = set()

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

t = s - p

answer = 20000

for i in t:
    if (abs(x - abs(int(i))) < abs(x - abs(answer))) or (abs(x - abs(int(i))) == abs(x - abs(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()))

a = 101
num = 0

for i in range(101):
    if i not in p:
        b = i-X
        if abs(b) < a:
            a = abs(b)
            num = i

print(num)

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(res1==-1000 and res2!=-1000):
  print(res2)
elif(res2==-1000 and res1!=-1000):
  print(res1)
elif(abs(X-res1)<abs(X-res2)):
  print(res1)
elif(abs(X-res2)<=abs(X-res1)):
  print(res2)

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(n):
        if x-i in p:
            if x+i in p:
                a =0
            else:
                print(x+i)
                exit(0) 
        else:
            print(x-i)
            exit(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x,n = list(map(int,input().split()))
if n >0 :
  p = list(map(int,input().split()))
#print(x,n)
#print(p)
#print(max(p))
y = 100
ans = n
if n == 0:
  print(x)
else:
  for i in range(max(p)+1):
    if p.count(i) == 0:
      #print('i=',i,abs(x-i))
      if abs(x-i) < y:
        ans = i
        y = abs(x-i)
  print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
import random
from decimal import Decimal


X, N = [int(x) for x in stdin.readline().rstrip().split()]

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

ans = 10**9
ans1 = [X, 10**9]
for i in range(-100, 101):
    if i not in p:
        if ans > abs(X-i):
            ans = abs(X-i)
            # print(i, abs(X-i))
            if ans1[1] == abs(X-i):
                pass
            else:
                ans1[1] = abs(X-i)
                ans1[0] = i
            # ans1[1] = abs(X-i)
            # if ans1 > i:
            #     ans1 = i
                # print(i)
print(ans1[0])

Submission status: Wrong Answer

Solution code:
line = input().split()
X = int(line[0])
N = int(line[1])

if N == 0:
    print(100)

else:
    p_line = input().split()
    p_line = [int(i) for i in p_line]
    num_line = [i for i in range(1, 101)]
    set_line = list(set(num_line) - set(p_line))

    min = 101
    ans = 0

    if X in set_line:
        print(X)
        exit()

    for i in set_line:
        if i < X:
            if X-i < min:
                min = X-i
                ans = i
        else:
            if i-X < min:
                min = i-X
                ans = i

            if i-X > min:
                break
            
    print(ans)

Submission status: Wrong Answer

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

cnt1 = 0
cnt2 = 0
ans1 = 0
ans2 = 0

for i in range(x,101):
    cnt1 += 1
    if not i in p:
        ans1 = i
        break

for i in range(x,-1,-1):
    cnt2 += 1
    if not i in p:
        ans2 = i
        break

if cnt1 < cnt2:
    print(ans1)
elif cnt1> cnt2:
    print(ans2)
else:
    print(ans2)

Submission status: Wrong Answer

Solution code:
def main():
	x, n = map(int, input().split())
	P = list(map(int, input().split()))
	if n == 0:
		print(x)
		return
	ans = 0
	min_dis = 1000
	for item in range(1, 101):
		if item in P:
			continue
		dis = abs(item - x)
		if min_dis > dis:
			min_dis = dis
			ans = item
	print(ans)
	return

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
m=100
ans=0
lis=list(range(100,0,-1))
for k in lis:
    for l in range(N):
        if k==P[l]:
            lis[100-k]=0
for i in lis:
    if abs(i-X)<m:
        m=abs(i-X)
        ans=i
print(ans)