Problem:


Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Wrong Answer

Solution code:
import 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(1, 101)]
    for i in range(100):
        if numlist[i] in p:
            numlist[i] = -1
    cnt = 0
    for i, numele in enumerate(numlist):
        if ans > abs(x - (numlist[i])):
            ans = abs(x - numlist[i])
            cnt = i+1
    if cnt > 0:
        print(cnt)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
import math
import itertools
import collections

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

s = set(P)

m = 1000
ans = None
for i in range(-101,101):
    if i not in s:
        if m > abs(X-i):
            ans = i
            m = abs(X-i)

print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
ans = 100000000
l = 1000000
for i in range(1,101):
    if P.count(i) == 0:
        #print(i)
        if abs(i-X) == l:
            ans = min(i,ans)
        elif abs(i - X) < l:
            l = abs(i - X)
            ans = i
            #print(ans,i,l)
print(ans)

Submission status: Wrong Answer

Solution code:
'''
Author : Shubhanshu Jain;
'''

import math
import random;
from collections import defaultdict 
mod =1000000007
r1 = lambda : int(input());
rm = lambda : map(int,input().split());
rms = lambda : map(str,input().split());
rls = lambda : list(rm())

def solve():
    x,n = rm();
    ls = rls();
    ar = [0]*101;
    for i in ls:
        ar[i]= 1;
    f = x;end = x;
    # ar[x]=1
    while(f>=1 or end<=100):
        if(f<0):
            print(f);
            break;
        if(end>100):
            print(end);
            break;
        if(f>=0 and ar[f]==0):
            print(f);
            break;
        if(end<=100 and ar[end]==0):
            print(end);
            break;
        f-=1;
        end+=1;
            
        





def def_value(): 
	return "nan"
	
solve();

Submission status: Wrong Answer

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

if n != 0:
    ps = list(map(int, input().split()))

    ans = 0
    sa = x
    
    for i in range(0, 102):
        if i not in ps and abs(x-i) < sa:
            ans = i
            sa = x-i
            print(ans, sa)
    
    print(ans)
    
else:
    print(x)

Submission status: Wrong Answer

Solution code:
x,n=list(map(int,input().split()))
if n:
  A=list(map(int,input().split()))
else:
  print(x)
  exit()
  
for i in range(n):
  if x-i in A and x+i in A:
    continue
  if x-i in A:
    print(x+i)
    break
  else:
    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()))

    check = [True]*101

    for i in p:
        check[i] = False

    mini = 100000
    index = 1

    for i in range(1,101):
        if check[i]:
            if mini > abs(x-i):
                #print(mini, abs(x-i), i)
                mini = abs(x-i)
                index = i
    print(index)

Submission status: Wrong Answer

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

    e_min=1000
    r=[]
    for i in range(min(p)):
        if (x-i in p):
            pass
        else:
            print(x-i)
            break
        if (x+i in p):
            pass
        else:
            print(x+i)
            break
else:
    print(x)

Submission status: Wrong Answer

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

mindif = 1000
candidate = 0
for i in range(-1, 101):
    if abs(i - X) < mindif and i not in p:
        mindif = abs(i - X)
        candidate = i

print(candidate)

Submission status: Wrong Answer

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

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

min_diff_val = X
min_val = 0
for y in range(20):
    if not (y in p):
        if min_diff_val > abs(y - X):
            min_val = y
            min_diff_val = abs(y - X)
print(min_val)

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

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n>0:
  p=list(map(int,input().split()))
else:
  p=[]
minx=0
absx=101
for i in range(101):
  if i in p:
    continue
  else:
    cabs=abs(x-i)
    if cabs < absx:
      absx=cabs
      minx=i
if absx==101:
  if x>50:
    minx=101
print(minx)

Submission status: Wrong Answer

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

if not X in p:
    print(X)
else:
    for i in range(1, N):
        if not X - i in p:
            print(X - i)
            exit()
        elif not X + i in p:
            print(X + i)
            exit()

Submission status: Wrong Answer

