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 math

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

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

p.sort()

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

if X < minimum or maximum < X:
    print(X)
    exit()

diff_min = abs(X - minimum - 1)
diff_max = abs(X - maximum + 1)
answer = minimum - 1 if diff_min < diff_max else maximum + 1
# answer = 9999
for candidate in range(minimum, maximum):
    if candidate in p: continue

    diff_answer = abs(X - answer)
    diff_candidate = abs(X - candidate)
    # print(candidate, diff, answer)
    answer = candidate if diff_candidate < diff_answer else answer

print(answer)

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    _near = -1
    for i in range(101):
        if i in p:
            continue
        if abs(_near - x) > abs(i - x):
                _near = i
    print(_near)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = map(int, input().split())
p_list = set([int(i) for i in input().split()])
set_all = set(np.arange(-101, 101))
ex_list = set_all-p_list
ex_list = list(ex_list)
diff_list = [np.abs(i-X) for i in ex_list]
min_index = np.argmin(diff_list)
print(ex_list[min_index])

Submission status: Wrong Answer

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

if N == 0:
    print(X)
else:
    for i in range(1,100):
        if i not in P:
            differ.append(abs(X - i))
        else:
            differ.append(1000)
    ans = differ.index(min(differ))+1
    print(ans)

Submission status: Wrong Answer

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

  if x<a[0]:
    print(x)
  elif x>a[-1]:
    print(x)
  else:
    b=list(range((a[0]-1),(a[-1]+1)))

    for n in range(n):
      b.remove(a[n])
  
    f=len(b)


    d=abs(x-int(b[0]))
    ans=b[0]

    for n in range(f):
      c=abs(x-int(b[n]))
      if d>c:
        ans=b[n]
        d=c
  
    print(ans)

except:
  print(x)

Submission status: Wrong Answer

Solution code:
import sys

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

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

li.sort()

result1 = 0
counter1 = 1
kekka1 = 0
while(True):

    try:
        result1 = li.index(x+counter1)
        kekka1 = li[result1]
        counter1 = counter1+1
    except ValueError as e:
        break

result2 = 0
counter2 = 1
kekka1 = 0
while(True):
    try:
        result2 = li.index(x-counter2)
        kekka1 = li[result2]
        counter2 = counter2+1
    except ValueError as e:
        break

if counter1 < counter2:
    print(x+counter1)
elif counter1 > counter2:
    print(x-counter2)
elif counter1 == counter2:
    print(x-counter2)

Submission status: Wrong Answer

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

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

a = [i for i in range(-100,201)]

for j in p:
    d = a.index(j)
    a.pop(d)

if (x in a):
    pass
else:
    a.append(x)
    a.sort()

idx_x = a.index(x)

if (idx_x == 0):
    print(a[idx_x+1])
    sys.exit()
if (idx_x == len(a)-1):
    print(a[-2])
    sys.exit()

lesser = a[idx_x-1]
greater = a[idx_x+1]

dl = x - lesser
dg = greater - x

if (dl <= dg):
    print(lesser)
else:
    print(greater)

Submission status: Wrong Answer

Solution code:
import math 
X, N = map(int,input().split())
d = int(999)
d1 = int()
ans = int(999)
if 0 < N:
    P = list(map(int,input().split()))
    for i in range(1,max(P)):
        if P.count(i) == 0:
            d1 = abs(X-i)
            if d1 < d and 0 <= d1:
                d = d1
                ans = i
    print(ans)
else:
    print(X)

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()))
p.sort()
wk = 101
wks = 101
an = 0

for i in range(1,101):
    if x!=i:
        if p.count(i)==0:
            if abs(x-i)<wk:
                an =i
                wk = abs(x-i)
            else:
                print(an)
                sys.exit()
print(an)

Submission status: Wrong Answer

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

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

min_abs = 100
min_num = -100

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

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = map(int, input().split())
if N==0:
  print(X)
  exit()
else:
  A = sorted(map(int, input().split()))

if A.count(X)==0:
  print(X)
  exit()

i=A.index(X)
l=len(A)-1

for k in range(N):
  if A.count(X-k)==0:
    print(X-k)
    exit()
  elif A.count(X+k)==0:
    print(X+k)
    exit()

Submission status: Wrong Answer

