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:
    p = list(map(int, input().split()))
else:
    print(x)
    exit()
ABS = 10 ** 9
ans = 0
for i in range(1, 101):
    if i in p:continue

    temp = abs(i - x)
    if ABS > temp:
        ABS = temp
        ans = i
    else:
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if X>=51:
    ans=101
else:
    ans=0
p=list(map(int,input().split()))
for i in range(1,101):
    if i in p:
        p.remove(i)
    else:
        p.append(i)
for i in range(100-N):
    if abs(X-p[i])<abs(X-ans):
        ans=p[i]
print(ans)

Submission status: Wrong Answer

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

if X not in P:
    print(X)
else:
    for i in range(50):
        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( ))
x = set(list(map(int,input().split( ))))
all_num = {i for i in range(1,101)}
ans = 1000
ans_num = 1000
for i in list(all_num - x):
    if abs(X - i) < ans_num:
        ans_num = abs(X-i)
        ans = i
    elif abs(X-i) == ans_num and i < ans :
        ans_num = abs(X-i)
        ans = i
print(ans)

Submission status: Wrong Answer

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

    i = 1
    while p:
        if X - i in p:
            p.remove(X - i)
        else:
            return (X - i)

        if X + i in p:
            p.remove(X + i)
        else:
            return (X + i)
        i += 1
    return X


print(main())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	x, n = map(int, sys.stdin.readline().split())
	p = list(map(int, sys.stdin.readline().split()))
	p.sort()
	a = [0]*100
	if n == 0:
		print(x)
		exit()
	for i in range(n):
		a[p[i]-1] = 1
	i = x - 1
	log.print(p, i)
	lower = 0
	while i >= 0:
		log.print(i, a[i])
		if a[i] == 0:
			lower = i + 1
			break
		i -= 1
	i = x - 1
	upper = 0
	while i < 100:
		log.print(i, a[i])
		if a[i] == 0:
			upper = i + 1
			break
		i += 1
	if abs(x - lower) == abs(x - upper):
		print(lower)
		exit()
	if abs(x - lower) < abs(x - upper):
		print(lower)
	else:
		print(upper)

main()

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
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
ls = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    i, j = 1, 1
    while True:
        if x + i not in ls:
            num1 = x + i
            break
        else:
            i += 1

    while True:
        if x - j not in ls:
            num2 = x - j
            break
        else:
            j += 1

    if abs(x - num1) > abs(x - num2):
        print(num2)
    elif abs(x - num1) < abs(x - num2):
        print(num1)
    else:
        print(min(num1, num2))

Submission status: Wrong Answer

Solution code:

import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

X, N = nn()
P = nn()

if N == 0:
    print(X)
else:
    d = 999
    ans = -1
    for i in range(-100, 101):
        if (i in P):
            continue

        t = abs(X - i)
        if t < d:
            d = t
            ans = i

    print(ans)

Submission status: Wrong Answer

Solution code:
a,b = map(float,input().split())
p = list(map(int,input().split()))

t = 10000
for i in range(101,0,-1):
    if i not in p:
        if abs(a-i)<= t:
            ans = i
            t = abs(a-i)
        # print(t)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

X, N = map(int, input().split())
p = list(map(int, input().split()))
ans = X
queue = deque()
queue.append(X)
done_list = []
ans = []
while queue:
    print(queue)
    var = queue.popleft()
    if var in p:
        done_list.append(var)
        if var - 1 not in done_list:
            queue.append(var-1)
        if var + 1 not in done_list:
            queue.append(var+1)
        continue
    else:
        ans = var
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

X, N = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
l2 = [abs(int(x)-X) for x in l]
l2.sort()
t = 0
for i in range(N):
    if ceil(i/2) != l2[i]:
        t = ceil(i/2)
if X - t in l:
    print(X + t)
else:
    print(X - t)

Submission status: Wrong Answer

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

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

