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:
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    A=list(map(int,input().split()))
    p=list(map(int,input().split()))
    if A[1]==0:
        print(A[0])
        sys.exit()
    X=A[0]
    N=A[1]
    for i in range(N):
        X1=X-i
        X2=X+i
        if X1 not in p:
            print(X1)
            sys.exit()
        if X2 not in p:
            print(X2)
            sys.exit()
    

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X, Y = input().split()
x = int(X)
y = int(Y)
a = (4*x - y) / 2
b = (-2*x + y) / 2
if(a >= 0 and a.is_integer() and b >= 0 and b.is_integer()):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
tmp = []
for i in range(-101,101):
    tmp.append(i)

if n == 0:
    print(x)
else:
    for i in p:
        tmp.remove(i)
    
    ans = []
    for i in tmp:
        a = abs(x-i)
        ans.append(a)

    b = min(ans)
    print(ans)
    c = x+b
    d = x-b

    if c and d in tmp:
        print(d)
    elif c in tmp:
        print(c)
    elif d in tmp:
        print(d)

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

if (X in p) == False:
    print(X)
    sys.exit()

for i in range(N):
    if (X - i in p) == False:
        print(X - i)
        sys.exit()
    elif (X + i in p) == False:
        print(X+i)
        sys.exit()

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(-100, 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(min(p))

Submission status: Wrong Answer

Solution code:
x, n = map(int,input().split())
if n == 0:
    print(x)
else:
    pls = list(map(int,input().split()))
    ans = 0
    i = 0
    while ans == 0:
        if x + i not in pls:
            if x - i not in pls:
                print(x - i)
                ans = 1
            else:
                print(x + i)
                ans = 1
        else:
            i += 1

Submission status: Wrong Answer

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

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

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

q = [i for i in range(-10, 100+1)]
r = []


for i in q:
    if i not in p:
        r.append(i)

s = [abs(x-i) for i in r]

print(r[s.index(min(s))])

Submission status: Wrong Answer

Solution code:
def resolve():
    X, N = map(int, input().split())
    if N != 0:
        P = list(map(int, input().split()))
        S = []
        for _ in range(0, 101):
            if _ in P:
                continue
            else:
                S.append(_)
        for i in range(N):
            if X-i in S:
                print(X-i)
                exit()
            elif X+i in S:
                print(X+i)
                exit()
    else:
        print(X)
resolve()

Submission status: Wrong Answer

Solution code:
def main():
    x,y = list(map(int, input().split()))

    if y == 0:
        print(x)
        exit()
    nums = list(map(int, input().split()))
    ans = 101
    for i in range(1, 200):
        if i not in nums:
            ans = ans if abs(ans-x) <= abs(i-x) else i
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit() 

nun_list = list(map(int, input().split()))
answer = nun_list[0]
target_num = nun_list[0]
for i in nun_list:
    if abs(x - answer) >= abs(x - i):
        if abs(x - answer) == abs(x - i):
            if answer > i:
                answer = i
        else:
            answer = i
            target_num == abs(x - i)
for i in range(0,100-n):
    if not nun_list.__contains__(answer -i):
        print(answer - i)
        sys.exit() 
    if not nun_list.__contains__(answer + i):
        print(answer + i)
        sys.exit()

Submission status: Wrong Answer

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

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

    for i in range(1, 101):
        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:長さ
# p1 ... pN
# 含まれない整数のうちXに近いものを答える
X, N = map(int, input().split())
p = list(map(int, input().split()))
for i in range(X, -50, -1):
    if i not in p:
        l = i
        break
for j in range(X, 201):
    if j not in p:
        r = j
        break
print(l if abs(l-X) < abs(r-X) else r)

Submission status: Wrong Answer

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

for i in range(50):
    if not str(x-i) in n_list:
        print(x-i)
        break
    elif not str(x+i) in n_list:
        print(x+i)
        break

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 = [0, 10**9]
for i in range(-100, 101):
    if i not in p:

        if ans > abs(X-i):
            ans = 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:
x, n = map(int, input().split())
a = list(map(int, input().split()))
if (x not in a):
    print(x)
    exit()


tar1 = x
tar2 = x
ff1 = True
ff2 = True

while True:
    if (ff1 is True):
        tar1 -= 1
        if (tar1 not in a):
            print(tar1)
            exit()
        if (tar1 == 1):
            ff1 = False

    if (ff2 is True):
        tar2 += 1
        if (tar2 not in a):
            print(tar2)
            exit()
        if (tar2 == 100):
            ff2 = False

    if ((ff1 is False) and (ff2 is False)):
        break

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(-10, 101):
    if i in nums:
      continue
    else:
      Dif = abs(X-i)
    if (Dif < minDiff):
      minDiff = Dif
      minNum=i
  print(minNum)

Submission status: Wrong Answer

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


def f(X, N, listp):

    if N == 0:
        return X
    if X not in listp:
        return X

    up_list = []
    down_list = []
    for p in listp:
        if p > X:
            up_list.append(p)
        if p < X:
            down_list.append(p)

    up_list = sorted(up_list)
    down_list = sorted(down_list, reverse=True)


    up_res = 10000
    for i, p in enumerate(up_list):
        if p != X+i+1:
            up_res = X+i+1
            break
    if up_res == 10000:
        up_res = X+1

    down_res = -10000
    for i, p in enumerate(down_list):
        if p != X-i-1:
            down_res = X-i-1
            break
    if down_res == -10000:
        down_res = X-1
    

    if abs(X - up_res) < abs(X - down_res):
        return up_res
    else:
        return down_res


print(f(X, N, listp))

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(201, dtype = np.int)
a[p+100] = 0
m = X
n = 0
for i in range(201):
    if a[i] == 1:
        if m>abs(i-X-100):
            if i-X-100 != 0:
                m = abs(i-X-100)
                n = i-100
print(n)

Submission status: Wrong Answer

Solution code:
import collections
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=list(map(lambda i:abs(x-i),p))
c=collections.Counter(p)
p.sort()

for i in range(len(p)):
  if p[i]!=(i+1)//2:
    if i==0:
      print(x)
      sys.exit()
    elif i==1:
      print(x-1)
      sys.exit()
    elif p[i-1]==p[i-2]:
      print(x-p[i-1]-1)
      sys.exit()
    else:
      if x-p[i-1] in p:
        print(x+p[i-1])
      else:
        print(x-p[i-1])
      sys.exit()
print(x)

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 min != 0:
            count += 1
            i = 0
            if count == 2:
                min += 1
                count = 0
        else:
            min += 1
            i = 0
    i += 1

print(i)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
sa = float("inf")
for i in range(-1, 101):
    if i not in p:
        sa = min(sa, abs(i - x))
if x - sa not in p and x + sa not in p:
    print(x - sa)
elif x - sa in p and x + sa not in p:
    print(x + sa)
elif x - sa not in p and x + sa in p:
    print(x - sa)

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
    tikai=255
    i=-1
    while True:
        if x+i not in p:
            print(x+i)
            break
        if x-i not in p:
            print(x-i)
            break
        i-=1
if __name__ == "__main__":
    main()

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(1,101))
for k in lis:
    for l in range(N):
        if k==P[l]:
            lis[k-1]=0