Solution code:
def inp():
    ls=list(map(int,input().split()))
    return ls
x,n=map(int,input().split())
ls=inp()
ls.sort()
if n==0:
    print(x)
    exit(0)
else:
    a=x-1
    b=x+1
    flag=False
    while(not flag):
        if a not in ls:
            print(a)
            exit(0)
        else:
            a-=1
        if b not in ls:
            print(b)
            exit(0)
        else:
            b+=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()))

    target_abs = [0]*1000

    for i in range(n):
        if abs(p[i]-x) >= 1000:
            continue
        elif p[i]-x > 0:
            target_abs[abs(p[i]-x)] += 2
        else:
            target_abs[abs(p[i]-x)] += 1

    ans = 0
    for i in range(1000):
        if i == 0:
            if target_abs[i] == 0:
                ans = x
        elif ans == 0:
            if target_abs[i] == 0:
                ans = x - i
            elif target_abs[i] == 1:
                ans = x + i
            elif target_abs[i] == 2:
                ans = x - i
    print(ans)

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-

import sys

def main():
    numbers=[]
    x,n = map(int,input().split())
    numbers=list(map(int,input().split()))
    if n==0:
        print(x)
        sys.exit()
    dp_list=list(range(-100, 101))
    dp_list=set(dp_list)-set(numbers)

    for i in range(101):
        if abs(x-i) in dp_list:
            print(x-i)
            break
        elif abs(x+i) in dp_list:
            print(x+i)
            break

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def readInt():
    return list(map(int,input().split()))
    
x,n = readInt()
a = []
if 0<n<100:
    p = readInt()
    p_r = [int(i) for i in range(101) if i not in p]
    # print(p_r)
    for i in p_r:
        dif = abs(x-i)
        a.append(dif)
    # print(a)
    print(p_r[a.index(min(a))])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N > 0:
  p = list(map(int,input().split()))
a = 101
ans = 0
for i in range(-1,101):
  if N == 0:
    ans = X
    break
  if p.count(i) == 0 and a >= abs(X - i):
    a = abs(X - i)
    ans = i
for i in range(-1,101):
  if a == abs(X - i):
    ans = i
    break
print(ans)

Submission status: Wrong Answer

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

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    while True:
        x1 -= 1
        x2 += 1
        
        if x1 not in p:
            print(x1)
            break
        if x2 not in p:
            print(x2)
            break

Submission status: Wrong Answer

Solution code:
import sys
X, N = map(int, input().split())
l = (int(i) for i in input().split())
if N == 0:
  print(X)

QUEUE = set()
def search(x):
  global QUEUE
  small = x - 1
  large = x + 1
  if small in QUEUE or large in QUEUE:
    return
  else:
    QUEUE.add(small)
    QUEUE.add(large)
    if not small in l:
      print(small)
      sys.exit(0)
    elif not large in l:
      print(large)
      sys.exit(0)
search(X)

Submission status: Wrong Answer

Solution code:
import sys

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

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

comp = 101
for i in range(100):
    x = abs(X - i)
    if comp > x and i not in p:
        comp = x
        result = i

print(result)

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(-10,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())
not_p = []
if n != 0:
    p = list(map(int, input().split()))
    not_p = [i for i in range(201) if i not in p]
else:
    not_p = [i for i in range(201)]
print(not_p)
mn = 101
ans = 100
for i in not_p:
    d = abs(x - i)
    if mn > d:
        mn = d
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

x, n = map(int, input().split())
pn = list(map(int, sys.stdin.readline().rstrip().split()))

qn = set([i for i in range(0,102)]) - set(pn)

qn = list(qn)

for i in range(102-n):
    if qn[i]==x:
        print(x)
        exit(0)
    elif x-qn[i+1]<0:
        if x-qn[i] <= qn[i+1]-x:
            print(qn[i])
            exit(0)
        else:
            print(qn[i+1])
            exit(0)

Submission status: Wrong Answer

Solution code:
k,n=map(int,input().split())
l=list(map(int,input().split()))
a=[]
for i in range (500):
	a.append(0)
x=0
for i in range(n):
	x=l[i]-k
	
	if x<0:
		a[2*abs(x)-1]=1
		
		
	else :
		a[2*x]=1
for i in range(200):
	if(a[i]==0):
		break