for i in range(1,len(p)):
    ans1 = X
    ans2 = X
    if X+i not in p:
        ans1 = X+i
    
    if X-i not in p and X-i >= 0:
        ans2 = X-i
    
    if ans1 != X and ans2 != X:
        print(ans2)
        exit()
    elif ans1 == X and ans2 != X:
        print(ans2)
        exit()
    elif ans1 != X and ans2 == X:
        print(ans1)
        exit()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
try:
  p = list(map(int, input().split()))
except EOFError:
  print(100)
  exit()
old_diff = 10000
for i in range(1, 101):
  if i in p:
    continue
  else:
    diff = abs(x-i)
    if diff < old_diff:
      ans = i
      old_diff = abs(x-i)

try:
  print(ans)
except:
  print()

Submission status: Wrong Answer

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

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

d = float("inf")
ans = -1
for n in range(101):
    if not n in P and abs(X - n) < d:
        ans = n
        d = abs(X - n)

print(ans)

Submission status: Wrong Answer

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

num = sorted([[abs(X - i),i] for i in range(101) if i not in P],key = lambda x: x[0])

print(num[0][1])

Submission status: Wrong Answer

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

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

alist = list(range(1,101))
for i in plist:
    alist.remove(i)

alist.sort()
alist.reverse()
ans = 0
count = 1000
for j in alist:
    if count >= abs(x - j):
        count = abs(x-j)
        ans = j

print(ans)

Submission status: Wrong Answer

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

p = list(map(int , input().split()))
ps = set(p)
o = []
for i in range(110):
    if i in ps:
        continue
    o.append(i)

m = 1000
ans = -1
for oi in reversed(o):
    if abs(x - oi) <= m:
        ans = oi
        m = abs(x - oi)

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int,input().split())
if n != 0:
  a = list(map(int,input().split()))
b = [i for i in range(-101,101)]
c = 1000

for i in range(n):
    b.remove(a[i])

for i in range(len(b)):
  if abs(b[i] - x) < abs(c - x):
      c = b[i]
  else:
      pass

print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
A = list(map(int, input().split()))
total = [i for i in range(1, 101)]
for i in range(len(A)):
    total[A[i]-1] = 10000
dif = [0]*100
for i in range(100):
    dif[i] = abs(X-total[i])
min_index = dif.index(min(dif))
if X < 0:
    min_index = X-1
print(min_index+1)

Submission status: Wrong Answer

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

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

for i in range(101):
    P.append(i)

MOD = 10**9+7
tmp = 0
m = 9999999999999
ans = 0

for i in range(N):
    P[p[i]] = MOD


for i in reversed(range(0,len(P))):
    tmp = abs(P[i]-X)
    m = min(m,tmp)
    if m == tmp:
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-14 21:12:01 +0900
# LastModified: 2020-06-14 21:17:16 +0900
#


import os
import sys
#import numpy as np
#import pandas as pd


def main():
    x,n = map(int,input().split())
    if n==0:
        print(x)
        return
    p = list(map(int,input().split()))
    for i in range(1,max(p)-min(p)):
        if not x-i in p:
            print(x-i)
            return 
        if not x+i in p:
            print(x+i)
            return
            


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

X, N = MAP()
p = LIST()

ans = 0
min_num = float("INF")
for i in range(1, 101):
    if i in p:
        continue
    
    if min_num > abs(X-i):
        min_num = abs(X-i)
        ans = i


print(ans)

Submission status: Wrong Answer

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