Solution code:
X,N= map(int,input().split())
p = list(map(int, input().split()))
p = sorted(p)
ans_tmp = 10**9+7
ans = 0
if len(p)==0:
    print(X)
else:
    for i in range(1,100):
        if i in p:
            continue
        else:
            tmp = abs(i-X)
            if tmp <ans_tmp:
                ans = i
            ans_tmp= min(tmp,ans_tmp)
print(ans)

Submission status: Wrong Answer

Solution code:

x,y=map(int,input().split())
a=set(list(map(int,input().split())))
if y==0:
    print(x)
else:
    b=[i for i in range(1,105)]
    b=set(b)
    c=list(b-a)
    c.append(x)
    c.sort()

    r=c.index(x)
    if r>0:
        p=abs(c[r]-c[r-1])
        q=abs(c[r]-c[r+1])
        if p==q:
            print(min(c[r-1],c[r+1]))
        elif p>q:
            print(c[r+1])
        else:
            print(c[r-1])
    else:
        print(c[r+1])

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P =  set(map(int, input().split()))
Nums = set(range(1, 101))
Nums = Nums - P
sorted(Nums)


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

print(minIndex)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    X, N = map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    L = []
    for i in range(1, 101):
        if not i in P:
            L.append(i)
    #print(L)
    ans = 1000
    for l in L:
        ans = min(ans, abs(X-l))
        
    if (X-ans) in P:
        print(X+ans)
    else:
        print(X-ans)




if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

if p == []:
    print(x)
    exit()

tmp1 = x
tmp2 = x

for i in range(1,500):
    tmp1 = tmp1 - 1
    tmp2 = tmp2 + 1
    if tmp1 not in p:
        print(tmp1)
        exit()
    if tmp2 not in p: 
        print(tmp2)
        exit()

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

    P = sorted(P)

    mini = -1
    for i in range(101):
        if i in P:
            continue
        if abs(X - i) < abs(X-mini):
            mini = i
    
    print(mini)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
if b == 0:
    print(a)
else:
    c = list(map(int,input().split()))
    for i in range(1,b+1):
        if (a-i not in c) or (a+i not in c):
            if a -i not in c:
                print(a-i)
                break
            else:
                print(a+i)
                break

Submission status: Wrong Answer

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

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

cnt = [0] *101
ans1 = 0
ans2 = 0

for _p in p:
    cnt[_p] += 1

for i in range(x, 101):
    if cnt[i] == 0:
        ans1 = i
        break

for i in range(x-1, -100, -1):
    if cnt[i] == 0:
        ans2 = i
        break

if abs(ans1 - x) < abs(ans2 - x):
    print(ans1)
elif abs(ans1 - x) >= abs(ans2 - x):
    print(ans2)

Submission status: Wrong Answer

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

ze = [0 for i in range(101)]

for i in range(n):
  ze[abs(x-l[i])] += 1
  
if ze[0] == 0:
  print(x)
else:
  for i in range(1, 101):
    if ze[i] != 2:
      if x+i not in l:
        print(x+i)
        break
      else:
        print(x-i)
        break

Submission status: Wrong Answer

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

if n == 0:
    print(x)
else:
    left = x-1
    right = x+1
    while True:
        if not left in p:
            print(left)
            exit()
        if not right in p:
            print(right)
            exit()
        left -= 1
        right += 1
        if left < 0 and right > 100:
            break

Submission status: Wrong Answer

Solution code:
in_1 = [int(x) for x in input().split(' ')]
x = in_1[0]
n = in_1[1]
result = 0

# n=0の場合、resultにxを設定する
if n == 0:
  result = x
# 絶対値が小さい順にin_dataに含まれるか検索し、含まれなければresultにx-i,もしくはx+1を設定する
else:
  in_data = [int(x) for x in input().split(' ')]
  for i in range(100):
    tmp_m = max(x-i,0)
    tmp_p = min(x+i,100)