for i in lis:
    if abs(i-X)<m:
        m=abs(i-X)
        ans=i
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 - 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 = sorted(list(map(int, input().split())))
a = 200
b = []
if n == 0:
    print(x)
else :
    for i in range(101):
        if not i in p:
            diff = abs(x-i)
            if diff < a :
                a = min(diff, a)
                b.append(i)
            else :
                print(b[-1])
                break

Submission status: Wrong Answer

Solution code:
from sys import stdin

x, n = map(int, stdin.readline().split())
seq = list(map(int, stdin.readline().split()))

diff = [0 for i in range(100)]
for num in seq:
  diff[abs(x-num)] += 1

for i in range(100):
  if diff[i]==0:
    ans = x+i
    break

print(ans)

Submission status: Wrong Answer

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

for n in range(1, (N // 1) + 1):
    if not (X - n) in P:
        print(X - n)
        exit()
    if not (X + n) in P:
        print(X + n)
        exit()
print(X - ((N // 1) + 1))

Submission status: Wrong Answer

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

if N == 0:
    print(X)
    
else:
    for i in range(100):
        if (X-(i+1)) and (X+i+1) in p:
            continue
    
        elif (X-i-1) not in p:
            print(X-i-1)
            break
    
        elif (X+i+1) not in p:
            print(X+i+1)
            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()))
  ans = []

  for i in range(n-2):
    if x-i not in p:
      ans.append(-i)
      break
    elif x+i not in p:
      ans.append(i)
      break
  if ans == []:
    ans.append(-3)

  print(x+ans[0])

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    if p != []:
        for i in range(0, 100):
            if not x-i in p and x-i >= 0:
                print(x-i)
                break
            else:
                if not x+i in p and x+i <= 100:
                    print(x+i)
                    break
    else:
        print(x)
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
if(y != 0):
  p = list(map(int, input().split()))
  p.sort()  
  forward = 0
  backward = 0
  for i in range(x, p[-1] + 1):
    if(i not in p):
      break
    forward += 1
  for i in range(x, p[0] - 1, -1):
    if(i not in p):
      break
    backward += 1
  if(forward > backward):
    k = x - backward
    if(k > p[0] and k < p[-1]):
      print(k)
    else:
      print(x + forward)
  else:
    k = x + forward
    if(k > p[0] and k < p[-1]):
      print(k)
    else:
      print(x - backward)
else:
  print(x)

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
A = list(map(int, input().split()))
if N == 0:
    print(X)
else:
    if N == 1:
        if N != X:
            print(X)
        else:
            print(X-1)
    else:
        B = []
        for i in range(N):
            B.append(abs(X-A[i]))
        B.sort()
        t = 0
        for i in range(N-1):
            if (i+1)//2 != B[i]:
                break
            else:
                t = t+1
        if t == N:
            if N%2 == 1:
                print(X-(N+1)//2)
            else:
                k = 0
                for i in range(N):
                    if A[i] == X-(N//2):
                        k = k+1
                if k == 0:
                    print(X-(N//2))
                else:
                    print(X+(N//2))
        else:
            if t%2 == 1:
                print(X-(t+1)//2)
            else:
                k = 0
                for i in range(N):
                    if A[i] == X-(t//2):
                        k = k+1
                if k == 0:
                    print(X-(t//2))
                else:
                    print(X+(t//2))

Submission status: Wrong Answer

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

    min = 1000

    for i in range(1, 150):

        if i in p:
            continue

        elif min > abs(x - i):
            result = i
            min = abs(x - i)

    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
x, n=map(int,input().split())
b=[]
try:
  p=list(map(int,input().split()))
  for i in range(n):
    a=abs(x-p[i])
    b.append(a)
    b.sort()
  if b[0]==b[1]:
    print(x-b)
  else:
    print(b[0])
except:
  print(x)

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


def ans():
    if n == 0:
        return x
    for i in range(n):
        if x - i not in p:
            return x-i
        if x + i not in p:
            return x+i


print(ans())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

D = 201
ans = 0
for j in range(len(A)):
    if D > abs(X - A[j]):
        D = abs(X - A[j])
        if ans <= A[j]:
            ans = A[j]
        else:
            pass
    else:
        pass
print(ans)

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(1,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:
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(101):
        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:
XN = input().split()
P = input().split()
X = int(XN[0])
N = int(XN[1])
pi = [int(a) for a in P]
if N == 0:
    print(X)
    exit()
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())
li = list(map(int,input().split()))

if n == 0:
    print(x)
else:
    for i in range(1, 101):
        up = x + i
        down = x - i
        if down not in li:
            print(down)
            break
        if up not in li:
            if down == up:
                print(down)
                break
            else:
                print(up)
                break

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:
# coding: utf-8
# Your code here!
x,n=map(int,input().split())
if n!=0:
    a=list(map(int,input().split()))
else:
    a=[0]*3
number=[0]*101

for num in range(len(a)):
    number[a[num]]=a[num]
    
counter=0
plus=0
ans=0

while counter==0:
    if number[x-plus]==0:
        ans=x-plus
        counter+=1
    elif number[x+plus]==0:
        ans=x+plus
        counter+=1
    else:
        plus+=1
        if plus>x or plus>100-x:
            ans=0
            counter+=1

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:
    for i in range(n+1):
        if not x-i in p and x-i > 0:
            print(x-i)
            break
        elif not x+i in p:
            print(x+i)
            break

Submission status: Wrong Answer

Solution code:
import collections
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=list(map(lambda i:abs(x-i),p))
c=collections.Counter(p)
p.sort()

for i in range(len(p)):
  if p[i]!=(i+1)//2:
    if p[i-1]==p[i-2]:
      print(x-p[i-1]-1)
      sys.exit()
    elif i==1:
      print(x-1)
      sys.exit()
    elif i==0:
      print(x)
      sys.exit()
    else:
      if x-p[i-1] in p:
        print(x+p[i-1])
      else:
        print(x-p[i-1])
      sys.exit()
print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np
a = list(map(int,input().split()))

x = a[0]
n = a[1]

if (n == 0):
    print(x)
else:
    d = list(map(int,input().split()))
    min_int = d[np.argmin(d)]
    max_int = d[np.argmax(d)]
    if (x < min_int or max_int < x):
        print(x)
    else:
        p = []
        for var in range(0,101):
            if var not in d:
                p.append(var)
            else:
                continue
        ans = []
        for pp in p:
            ans.append(np.abs(pp - x))
        anb = np.array(ans)
        print(p[np.argmin(anb)])

Submission status: Wrong Answer

Solution code:
import sys

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

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

l = list(range(1, 101))
for p in P:
    l.pop(l.index(p))

dis_min = 1000
n = 1000
for i in l:
    dis = abs(i - X)
    if dis_min >= dis:
        if dis_min == dis:
            if n > i:
                n = i
        else:
            dis_min = dis
            n = i

print(n)

Submission status: Wrong Answer

Solution code:
import sys

x, n = map(int, input().split())
if n == 0:
  print(x)
  sys.exit()
li = list(map(int, input().split()))

i = 1
while i <= 100:
  if x - i not in li:
    print(x - i)
    break
  elif x + i not in li:
    print(x + i)
    break
  else:
    i += 1

Submission status: Wrong Answer

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

a=[]
b=[]

for i in range(-100,100):
    if  i not in p :
        a.append(abs(x-i))
        b.append(i)
ans=min(a)
bb=a.index(ans)
print(b[bb])

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
p_ans = [200] * 201
count = 0
for i in range(-100,101):
    if not(i in p):
        p_ans[count] = abs(x-i) 
    count += 1
p_min = min(p_ans)
for i in range(len(p_ans)):
    if p_min == p_ans[i]:
        print(i-100)
        exit()

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
l=list(map(int,input().split()))
loop = True
j = 1
while loop:
    if n == 0:
        print(x)
        break
    if x-j not in l:
        loop = False
        print(x-j)
        break
    elif x+j not in l:
        loop = False
        print(x+j)
    j+=1

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=[]
  for i in range(N):
    A.append(abs(P[i]-X))
  if 0 not in A:
    print(X)
  else:
    for i in range(1,N):
      if i not in A:
        print(X-i)
        break
      else:
        A.remove(i)
        if i not in A:
          if X+i in P:
            print(X-i)
            break
          if X-i in P:
            print(X+i)
            break
        else:
          A.remove(i)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  q=[i-X for i in p]
  qs=set(q)

  for i in range(N):
    if -i not in qs:
      print(X-i)
      break
    elif i not in qs:
      print(X+i)
      break

Submission status: Wrong Answer

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

def minusx(f):
    return f-x

if n !=0:
    plist =list(map(int,input().split(" ")))
    # print(x,n)
    # print(plist)
    plistx = list(map(minusx,plist))
    # print(plistx)
    plisty = list(map(abs,plistx))
    # print(plisty)
    plisty_max = max(plisty)
    
    newlist = list(range(x-plisty_max,x+plisty_max+1))
    # print(newlist)
    pset_diff = set(plist) ^ set(newlist)
    plist_diff = list(pset_diff)
    # print(plist_diff)

    for i in range(200):
        if x-i in plist_diff:
            if x-i >= 1:
                print(x-i)
                break
            else:
                pass
        elif x+i in plist_diff:
            if x+i <= 100:
                print(x+i)
                break
            else:
                pass
else:
    print(x)

Submission status: Wrong Answer

Solution code:
x, n = input().split()
x = int(x)
n = int(n)
m = list(map(int,input().split()))
sa = 999
ans = 0

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

for k in range(1,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 -x):
    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 = input().split()

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

def check(x,n):
    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))

        # この二つのうちのどちらかがp＿listに含まれるかを求める
        if min_x in p_list and max_x in p_list:
            continue
        else:
            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)
    exit()

p = list(map(int,input().split()))
p.sort()
q = [i for i in range(-1000,1000)]
li = set(p) ^ set(q)
tmp = 1
ans = 0
while(1):
    if X-tmp in li:
        ans = X-tmp
        break
    elif X+tmp in li:
        ans = X+tmp
        break
    tmp += 1
print(ans)

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()))
if N==1:
    
    if X!=P:
        print(X)
        sys.exit()
    if X==P:
        print(X-1)
        sys.exit()
PP=sorted(P, reverse=True)
sab=abs(X-P[0])
#print(PP[0])
for i in range(N):
    if PP.count(X-i)==0 :
        print(X-i)
        sys.exit()
    if PP.count(X+i)==0:
        
        print(X+i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
X , N =map(int,input().split())
if N == 0:
    print(X)
elif N == 1:
    P = int(input())
    j = 1
    if X + 1 == P or X - P > 1:
        print(X - 1)
    else:
        print(X + 1)

else:
    P = list(map(int,input().split()))
    j = 1
    while True:
        if X - j not in P:
            print(X - j)
            break
        if X + j not in P:
            print(X + j)
            break
        j += 1

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int,input().split())
    li = list(map(int,input().split()))
    li2 = []
    ans = 0
    for i in range(101):
        check = True
        for j in li:
            if j == i:
                check = False
        if check:
            li2.append(i)
    for i in li2:
        if abs(ans - x) >= abs(i - x):
            ans = i
    print(ans)
 
 
if __name__ == '__main__':
    main()

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