for i in range(N//2 + 1):
    A = X - i
    if A not in P:
        print(A)
        exit() 
    B = X + i
    if B not in P:
        print(B)
        exit()

Submission status: Wrong Answer

Solution code:
X, N = map( int, input().split() )
if N > 0:
  P = sorted( list( map( int, input().split() ) ))
  ret = -1
  dis = 10 ** 18
  for i in range( 1, 100 + 1 ):
    if i in P:
      continue
    if dis - abs( i - X ) > 0:
      ret = i
      dis = abs( i - X )
else:
  ret = X
print( ret )

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n==0:
    print(x)
else:
    p = list(map(int,input().split()))
    k = [0]*100
    a = [i+1 for i in range(100)]
    ans = 101
    ans_x = 101
    for i in p:
        k[i-1]=1
    for i in range(x-1,100):
        if k[i]==0:
            if ans_x > abs(x-a[i]):
                ans,ans_x = a[i],abs(x-a[i])
                break
    for i in range(x-1,0,-1):
        if k[i]==0:
            if ans_x >= abs(x-a[i]):
                ans,ans_x = a[i],abs(x-a[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()))

exist = [False] * 101
for pi in p:
  exist[pi] = True
  
minabs = X
ans = 0
for i in range(101):
  if exist[i]:
    continue
  if abs(X-i) < minabs:
    ans = i
    minabs = abs(X-i)
    
print(ans)

Submission status: Wrong Answer

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

if N == 0:
    print(X)
else:
    a = [int(i) for i in range(1, 101) if not i in p]
    m = 100
    val = 0
    for i in a:
        if abs(i-X) < m:
            m = abs(i-X)
            val = i
    print(val)

Submission status: Wrong Answer

Solution code:

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

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

Sa=[]

for i in range(1,100):
    ma=X+i
    mi=X-i
    if mi not in P:
        print(mi)
        sys.exit()
    elif ma not in P:
        print(ma)
        sys.exit()

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 i in range(50):
    if not x-i in p:
        print(x-i)
        break
    if not x+i in p:
        print(x+i)
        break

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
if b==0:
  print(a)
  exit()
s=list(map(int,input().split()))

lst=[i for i in range(-100,101)]
for j in range(b):
  lst.remove(s[j])

n=100
for k in lst:
  m=abs(a-k)
  n=min(n,m)

if (a-n) in lst:
  print(a-n)
  exit()
else:
  print(a+n)

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;
    if(n==100):
        print(0);
    # ar[x]=1
    else:
        while(f>=1 or end<=100):
            if(f>=1 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:
    print(X)
    exit(0)
l = list(map(int, input().split()))

n = 0
while True:
    n += 1
    candidate = X - n
    if candidate not in l:
        print(candidate)
        break
    candidate = X + n
    if candidate not in l:
        print(candidate)
        break

Submission status: Wrong Answer

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

X,N=(int(x) for x in input().rstrip('\n').split())
ps=[int(x) for x in input().rstrip('\n').split()]
if N==0:
  print(X)
else:
  for i in range(X):
    if X-i not in ps:
      print(X-i)
      break
    elif X+i not in ps:
      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()))

    p.sort()
    gap = 10**1000
    ans =10**1000
    for i in p:
        if gap > abs(i-x) :
            ans = i
            gap =abs(i-x)



    print(ans)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    X,N = map(int, input().split())
    if N==0:
        input()
        print(X)
        return 
    A = list(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    
    A.sort()
    a=A
    i=bisect_left(A,X)

    if A[i]!=X:
        print(X)
        return
    
    j=i-1
    cur=X
    amin=0
    while j>=0:
        if abs(a[j]-cur)<2:
            cur=a[j]
            j-=1
            continue
        else:
            amin=cur-1
            break
    j=i+1
    amax=max(A)+1
    cur=X
    while j<=len(A)-1:

        if abs(a[j]-cur)<2:
            cur=a[j]
            j+=1
            continue
        else:
            amax=cur+1
            break
    
    if abs(amin-X)<=abs(amax-X):
        print(amin)
    else:
        print(amax)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    NP = list()

    for i in range(-100, 101):
        if i in P:
            pass
        else:
            NP.append(i)

    mi = 10000

    for i in range(len(NP)):
        diff = abs(NP[i] - X)

        if diff < mi:
            mi = diff

    ans = list()

    for i in range(len(NP)):
        if abs(NP[i] - X) == mi:
            ans.append(NP[i])

    ans.sort()
    print(min(ans))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


for i in range(0,100+1):
    
    for j in range(0,100+1):
        if i + j > X:
            break
        if (i*2 + j*4) == Y and (i+j) == X:
            print('Yes')
            exit()

print('No')

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,100):
    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:
x,n=map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
msf = 1000
for i in range(100,0,-1):
    if i not in lis:
        diff = abs(i-x)
        if(min(diff,msf)==diff):
            msf = diff
            ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]
ans = -1
tmp = 1000
for i in range(1, 101):
    if i in P: continue
    if abs(X-i) < tmp:
        ans = i
        tmp = abs(X-i)
print(ans)

Submission status: Wrong Answer

Solution code:

def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    A=list(map(int,input().split()))
    if A[1]==0:
        print(A[0])
        sys.exit()
    p=list(map(int,input().split()))
    
    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, n = map(int, input().split())
p = list(map(int, input().split()))
v = 1
if not n:
	print(x)
	exit()
while True:
	if x-v not in p:
		print(abs(x-v))
		break
	elif x+v not in p:
		print(x+v)
		break

	v += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

  

A = [i for i in range(1, 101)]
B = set(A) - set(P)

for i in range(101):
  if X - i in B:
    print(X-i)
    exit()
  elif X + i in B:
    print(X + i)
    exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def solve(x, n, p):
    p = set(p)
    best = None
    best_diff = float("inf")
    for item in range(1, 101):
        if item not in p and abs(item - x) < best_diff:
            best_diff = abs(item - x)
            best = item
        if abs(-item - x) <= best_diff:
            best_diff = abs(-item - x)
            best = -item
    return best


if __name__ == "__main__":
    x, n = arr_in()
    if n == 0:
        out(x)
        exit()
    p = arr_in()
    out(solve(x, n, p))

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
    quit()
p = set(map(int, input().split()))
not_p = set(range(1, 101)) - p
ans = 0
minval = 101
for i in not_p:
    if minval > abs(X - i):
        minval = abs(X - i)
        ans = i
print(ans)

Submission status: Wrong Answer

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

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

p.sort()
q = [i for i in range(101) if i not in p]

diff = [0] * len(q)
for i in range(len(q)):
      diff[i] = abs(q[i] - x)

index = diff.index(min(diff))
print(q[index])

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
List=list(map(int,input().split()))
num=list(range(1,101))
min_num=100
for i in range(len(List)):
    if num.count(List[i])>=1:
        num.remove(List[i])
for i in range(len(num)):
    if (abs(num[i]-x)<abs(min_num-x)) or (abs(num[i]-x)==abs(min_num-x) and num[i]<min_num):
        min_num=num[i]
print(min_num)

Submission status: Wrong Answer

Solution code:
import sys

X,N = (int(a) for a in input().split())
p = list(map(int,input().split()))

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

for i in range(N) :
    if X not in p :
        print(int(X))
        sys.exit()
    else :
        X = X + (i+1)* ( (-1)**(-(i+1)) )

Submission status: Wrong Answer

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

ans = x
diff = [0]*n

min_num = x
for i in range(101):
    if p.count(i) == 0:
        if min_num > abs(x-i):
            min_num = abs(x-i)
            ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
# fall 7, stand 8...
# !/ankit_SM/bin/env python

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def main():
    tinn=1; #tinn=int(input())
    for tin in range(tinn):
        x,n=map(int,input().split())
        a=list(map(int,input().split()))
        dic={}
        for _ in range(101):
            dic[_]=0;
        for _ in range(n):
            dic[a[_]]=1;
        mn=100000; val=0;
        for _ in range(101):
            if(dic[_]==0):
                if(mn>abs(x-_)):
                    mn=abs(x-_)
                    val=_
        print(val)


# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
    main()

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 n in range(1,100):
        if X-n >= 0 and X-n not in P:
            print(X-n)
            break
        elif X+n <= 100 and X+n not in P:
            print(X+n)
            break

Submission status: Wrong Answer

Solution code:
import numpy as np

X, N = map(int, input().split())
P = set(map(int, input().split()))
Q = set(range(101))
P = np.array(list(Q - P))
Q = np.abs(P - X)
Q = np.where(Q == Q.min())

print(P[Q].min())

Submission status: Wrong Answer

Solution code:
import bisect

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

p.sort()

temp = 100
temp2 = 0

if(n == 0):
    print(x)
else:
    for i in range(100):
        temp3 = abs(x-i)
        if(temp3 < temp):
            flag = 1
            for j in p:
                if(i == j):
                    flag = 0
            if(flag == 1):
                temp2 = i
                temp = temp3
    print(temp2)

Submission status: Wrong Answer

Solution code:
X,N = list(map(int,input().split()))
if N == 0:
  print(X)
  exit()
P = sorted(list(map(int,input().split())))
ans1 = P[0] - 1
ans2 = P[-1] + 1
for i in range(1,N):
  if P[i] == 0:
    break
  if P[i-1] != P[i]-1:
    ans1 = P[i] -1

for i in range(1,N):
  if P[-i] == 0:
    break
  if P[-i+1] != P[-i]+1:
    ans2 = P[-i] +1

aa1 = abs(X-ans1)
aa2 = abs(X-ans2)
if aa1 == aa2:
  print(ans1)
elif aa1 > aa2:
  print(ans2)
else:
  print(ans1)

Submission status: Wrong Answer

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

ans = 10000
idx = 0
for i in range(1, 101):
    if(abs(X-i) < ans):
        if(i not in pp):
            ans = abs(X-i)
            idx = i
if(X < ans):
    idx = 0 
print(idx)

Submission status: Wrong Answer

Solution code:
li = []
for i in range(100):
    li.append(i+1)
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(100-n):
    if abs(li[i]-x) <= a:
        a = abs(li[i]-x)
        b = li[i]
print(b)

Submission status: Wrong Answer

Solution code:
x, n = map(int,input().split())
if n != 0:
  a = list(map(int,input().split()))
b = [i for i in range(-100,101)]
c = 1000

for i in range(n):
    b.remove(a[i])

for i in range(len(b)):
  if abs(b[i] - x) < abs(c - x):
      c = b[i]
  else:
      pass

print(c)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
try:
    P = list(map(int, input().split()))
except:
    P = []
    
tmp = 10**9
ans = 10**9

if P:
    for p in range(0, 101):
        if p in P:
            continue
        abs_PX = abs(X-p)
        if abs_PX < tmp:
            ans = p
            tmp = abs_PX
else:
    ans = X

print(ans)

Submission status: Wrong Answer

Solution code:
# C - Forbidden List

X, N = map(int, input().split())
P = list(int(p) for p in input().split())
P = set(P)
INF = 10**18

ans = 0
tmp = INF
for i in range(101):
    if i not in P:
        if abs(i-X) < tmp:
            tmp = abs(i-X)
            ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p_li = list(map(int,input().split()))
p_li.sort()
if p_li.count(x) == 0:
    print(x)
    exit()
dum1 = x-1
dum2 = x+1
for i in range(n//2):
    if p_li.count(dum1) == 0:
        print(dum1)
        exit()
    if p_li.count(dum2) == 0:
        print(dum2)
        exit()
    dum1 -= 1
    dum2 += 1

Submission status: Wrong Answer

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

exist = [0] * 102
for pp in p:
    exist[pp] = 1

res = 101
diff = abs(res - x)
for i in range(101):
    if not exist[i] and (d := abs(i - x)) < diff:
        res = i
        diff = d
print(res)