#    print('tmp_m:{}'.format(tmp_m))
#    print('tmp_p:{}'.format(tmp_p))
    if tmp_m not in in_data:
      result = tmp_m
      break
    if tmp_p not in in_data:
      result = tmp_p
      break

print(result)

Submission status: Wrong Answer

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

if len(p)==0:
  print(x)
  exit(0)

ans=1
while True:
  if x-ans not in p:
    print(x-ans)
    exit(0)
  elif x+ans not in p:
    print(x+ans)
    exit(0)
  ans+=1

Submission status: Wrong Answer

Solution code:
# coding: utf-8
X,N=map(int,input().split())
P=[]
if N!=0:
    P=list(map(int,input().split()))
K=[]
for i in range(1,102):
    if not(i in P):
        K.append(i)

ans=[]

for i in range(len(K)):
    ans.append([abs(X-K[i]),K[i]])

ans.sort()

A=[]

for i in range(len(ans)):
    if ans[i][0]==ans[0][0]:
        A.append(ans[i][1])

print(min(A))

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n != 0:
    p = set(map(int, input().split()))
else:
    p = {}
nums = []
for i in range(0, 102):
    nums.append(i)
nums_set = set(nums)
rest = nums_set.difference(p)
minVal = 101
for j in rest:
    if abs(minVal-x) > abs(x - j):
        minVal = j
    else:
        pass
print(minVal)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
li = list(map(int,input().split()))
li.sort()
try:
    idx = li.index(x)
    i = 0
    while(1):
        i = i+1
        if(li[idx-i]!=x-i):
            print(x-i)
            break
        elif(li[idx+i]!=x+i):
            print(x+i)
            break
except:
    print(x)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
p=[]
for j in range(X*2):
    if j in P:
        a=0
    else:
        p.append(j)
result=1000
answer=1000
for i in range(X*2-N):
    if abs(X-p[i])<result:
        answer=p[i]
        result=abs(X-p[i])
    elif abs(X-p[i])==result and p[i]<=answer:
        answer=p[i]
print(answer)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = [int(p) for p in input().split()]
A = X
B = X

while True:
  if B in P:
    B += 1
  else:
    break

while True:
  if A in P:
    A -= 1
  else:
    break


print(min(A, B))

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split(" "))
minimum = 0
if N!=0:
  P = list(map(int,input().split(" ")))
  for i in range(101):
    if (abs(X-minimum)>abs(X-i)) and (i not in P):
      minimum = i
  print(minimum)
else:
  print(X)

Submission status: Wrong Answer

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

if N == 0:
  print(X)
elif N == 100:
  if X > 50:  
    print(101)
  else:
    print(0)
else:
  List = list(map(int,input().split()))
  List.sort()

  c = 10 ** 10
  ans = 1000

  for i in range(1,100):
    if not i in List:
      if abs(i - X) < c:
        c = abs(i-X)
        ans = i
      
  print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    pn = list(map(int, input().split()))
    is_ex_list = [False for i in range(max(pn) + 1)]
    for p in pn:
        is_ex_list[p] = True
    min_v = x
    min_f = 0
    for i in range(max(pn) + 1):
        if not is_ex_list[i] and abs(x - i) < min_v:
            min_v = abs(x - i)
            min_f = i
    print(min_f)

Submission status: Wrong Answer

Solution code:
import sys
#sys.exit()
#sorted( ,reverse=True)
#N = int(input())
X, N = map(int, input().split())
P = list(map(int, input().split()))


if N ==0:
    print(X)
    sys.exit()
    
elif X not in P:
    print(X)
    sys.exit()