if(i%2==0):
	x=i/2
	print(k+x)
else:
	x=(i+1)/2
	print(k-i)

Submission status: Wrong Answer

Solution code:
str1 = input()
str2 = input()

A = str1.split(" ")
B = str2

res = 0
#print(A[1])
if A[1] == "0":
    res = A[0]
else:
#    print("A[1]!=0")
    B = B.split(" ")
    intB = []
    for i in B:
        intB.append(int(i))
    intB.sort(reverse=True)

    X = int(A[0])
    N = int(A[1])

    res = 0
    diff = 999999

    # 1~100の配列を作る
    l = list(range(1, 102))

    # 入力内容を削る
    for i in range(0, N):
        l.pop(intB[i]-1)

 #   print(l)
    for i in l:
        if 0 == abs(X - int(i)):
            diff = 0
            res = i
            break
        elif diff > abs(X - int(i)):
            diff = abs(X - int(i))
            res = i
#            print(diff, res)


print(res)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
list_p = [i for i in range(1, 101)] 
t = x
num = x

for i in p:
  list_p[i - 1] = -1

for i in range(len(list_p)):
  if(list_p[i] == -1):
    continue
  else:
    if(abs(list_p[i] - x) < t):
      t = abs(list_p[i] - x)
      num = list_p[i]

print(num)

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()
list = []
list2 = []
for i in range(max(P)):
  if i not in P:
    res = abs(X - i)
    list.append(res)
    list2.append(i)
    
maxres = list.index(min(list))
print(list2[maxres])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

input_list1 = input().split()
input_list1_int = [int(x) for x in input_list1]

try:
    input_list2 = input().split()
    input_list2_int = [int(x) for x in input_list2]

    num_min = min(input_list2_int)
    num_max = max(input_list2_int)
    
    if num_min == num_max:
        if num_min == input_list1_int[0]:
            answer = input_list1_int[0] -1
        else:
            answer = input_list1_int[0]
        
    else:
        if num_min > input_list1_int[0]:
            answer = input_list1_int[0]
        
        elif num_max < input_list1_int[0]:
            answer = input_list1_int[0]
        
        else:
            number_list = list(range(num_min,num_max+1))
            pre_abs = 10000000
        
        
            for i in input_list2_int:
                number_list.remove(i)
    
            if input_list1_int[0] in number_list:
                answer = input_list1_int[0]
    
            else:
                for j in number_list:
                    temp1 = abs(j - input_list1_int[0])
                    if temp1 < pre_abs:
                        pre_abs = temp1
                        answer = j
            
                    else:
                        break
    print(answer)

except:
    print(input_list1_int[0])

Submission status: Wrong Answer

Solution code:
import math 
X, N = map(int,input().split())
d = int(999)
d1 = int()
ans = int(999)
if 1 < N:
    P = list(map(int,input().split()))
    for i in range(max(P),1,-1):
        if P.count(i) == 0:
            d1 = abs(X-i)
            if d1 < d and 0 <= d1:
                d = d1
                ans = i
    print(ans)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