for i in range(1,N//2+1):
    #print(X-i,X+i)
    if (X -i) not in P:
        print(X-i)
        sys.exit()
    elif (X+i) not in P:
        print(X+i)
        sys.exit()
        

#A = [int(input()) for _ in range(N)]

#cnt = 0
#cnt += 1



#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')
#print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    X, N = map(int, input().split())
    p = set(list(map(int, input().split())))
    table = set()
    for i in range(1, 101):
        table.add(i)
    table = table - p
    lis = list(table)
    ans = -1
    diff = 10 ** 9
    for i, a in enumerate(lis):
        if abs(a-X) < diff:
            diff = abs(a-X)
            ans = a
        elif abs(a-X) == diff:
            ans = min(ans, a)
    if abs(X-ans) > abs(X):
        ans = 0
    elif abs(X-ans) > abs(X-101):
        ans = 101
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = 0
j = 0 
for i in range(-1, 101):
    if j != n and p[j] == i:
        j += 1
        continue
    if abs(i - x) < abs(ans - x):
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

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


def ipl():
    return sys.stdin.readline().split()


def solve():
    x, n = map(int, ipl())
    li = list(map(int, ipl()))
    freq = defaultdict(int)
    for i in li:
        freq[i] = 1
    i, j = x, x
    while freq[i]:
        i -= 1
    while freq[j]:
        j += 1
    if abs(i - x) < abs(j - x):
        print(i)
    else:
        print(j)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math


def get_int():
    return int(stdin.readline().strip())


def get_tuple():
    return map(int, stdin.readline().split())


def get_list():
    return list(map(int, stdin.readline().split()))

x,n = get_tuple()
ls = get_list()
if n==0: print(x)
else:
    st = set()
    for i in range(-99,201): st.add(i)
    ls = set(ls)
    for val in ls:
        st.remove(val)

    ans ,mini = float('inf'),float('inf')
    for val in st:
        diff = abs(val-x)
        if diff>0:
            if mini>diff:
                mini = diff
                ans = val
    print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if(N==0):
    print(X)
else:
    P = [int(i) for i in input().split()]
    A = []
    for i in range(101):
        if not i in P:
            A.append([abs(X-i),i])

    A.sort()
    s = A[0][0]
    B = [[i,j] for i,j in A if i==s]
    B.sort(key = lambda x:x[1])
    print(B[0][1])

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()))
mylist = [i for i in range(-1,102)]
#print(mylist)
mymin = float('INF')
mynum = 0

for i in range(102):
    if abs(mylist[i] - X) < mymin and mylist[i] not in p:
        mymin = abs(mylist[i] - X)
        mynum = i
print(mylist[mynum])

Submission status: Wrong Answer

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

ans = 10 ** 9
num = 0
a = [0] * 101
for i in range(len(p)):
    a[p[i]] = 1

for i in range(101):
    if a[i] == 1:
        continue

    if ans > abs(i - x):
        num = i
        ans = abs(i - x)
print(num)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    x, n = map(int, input().split())
    if n >0:
        a = [int(i) for i in input().split()]
        listN = [i for i in range(100)]
        diffList = list(set(listN) -set(a) )
        ans = 0
        diff = 100
        for i in diffList:
            now = abs(i-x)
            if diff > now:
                diff=now
                ans =i
        if n==100:
            print(x)
        else:
            print(ans)
    else:
        print(x)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
not_p = []
if n != 0:
    p = list(map(int, input().split()))
    not_p = [i for i in range(1,101) if i not in p]
else:
    not_p = [i for i in range(1, 101)]

mn = 100
ans = 101
for i in not_p:
    d = abs(x - i)
    if mn > d:
        mn = d
        ans = i

print(ans)

Submission status: Wrong Answer

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


min= 1000

p.sort()

for i in range(101):
  if (i not in p ) and len(p) > 0:
    a = abs(i-X)
    if a<min:
      min=a
      ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
if n == 0:
    ans = x
else:
    p = sorted(p)
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = 10000
    for i in range(min_p+1, max_p):
        if i == p[j+1]:
            j += 1
        else:
            if abs(ans-x) > abs(i-x):
                ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
li = []
for i in range(101):
    li.append(i)
lis = set(li)
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
lia = list(map(int,input().split()))
lias = set(lia)
seta = lis - lias
li = list(seta)
li.reverse()
a = 1000
b = 0
for i in range(101-n):
    if abs(li[i]-x) <= a:
        a = abs(li[i]-x)
        b = li[i]
print(b)

Submission status: Wrong Answer

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

  ans = X;
  min_value = 100

  if N == 0:
    print(ans)
  else:

    a = [i for i in range(0, 101)]

    for v in p:
      a[v] = -1

    for i in range(0, 101):
      if a[i] != -1:
        d = abs(X - a[i])

        if(min_value > d):
          min_value = d
          ans = i

  print(ans);

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = sorted(map(int, input().split()))
    nums = [num for num in range(101) if not num in p]
    A = [abs(num - X) for num in nums]
    print(nums[A.index(min(A))])

Submission status: Wrong Answer

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

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

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

for i in range(1,101):
    if i in p:
        continue
    s = min(abs(x-i),s)
        
if not x - s in p: 
    print(x - s)
else :
    print(x + s)

Submission status: Wrong Answer

Solution code:
k = list(map(int, input().split()))
if k[1] == 0:
  print(k[0])
else:
  l = list(map(int, input().split()))

  a = [i for i in range(101) if not i in l]
  m = []
  for i in a:
    m.append(abs(i - k[0]))

  print(a[m.index(min(m))])

Submission status: Wrong Answer

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

print(i)

Submission status: Wrong Answer

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

if N == 0:
    print(X)

else:
    n2 = input().split()
    p = [int(item) for item in n2]

    for i in range(100):
        if i == 0:
            continue
        tmp = []

        if (X + i not in p ) and (X + i < 101):
            tmp.append(X + i)

        if (X - i not in p ) and (X - i > 0):
            tmp.append(X - i)
    
        if len(tmp)!=0:
            print(min(tmp))
            break

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
try:
  p=list(map(int,input().split()))
except:
  print(x)
  exit()
ans=float('inf')
for i in range(1,101):
  if i not in p:
    ans=min(ans,abs(x-i))
    
    
if x-ans not in p:
  print(x-ans)
  exit()
else:
  print(x+ans)

Submission status: Wrong Answer

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

nota = list()

for i in range(1, 101):
    if i in a:
        continue
    nota.append(i)

print(nota)
nota.sort()
ans = 1000
minabs = 1000
for i in nota:
    if minabs > abs(i-x):
        minabs = abs(i-x)
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
x, n = map(int, input().split())
p = list(map(int, input().split()))
if (n == 0):
    print(x)
    sys.exit()
diff = 1000
ans = 0
p.sort()
diff=1000
for i in range(100):
    if (i in p):
       continue
    else:
        if (abs(x - i) < diff):
            diff = abs(x - i)
            ans = i
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()))

n_ans = 1
sa = 100
for k in range(1,100,1):
    if (k in p):
        continue
    if(abs(k-X) < sa):
        n_ans = k
        sa = abs(k-X)
    else:
        break
print(n_ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n!=0:
    p = list(map(int,input().split()))
    li = set([i for i in range(1,101)])
    li = li-set(p)
    k=10**9
    m=0
    li=sorted(list(li))
    for i in li:
        if k>abs(x-i):
            k=abs(x-i)
            m=i
    print(m)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
b = n // 2 + 1
for i in range(b):
    if (x - i) not in p:
        print(x - i)
        break
    elif (x + i) not in p:
        print(x + i)

Submission status: Wrong Answer

Solution code:
import sys

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

A = list(map(int,stdin.readline().split()))
B = list(map(int,stdin.readline().split()))
C = [x for x in range(-100,101)]

C = set(C)
B = set(B)
C = C.difference(B)
C = list(C)
X=A[0]
N=A[1]
record=max(C)
number=0
K=0

if N==0:
    print(X)
    K=1

for t in C:
    diff=abs(t-X)
    if diff<record:
        record=diff
        number=t
    elif diff==record:
        number=min(number,t)

if K==0:
   print(number)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split(" "))
minimum = 0
if N!=0:
  P = list(map(int,input().split(" ")))
  for i in range(100):
    if (abs(X-minimum)>abs(X-i)) and (i not in P):
      minimum = i
  print(minimum)
else:
  print(X)

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
tmp=0
if n==0:
    print(x)
    sys.exit()