q = set(range(0,102))
q = q - set(p)
q_list = list(q)
ans = 100
d = 100
print(q_list)
for i in range(102-n):
   if d != min(d,abs(x - q_list[i])):
       ans = q_list[i]
       d = abs(x - q_list[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)
  exit(0)

ans=float('inf')
tmpX=X
while X <= 100:
  if X not in P:
    ans = X
    break
  X = X+1

while tmpX >= 1:
  if tmpX not in P:
    ans = min(tmpX, ans)
    break
  tmpX = tmpX-1
print(ans)

Submission status: Wrong Answer

Solution code:
XN = input().split()
X = int(XN[0])
N = int(XN[1])
if N == 0:
    print(X)
else:
    p = input().split()
    A = [None]*N
    for i in range(N):
        A[i] = abs(int(p[i])-X)
    j = 0
    while j in A:
        j += 1
    if j == 1:
        print(X-j)
    else:
        if A.count(j-1) == 2:
            print(X-j)
        else:
            if str(X-(j-1)) in p:
                print(X+(j-1))
            else:
                print(X-(j-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = map(int, input().split())
p = list(map(int, input().split()))
cnt1 = []
cnt2 = []
for i in range(-100,101):
  if not i in p:
    cnt1.append(i)
    cnt2.append(abs(X-i))
cnt2_ = np.array(cnt2)
b = np.argmin(cnt2)
print(cnt1[b])

Submission status: Wrong Answer

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

    target_abs = [0]*100

    for i in range(n):
        if abs(p[i]-x) >= 100:
            continue
        elif p[i]-x > 0:
            target_abs[abs(p[i]-x)] += 2
        else:
            target_abs[abs(p[i]-x)] += 1

    ans = 0
    for i in range(100):
        if i == 0:
            if target_abs[i] == 0:
                ans = x
        elif ans == 0:
            if target_abs[i] == 0:
                ans = x - i
            elif target_abs[i] == 1:
                ans = x + i
            elif target_abs[i] == 2:
                ans = x - i
    print(ans)

Submission status: Wrong Answer

Solution code:
def readInt():
    return list(map(int,input().split()))
    
x,n = readInt()
a = []
if 0<n<100:
    p = readInt()
    p_r = [int(i) for i in range(1,101) if i not in p]
    # print(p_r)
    for i in p_r:
        dif = abs(x-i)
        a.append(dif)
    # print(a)
    print(p_r[a.index(min(a))])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
x,n=map(int,input().split())
if n!=0:
    l=list(map(int,input().split()))
    v=collections.Counter(l)
if n==0:
    print(x)
else:
    for i in  range(101):
        if x not in v:
            ans=x
            break
            
        if x+i not in v:
            ans=x+i
            break
        if x-i not in v:
            ans=x-i
            break
    print(ans)

Submission status: Wrong Answer

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

# 0~100
data_list = [i for i in range(V_RANGE)]
# 取得リスト
get_list = list(map(int, input().split()))

# (data_list-in_value)のリストを作る
sub_list = set(data_list) - set(get_list)

# 絶対値が最小のものを取得
g_abs = 10**4
abs_value = 0
for i in sub_list:
	t_abs = abs(X - i)

	if(g_abs > t_abs):
		g_abs = t_abs
		abs_value = i

print(abs_value)

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
P = list(map(int, input().split()))
sortP = sorted(P)
if N==0:
    print(X)
elif sortP[0]>X:
    print(sortP[0]-1)
elif sortP[N-1]<X:
    print(sortP[N-1]+1)
else:
    for n in range(sortP[0]-2,sortP[N-1]+2):
        if n in sortP:
            continue
        if n ==X:
            print(X)
        elif n>X:
            if X-a<=n-X:
                print(a)
                break
            else:
                print(n)
                break
        a = n

Submission status: Wrong Answer

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

def search(l, x, i=1):
    min_, max_ = x-i, x+i
    if not min_ in l and not max_ in l:
        return min_
    if not min_ in l:
        return min_
    if not max_ in l:
        return max_
    return search(l, x, i+1)

print(search(lst, x))

Submission status: Wrong Answer

Solution code:
status = list(map(int, input().split()))
aru = list(map(int, input().split()))

if status[1] == 0:
    print(status[0])
else:
    sort_aru = sorted(aru)

    num = status[0]
    total = sort_aru[-1]

    target_list = list()
    for i in range(total):
        for j in sort_aru:
            if i == j:
                break
            elif i < j:
                target_list.append(i)
                break
        else:
            target_list.append(i)

    result = target_list[0]
    zettai = (num - target_list[0]) * (num - target_list[0])
    for i in target_list:
        if zettai > (num - i) * (num - i):
            zettai = (num - i) * (num - i)
            result = i
            if zettai == 0:
                break

    print(result)

Submission status: Wrong Answer

Solution code:
def main():
    X, N = map(int, input().split())
    P = sorted(list(map(int, input().split())))
    
    if P is None:
        print(X)
        return

main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
num, i = map(int, input().split())
if(i != 0):
  s = set(map(int, input().split()))
else:
  s = set()
m = set(range(101))
o = list(m-s)
o2 = list(map(lambda x: abs(x - num), o))
print(o2.index(min(o2)))

Submission status: Wrong Answer

Solution code:
import math

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

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

p.sort()

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

if X < minimum or maximum < X:
    print(X)
    exit()

answer = min(abs(X - minimum - 1), abs(X - maximum + 1))
# answer = 9999
for candidate in range(minimum, maximum):
    if candidate in p: continue

    diff_answer = abs(X - answer)
    diff_candidate = abs(X - candidate)
    # print(candidate, diff, answer)
    answer = candidate if diff_candidate < diff_answer else answer

print(answer)

Submission status: Wrong Answer

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

def main():
    if len(p) == 0:
        print(x)
        return

    ans_l = list(range(x-15, x+15))

    diff_l = list(set(p) ^ set(ans_l))
    diff_l.sort()

    cnt = 100
    ans = 100
    for i in range(0, len(diff_l)):
        check = abs(diff_l[i]-x)
        if check < cnt:
            cnt = check
            ans = diff_l[i]
    print(ans)
    return

main()

Submission status: Wrong Answer

Solution code:
def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    else:
        p = [int(i) for i in input().split()]

    s = []
    for i in range(101):
        if not i in p:
            s.append(i)
    if not x in p:
        print(x)
        return
    
    t = s + [x]
    t.sort()
    pos = t.index(x)
    try:
        if abs(x-t[pos-1]) <= abs(x-t[pos+1]):
            print(t[pos-1])
            return
        else:
            print(t[pos+1])
    except:
        print(t[-1])
        return

resolve()

Submission status: Wrong Answer

Solution code:
num = list(map(int,input().split()))
if num[1] ==0:
  print(num[0])
else:  
  num_list = list(map(int,input().split()))
  flg = True
  ans = num[0]
  distance = 1
  while flg:
    ch_1 = ans-distance
    ch_2 = ans+distance
    if ch_1 not in num_list:
      print(ch_1)
      flg = False
    elif ch_2 not in num_list:
      print(ch_2)
      flg = False
    else:
      distance +=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:
    a = x - 1
    b = x + 1
    if a not in p and b not in p:
        if a > b:
            print(b)
        else:
            print(a)
    elif a not in p and b in p:
        print(a)
    elif a in p and b not in p:
        print(b)
    else:
        while True:
            if a not in p:
                c = abs(a - x)
            else:
                c = 0
            if b not in p:
                d = abs(b -x)
            else:
                d = 0
            if c != 0 and d == 0:
                print(a)
                quit()
            elif c == 0 and d != 0:
                print(b)
                quit()
            elif c != 0 and d != 0:
                print(a)
                quit()
            else:
                a -= 1
                b += 1

Submission status: Wrong Answer

Solution code:
import sys
x = input().split()
y = input().split()

if len(y) == 0:
    print(x[0])
    sys.exit()
a=[]
b=[]
for n in range(-1,102):
    b.append(n)
   
for nn in range(len(y)):
    
    b.remove(int(y[nn]))
for m in range(len(b)):  
    d = b[m] - int(x[0])
    if d < 0:
        c = d*(-1)
    if d >= 0:
        c = d
    a.append(c)
mm = min(a)
if (int(x[0]) - mm) in y:
    print(int(x[0]) + mm)
else:
    print(int(x[0]) - mm)

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-

import sys

def main():
    numbers=[]
    x,n = map(int,input().split())
    numbers=list(map(int,input().split()))
    if n==0:
        print(x)
        sys.exit()
    dp_list=list(range(-100, 101))
    dp_list=set(dp_list)-set(numbers)

    for i in range(101):
        if x-i in dp_list:
            print(x-i)
            break
        elif x+i in dp_list:
            print(x+i)
            break

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

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

ans = 0

max_ = 0
min_ = 0

# 増える側
for i in range(x, 100, 1) :

    # print('i+')
    # print(i)

    if i not in p_list:
        # print('確定')
        max_ = i
        break

# 減る側
for j in reversed(range(x + 1)) :

    # print('j-')
    # print(j)

    if j not in p_list:
        # print('確定')
        min_ = j
        break

# print('min')
# print(min_)
# print('max')
# print(max_)

if min_ == 0 :
    ans = max_
else :   

    if abs (min_ - x) <= abs(max_ - x) :
        ans = min_
    else : 
        ans = max_

print(ans)

Submission status: Wrong Answer

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

def main():
    if len(p) == 0:
        print(x)
        return

    ans_l = list(range(x-10, x+10))

    diff_l = list(set(p) ^ set(ans_l))
    diff_l.sort()

    cnt = 100
    ans = 100
    for i in range(0, len(diff_l)):
        check = abs(diff_l[i]-x)
        if check < cnt:
            cnt = check
            ans = diff_l[i]
    print(ans)
    return

main()

Submission status: Wrong Answer

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

lis = [1] * (201)
for p in P: lis[p+99] -= 1

for i in range(100+1):
    up = X+i
    down = X-i
    if lis[100+down-1] == 1 and down >= 0 :
        print(down)
        exit()
    elif lis[100+up-1] == 1 and up <= 100:
        print(up)
        exit()

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
nlist=list(map(int,input().split()))
Nlist=[]
if n==0:
    print(x)
    exit(0)
elif x not in nlist:
    print(x)
    exit(0)

delta=200
ans=-x
for i in range(-x,100):
    if i not in nlist:
        X=abs(x-i)
        if X<delta:
            ans=i
            delta=X
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = list(map(int, input().split()))
if N > 0:
    P = list(map(int, input().split()))
    L = X - 1
    H = X + 1
    while True:
        if L not in P and L >= 0:
            print(L)
            break
        if H not in P:
            print(H)
            break
        L -= 1
        H += 1
else:
    input()
    print(X)

Submission status: Wrong Answer

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

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

abs_n = 0
ans = 0

if n == 0:
    print(x)
else:
    #r = max(p)
    #l = min(p)

    for i in range(-100,201):
    
        # 配列に含まれていると
        if i in p:
            continue
            
        tmp = abs(x-i)
        #print(i, tmp)

        if i == 1:
            abs_n = tmp
            ans = i
        
        if tmp < abs_n:
            abs_n = tmp
            ans = i
        
    print(ans)

Submission status: Wrong Answer

Solution code:
def do():
    n,m=map(int,input().split())
    l=list(map(int,input().split()))
    k1 = 0
    k2 = 0
    v1 =0
    v2=0
    if m==0:
        return n
    for i in range(n,0,-1):
        k2+=1
        if i not in l:
            k1=i
            break

    for j in range(n,100+1):
        v2+=1
        if j not in l:
            v1=j
            break
    if k2>v2:
        return v1
    elif k2==v2:
        return min(v1,k1)
    else:
        return k1



print(do())

Submission status: Wrong Answer

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

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

P = input().split()
for i in range(len(P)):
    P[i] = int(P[i])

if X not in P:
    print(X)

flag_p = True
flag_n = True

abs_num = 0
abs_num_p = X + 1
abs_num_n = X - 1
while True:

    if abs_num_p in P:
        flag_p = True
    else:
        flag_p = False

    if abs_num_n in P:
        flag_n = True
    else:
        flag_n = False

    if(flag_n == True & flag_p == True):
        abs_num_p += 1
        abs_num_n -= 1
        continue;
    elif(flag_n == True & flag_p == False):
        print(abs_num_p)
        break;
    elif(flag_n == False):
        print(abs_num_n)
        break;

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

def Forbidden_List():
    X ,N = map(int, input().split())
    
    if N == 0:
        return X
    
    p = list(map(int, input().split()))
        
    if min(p)-1 <= X and X <= max(p)+1:
        other_integer = [i for i in range(min(p)-1, max(p)+2)]
    else:
        return X

    other_integer = set(other_integer) - set(p)

    min_abs = sys.maxsize
    for i in other_integer:
        next_min = abs(i - X)
        #print(next_min, min_abs)
        if next_min < min_abs:
            min_num = i
            min_abs = next_min
        else:
            break
    return min_num

print(Forbidden_List())

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
counter = 1
find = 0
while True:
  ceil = counter / 2 if counter % 2 == 0 else (counter // 2 + 1)
  find = int(ceil * ((-1) ** counter))
  if (x + find) not in p:
    find = x + find
    break
  counter += 1
print(x if n == 0 else find)

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 A[0] != 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):
            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,t)
            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:
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    l = [k for k in range(-100,101)]
    for p in input().split():
        p = int(p)
        l[p+100] = 1000
    l_d = [x-k for k in l]
    l_sorted = sorted(l_d,key= lambda x: (-x+0.1, x)[x > 0])
    print(x-l_sorted[0])