for i in range(1,101):
    ans=x-i
    if not ans in p:
        print(ans)
        sys.exit()

Submission status: Wrong Answer

Solution code:
'''
Author : Shubhanshu Jain;
'''

import math
import random;
from collections import defaultdict 
mod =1000000007
r1 = lambda : int(input());
rm = lambda : map(int,input().split());
rms = lambda : map(str,input().split());
rls = lambda : list(rm())

def solve():
    x,n = rm();
    ls = rls();
    ar = [0]*101;
    for i in ls:
        ar[i]= 1;
    f = x;end = x;
    # ar[x]=1
    while(f>=1 or end<=100):
        if(f<0):
            print(f);
            break;
        if(f>100):
            print(f);
            break;
        if(f>=0 and ar[f]==0):
            print(f);
            break;
        if(end<=100 and ar[end]==0):
            print(end);
            break;
        f-=1;
        end+=1;
            
        





def def_value(): 
	return "nan"
	
solve();

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
ans = 0
if n == 0:
    print(x)
else:
    p = sorted(list(map(int,input().split())), reverse=True)
    data = []
    for i in range(100,0,-1):
        if not(i in p):
            data.append(i)
    #print(data)
    mi = 1000
    for i in data:
        #print(p)
        if mi >= abs(i-x):
            mi = abs(i-x)
            ans = i
    print(ans)

Submission status: Wrong Answer

Solution code:
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
b=sorted(b)
base = 0
for i in range(1, 101):
  if abs(a[0]-base)>abs(a[0]-i) and i not in b:
    base = i
print(base)

Submission status: Wrong Answer

Solution code:
# C

import bisect

x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p_list = {int(x) for x in input().split()}
    q_list = {int(x) for x in range(101)}
    q_list = list(q_list - p_list)

    p = bisect.bisect_left(q_list, x)
    if p == 0:
        print(q_list[p])
    elif p == len(q_list):
        print(q_list[p-1])
    else:
        if abs(q_list[p-1] - x) <= abs(q_list[p] - x):
            print(q_list[p-1])
        else:
            print(q_list[p])

Submission status: Wrong Answer

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

min_val = -1
for i in range(12):
    if i in P:
        continue
    if abs(min_val - X) > abs(X - i):
        min_val = i
if len(P) == 0:
    print(X)
else:
    print(min_val)

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 b < a:
        a = b
        ans = i
    else:
      pass
  print(ans)

Submission status: Wrong Answer

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

if n == 0:
  print(x)

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

ans = 100000
for i in range(101):
    if not i in p:
        if abs(i - x) < abs(ans - x):
            ans = i
            
print(ans)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque, Counter
from sys import exit
import math
import copy
from bisect import bisect_right

import sys
sys.setrecursionlimit(1000000)
import heapq
INF = 10**10

def dijkstra(graph, start, n):
    h = []
    heapq.heappush(h, (0, start))
    costs = [INF for _ in range(n)]
    while h:
     cost, cur = heapq.heappop(h)
     if costs[cur] != INF:
         continue
     costs[cur] = cost
     for edge in graph[cur]:
         ecost, tgt = edge
         if costs[tgt] == INF:
             heapq.heappush(h, (cost + ecost, tgt))

    return costs

def main():
    x, n = getList()
    nums = getList()
    ans = -1
    tmp = 100000
    for i in range(1, 201):
        if i not in nums and abs(i - x) < tmp:
            ans = i
            tmp = abs(i - x)

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

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
p_bar=[]
for i in range(0,101):
  if i not in p:
    p_bar.append(i)

d_min=1000
for i in p_bar:
  d = abs(X-i)
  if d < d_min:
    d_min = d
if X-d_min >= 0:
  print(X-d_min)
else:
  print(X+d_min)

Submission status: Wrong Answer

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


min= 1000

p.sort()

for i in range(100):
  if (i not in p ) and len(p) > 0:
    a = abs(i-X)
    if a<min:
      min=a
      ans = i
print(ans)