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

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

    chk_x = False
    pmax = 0
    pmin = 101
    for pr in p:
        if pmax < pr:
            pmax = pr
        if pmin > pr:
            pmin = pr
        if pr == x:
            chk_x = True

    all_i = list(range(0,101))
    target_i = list(set(all_i)^set(p))

    minsub = abs(target_i[0] - x)
    ans = -1
    for i in target_i:
        if abs(i-x) < minsub:
            minsub = abs(i-x)
            ans = i
    # Xがこの範囲にないが最小だった場合
    if not chk_x:
        print(x)
    else:
        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):
#    p.append(input().split())
#print(p)
#rint(type(p[0]))
min = 1e9
ans = 0
for i in range(100):
    i = i + 1
    if i in p:
        continue
    sa = abs(x - i)
    #print(sa)
    if min > sa :
        min = sa
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
list_n = [0, -1, 1]
for i in range(2, 50):
  list_n.append(-i)
  list_n.append(i)
X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))
x = [0] * N
for i in range(0, N):
    x[i] = p[i] - X
for i in list_n:
    if my_index(x, i) == False:
        print(X+i)
        break

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input(). split())
l = [0]*n
m = [0]*101
p = list()
if n > 0:
  p = list(map(int, input(). split()))
else:
  print(x)
  sys.exit()
for i in range(n):
  l[i] = abs(x-p[i])
  m[l[i]] += 1
if m[0] == 0:
  print(x)
for j in range(1, 101):
  if m[j] != 2:
    a = x-j
    A = x+j
    b = p.count(a)
    B = p.count(b)
    if b == 0:
      print(a)
    else:
      print(A)
    break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
p = list(map(int, input().split()))
unique = set(range(-100, 101)) - set(p)
ans = {}
ans2 = []
for i in unique:
  calc = abs(x-i)
  ans[calc] = i
  ans2.append(calc)
print(ans[min(ans2)])

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n is 0:
    print(x)   
else:
    # l=list(sorted(map(int,input().split())))
    l=list(map(int,input().split()))
    if x not in l:
        print(x)
    else:
        for i in range(1,len(l)):
            if x-i not in l:
                print(x-i)
                break
            elif x+i not in l:
                print(x+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)
    
else:
    for i in range(110):
        if (X-(i+1)) and (X+i+1) in p:
            continue
    
        else:
            if(X-i-1) not in p:
                print(X-i-1)
                break
    
            elif (X+i+1) not in p:
                print(X+i+1)
                break

Submission status: Wrong Answer

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

if N==0:
    print(X)
for i in range(101):
    ans = int(X)-i
    if str(ans) not in P:
        print(ans)
        break
    ans2 = int(X)+i
    if str(ans2) not in P:
        print(ans2)
        break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
len=float("inf")
memo=list(range(-100,101))
ans=[[float("inf")] for i in range(10000)]
for i in p:
    memo.remove(i)
for i in memo:
    if abs(x-i)<=len:
        len=abs(x-i)
        ans[len].append(i)
ans[len].sort()
print(ans[len][0])

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

answer = min(abs(X - minimum - 1), abs(X - maximum + 1))
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:
#C
X, N = list(map(int, input().split()))
p = set(map(int, input().split()))

result = X
if p:
    if X not in p:
        result = X
    else:
        for i in range(1, len(p)):
            if X + i not in p:
                result = X + i
                break
            elif X - i not in p:
                result = X - i
                break
    print(result)
else:
    print(X)

Submission status: Wrong Answer

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

  n = [x for x in range(101)]

  for i in p:
    n.remove(i)
  ans = 0  
  a = 101
  b = -1
  for j in n:
    b += 1
    
    if abs(j-X) < a:
      a=abs(j-X)
      ans = n[b]
  
  print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
L=list(map(int,input().split()))
L.append(X)
if L.count(X)==1:
  print(X)
else:
  set(L)
  for i in range(1,N):
    if X-i not in L:
      print(X-i)
      break
    elif X+i not in L:
      print(X+i)
      break

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(X: int, N: int, p: "List[int]"):
    ii = [i for i in range(-101,101)]
    iii = sorted(list(set(ii) - set(p)))
    idx = np.abs(np.asarray(iii) - X).argmin()
    if idx>0:
        if iii[idx]-X > X-iii[idx-1]:
            print(iii[idx-1])
        else:
            print(iii[idx])
    else:
        print(iii[idx])
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
xp=[]
xm=[]
if n==0:
    print(x)
else:
    for i in range(0,1000):
        xp.append(x+i)
        xm.append(x-i)
        if len(set(p)-set(xm))==5:
            print(x-i)
            exit()
        elif len(set(p)-set(xp))==5:
            print(x+i)
            exit()
        else:
            xp.pop(0)
            xm.pop(0)

Submission status: Wrong Answer

Solution code:
x, n = map(int,input().split())
ps = list(map(int,input().split()))
mtmp = x
ptmp = x
rt = True
r = []
if len(ps) == 0:
  print(x)
else:
  while True:
    if mtmp+1 not in ps:
      r.append(mtmp+1)
      rt = False
    if ptmp-1 not in ps:
      r.append(mtmp-1)
      rt = False
    mtmp = mtmp+1
    ptmp = ptmp-1
    if rt:
      continue
    else:
      break
  print(min(r))

Submission status: Wrong Answer

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

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

    chk_x = False
    pmax = 0
    pmin = 101
    for pr in p:
        if pmax < pr:
            pmax = pr
        if pmin > pr:
            pmin = pr
        if pr == x:
            chk_x = True

    all_i = range(pmin-1, pmax+2)
    target_i = list(set(all_i)^set(p))

    minsub = abs(target_i[0] - x)
    ans = -1
    for i in target_i:
        if abs(i-x) < minsub:
            minsub = abs(i-x)
            ans = i
    # Xがこの範囲にないが最小だった場合
    if not chk_x:
        print(x)
    else:
        print (ans)

Submission status: Wrong Answer

Solution code:
x,n = list(map(int,input().split()))
if n >0 :
  p = list(map(int,input().split()))
#print(x,n)
#print(p)
#print(max(p))
y = 100
ans = x
if n == 0:
  print(x)
else:
  for i in range(0,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(ans)

Submission status: Wrong Answer

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

nun_list = list(map(int, input().split()))
answer = 0

for i in range(0, 100):
    if nun_list.__contains__(i):
        continue
    else :
        if abs(x - answer) >= abs(x - i):
            if abs(x - answer) == abs(x - i):
                if answer > i:
                    answer = i
            else:
                answer = i
print(answer)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
l = list(range(1, 100))
ll = []
if n ==0:
    print(x)
else:
    for j in range(50):
        if x-j in l:
            if not x-j in p:
                ll.append(x-j)
        if len(ll) != 0:
            print(min(ll))
            break
        if x+j in l:
            if not x+j in p:
                ll.append(x+j)
            if len(ll) != 0:
                print(min(ll))
                break

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 len(p) == 0 else find)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split(' '))
found = False
goal = 0
challenge_plus = X
challenge_minus = X
# そもそもNが0ならXが正解
# Xを基準に大きい方向、小さい方向の両方向へ1づつ数値をずらしていき、
# p_listにヒットしない整数が合ったときに正解となる。
# 同時に大小ヒットした場合は小さいほうが正解

if(N == 0):
  found = True
  goal = X
else:
  p_list = list(map(int, input().split(' ')))
  max_p = max(p_list)
  min_p = min(p_list)
  #print(X,N)
  #print(p_list)
  #print(max_p, min_p)

  for i in range(101):
    tmp_break = False
    challenge_plus += 1
    challenge_minus -= 1
    #print("比較対象は{0}, {1}".format(challenge_plus, challenge_minus))
    if not (challenge_plus in p_list):
      goal = challenge_plus
      found = True
      tmp_break = True
      
    if not(challenge_minus in p_list):
      goal = challenge_minus
      found = True
      break
      
    if(tmp_break):
      break

if(found):
  print(goal)
else:
  abs_plus = abs(challenge_plus + 1 - X)
  abs_minus = abs(challenge_minus - 1 - X)
  print(min((abs_plus, abs_minus)))

Submission status: Wrong Answer

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

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

p.sort()

minp = abs(-1 - x)
minv = -1
if n == 100:
    if abs(-1 - x) <= abs(101 - x):
        print(-1)
    else:
        print(101)
else:
    for i in range(1, 101):
        if i in p:
            continue
        else:
            if abs(i - x) < minp:
                minp = abs(i - x)
                minv = i
            else:
                break
    print(minv)

Submission status: Wrong Answer

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


def num(x, p_list):
    if n == 0:
        return x
        
    p_num = x + 1
    m_num = x - 1
    p_list_max = max(p_list)
    p_list_min = min(p_list)

    while p_num <= p_list_max:
        if p_num not in p_list:
            break
        else:
            p_num += 1

    while m_num >= p_list_min:
        if m_num not in p_list:
            break
        else:
            m_num -= 1
    
    if abs(p_num - x) == abs(x - m_num):
        return min(p_num, m_num)
    elif abs(p_num - x) > abs(x - m_num):
        return m_num
    else:
        return p_num

print(num(x, p_list))

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 1000
l = []
if n == 0:
  print(x)
elif x not in p:
  print(x)
else:
  for i in range(-100,100):
    if (abs(i - x) < abs(ans - x)) and (i not in p):
      ans = i
  print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
x, n = map(int, stdin.readline().rstrip().split())
if n ==0:
    print(x)
else:
    data = list(map(int, stdin.readline().rstrip().split()))

    data_sorted = sorted(data)

    abs_min = 100000000
    res = data_sorted[0]-1
    for i in range(data_sorted[0]-1, data_sorted[-1]+1):
        if (i in data_sorted) == False and abs_min > abs(i-x):
            abs_min = abs(i-x)
            res = i
    print(res)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N>0:
  p=list(map(int,input().split()))
  d=abs(X-p[0])
if N>0:
  for i in range(N):
    d=min(abs(X-p[i]),d)
  print(p[i])
else:
  print(X)

Submission status: Wrong Answer

Solution code:
x,n= map(int,input().split())
u = 100
num_str=input().split()
s=list(map(int, num_str))
m = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100}
for k in s:
    m.remove(k)
for l in m:
    if u >= abs(l - x):
        u = abs(l - x)
print(u)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
q = set(range(-2,101))
q = q - set(p)
q_list = list(q)
ans = 1000
d = 1000
for i in range(100-n):
   if d != min(d,abs(x - q_list[i])):
       ans = q_list[i]
       d = min(d,abs(x - q_list[i]))
print(ans)

Submission status: Wrong Answer

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

if n>=1:
    p=list(map(int,input().split()))
else:
    print(x)
    sys.exit()
s=[]
d={}
l={}
for i in range(-101,101):
    if i not in p:
        s.append(i)


for k in s:

    d[k]=abs(x-k)


l=[m[0] for m in d.items() if m[1]==min(d.values())]
print(min(l))

Submission status: Wrong Answer

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

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

  min_abs = 101
  min_e = 0
  for i in p:
    if abs(x-i) < min_abs:
      min_abs = abs(x-i)
      min_e = i

  if min_abs != 0 and min_e not in p:
      print(min_e)
      return

  for i in range(1, 100):
    if min_e - i not in p and x != min_e-i:
      print(min_e - i)
      return
    if min_e + i not in p and x != min_e+i:
      print(min_e + i)
      return
    
main()

Submission status: Wrong Answer

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

i=0

while i<10:
    
    jud=1
    con=x-i
    
    for j in range(n):

        if con==p[j]:
            jud=0
            break

    if jud==1:
        print(con)
        break

    jud=1
    con=x+i

    for k in range(n):

        if con==p[k]:
            jud=0
            break

    if jud==1:
        print(con)
        break

    i+=1

Submission status: Wrong Answer

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

if n==0:
    print(x)

for i in range(n):
    if x-i not in p:
        print(x-i)
        exit()
    if x+i not in p:
        print(x+i)
        exit()
print(x-n)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split(" "))
if N == 0:
  print(X)
  exit()
else:
  p = list(map(int, input().split(" ")))
  c = 0
  for i in range(100):
    if i+1 not in p:
      if abs(X-(i+1)) < abs(X-c):
        c = i+1
  print(c)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().strip().split())
list = []
list1 = []
if n==0:
    print(x)
else:
    dic = {}
    a = input().split()
    for i in range(0, len(a)):
        list.append(int(a[i]))
    for i in range(0, 101):
        b = abs(i - x)
        dic[i] = b
    min1 = min(dic, key=dic.get)
    i = 0
    for i in range(0, 101):
        if (list.__contains__(min1)):
            del dic[min1]
            min1 = min(dic, key=dic.get)
    print(min1)

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()))
absp = []
for i in p:
  absp.append(i-X)
for check in range(1,101):
  if not check*(-1) in absp:
    print(X-check)
    exit()
  if not check in absp:
    print(X+check)
    exit()

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
q = set(range(-2,101))
q = q - set(p)
q_list = list(q)
ans = 1000
d = 1000
print(q_list)
for i in range(100-n):
   if d != min(d,abs(x - q_list[i])):
       ans = q_list[i]
       d = min(d,abs(x - q_list[i]))
       print(ans,d)
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n > 0:
    P = list(map(int, input().split()))
    Q = sorted(
        [[i, abs(i - x)] for i in range(-100, 101) if i not in P],
        key=lambda x:x[0])
    Q.sort(key=lambda x:x[1])
    print(Q[0][0])
else:
    print(x)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
if not a[1] ==0:
  b = list(map(int,input().split()))
  b2 = sorted(b)##小さい順に並べる
  if a[0] < b2[0]:
    print(a[0])
  elif a[0] > b2[a[1]-1]:
    print(a[0])
  else:
    c = abs(b2[0]-1-a[0])
    for i in range(a[1]-1):
      if abs(b2[i+1]-b[i])>1:
        for j in range(b2[i+1]-b2[i]-1):##差分が1より大きい場合ソート
          if abs(c) > abs(b2[i]-a[0]+j+1):
            c = b2[i]-a[0]+j+1
    print(c+a[0])
else:
  print(a[0])

Submission status: Wrong Answer

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

    p.sort()
    y = 0

    for i in range(n):
        if p[i] <= x:
            y = i
            if i != n-1 and x < p[i+1]:
                break 

    i = 0
    while 1 == 1:
        if y - i < 0:
            print(0)
            break
        elif x - i != p[y - i]:
            print(x - i)
            break
        if n <= y + i:
            print(p[n - 1] + 1)
            break
        elif x + i != p[y + i]:
            print(x + i)
            break
        i = i + 1

Submission status: Wrong Answer

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

tmp = [i for i in range(-100, 101)]
for i in p:
  tmp.remove(i)
for i in range(len(tmp)):
  tmp[i] = abs(tmp[i] - X)

ans = 0
for i in p:
  if X-min(tmp)==i:
    ans = 1

if ans==0:
  print(X-min(tmp))
else:
  print(X+min(tmp))

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

lis = []
for i in range (-100,101,1):
    if i not in P:
        lis.append(i)


        
        
        
ans = 10**18
suzi = 0
for j in lis:
    num = abs(X-j)
    if num < ans:
        ans = num
        suzi = j

print(suzi)

Submission status: Wrong Answer

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

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


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


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

    if x >= 0:
        ans1 = x - x1
        ans2 = x2 - x
        if ans1 <= ans2:
            print(x1)
        else:
            print(x2)
    else:
        ans1 = (x1 - x) * (-1)
        ans2 = (x - x2) * (-1)
        if ans1 <= ans2:
            print(x1)
        else:
            print(x2)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    quit()
p=list(map(int,input().split()))
if x not in p:
    print(x)
    quit()
p.sort()
ans=[]
#本題
for i in range(p[0],p[-1]+1):
    if i not in p:
        ans.append(i)
ans.append(100000000)
for i in range(len(ans)):
    if ans[i]>x:
        if abs(x-ans[max(i-1,0)]) <= abs(x-ans[i]):
            print(ans[max(i-1,0)])
        else:
            print(ans[i])
        quit()

Submission status: Wrong Answer

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

for j in range(n):
    q.remove(p[j])
min=1000
for k in range(0,101-n):
    a=x-q[k]
    if min>=abs(a):
        min=abs(a)

print(abs(min-x))

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input(). split())
l = [0]*n
m = [0]*100
p = list()
if n > 0:
  p = list(map(int, input(). split()))
else:
  print(x)
  sys.exit()
for i in range(n):
  l[i] = abs(x-p[i])
  m[l[i]] += 1
if m[0] == 0:
  print(x)
for j in range(1, 100):
  if m[j] != 2:
    a = x-j
    A = x+j
    b = p.count(a)
    B = p.count(b)
    if b == 0:
      print(a)
    else:
      print(A)
    break

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

for i in range(N // 2):
  if not(X - i in P):
    Ans = X - i
    break
  elif not (X + i in P):
    Ans = X + i
    break

print(Ans)

Submission status: Wrong Answer

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

if Y == 0:
    print(X)
if Y != 0:
    p = map(int, input().split())
    for i in range(1, 100):
        if X-i >= 1:
            if abs(X-i) not in p:
                print(X-i)
                break
        if X+i <= 100:
            if abs(X+i) not in p:
                print(X+i)
                break

Submission status: Wrong Answer

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


mini=101
for i in range(N):
    if abs(p[i]-X) <= mini:
    	mini= p[i]

minimini=101
answer=0
for a in A:
    if abs(a-mini)<minimini:
        minimini=a-minimini
        answer=min(a,answer)

print(a)

Submission status: Wrong Answer

Solution code:
x, n = [int(s) for s in input().split(" ")]
if n == 0:
  print(x)
else:
  plist = [int(s) for s in input().split(" ")]

  dlist = {}
  for p in plist:
    d = abs(p - x)
    if d in dlist or d == 0:
      dlist[d] = (True, None)
    else:
      dlist[d] = (False, p - x)

  sorted_d = sorted(dlist.items(), key=lambda x:x[0])

  ans = 0
  prevk = 0
  flag = False
  for k, v in sorted_d:
    if not flag and prevk == 0 and k >= 1:
      ans = 0
      break
    elif v[0] and k - prevk > 1:
      ans = -(prevk + 1)
      break
    elif not v[0]:
      ans = -v[1]
      break
    flag = True
    prevk = k
    ans = -(k + 1)
  print(x + ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N > 0:
    l = list(map(int, input().split()))
    A = [0] * N
    for i in range(N):
        A[i] = abs(l[i] - X)
        S = A.count(0)
        if S == 0:
            print(X)
        else:
            for i in range(1, N):
                S = A.count(N)
                if S == 1:
                    if l.count(X + 1) == 1 or l.count(X - 1) == 0:
                        print(X - 1)
                        break
                    else:
                        print(X + 1)
                        break
                else:
                    pass
else:
    print(X)

Submission status: Wrong Answer

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

min_abs = min([abs(X-i) for i in range(0, 100+1) if not i in P])

delta, notP = [], []
for i in range(0, 101):
    if not i in P:
        delta.append(abs(X-i))
        notP.append(i)

i = delta.index(min(delta))
print(notP[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(X: int, N: int, p: "List[int]"):
    ii = [i for i in range(-101,101)]
    iii = sorted(list(set(ii) - set(p)))
    idx = np.abs(np.asarray(iii) - X).argmin()
    #print(iii)
    if idx>0:
        if iii[idx]-X >= X-iii[idx-1]:
            print(iii[idx-1])
        else:
            print(iii[idx])
    else:
        print(iii[idx])
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

p_list = sorted(p_list)
all_range = list(range(101))
A = [i for i in all_range if i not in p_list]
B = [abs(i - X) for i in A]

low = X - min(B)
high = X + min(B)

if N == 0:
  print(X)
elif high in p_list:
  print(low)
elif low in p_list:
  print(high)
else:
  print(low)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n > 0:
    P = list(map(int, input().split()))
    Q = sorted(
        [[i, abs(i - x)] for i in range(101) if i not in P],
        key=lambda x:x[0])
    Q.sort(key=lambda x:x[1])
    print(Q[0][0])
else:
    print(x)

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)
        elif x-qn[i] > qn[i+1]-x:
            print(qn[i+1])
            exit(0)

Submission status: Wrong Answer

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

p.sort()
#print(p)
index = 0
for i in range(n):
    if p[i] == x:
        index = i

prev = x - 1
right = 1000
left = 1000

for i in p[index:]:
    #print(i)
    if i != prev + 1:
        right = prev + 1
        #print('aaaaa')
        #print(right)
        break
    prev = i

prev = x + 1
for i in reversed(p[: index + 1]):
    if i != prev - 1:
        left = prev - 1
        #print('bbbbb')
        #print(left)
        break
    prev = i

if n != 0:
    if index == n - 1:
        right = p[index] + 1
    elif index == 0:
        left = p[index] - 1

if n == 0:
    print(x)
else:
    print(min(left, right))

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
num = list(map(int, input().split()))
back, forward, val1, val2 = 0, 0, 0, 0

if len(num) == 0 or X not in num:
    print(X)
else:
    for i in range(X, 0, -1):
        if i not in num:
            val1 = i
            back = abs(i - X)
            break

    for j in range(X, 101):
        if j not in num:
            val2 = j
            forward = abs(j - X)
            break

    if back <= forward:
        print(val1)
    else:
        print(val2)

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,500):
  if i not in p:
    ans=min(ans,abs(x-i))
    
    
if x-ans not in p :
  print(x-ans)
  
else:
  print(x+ans)

Submission status: Wrong Answer

Solution code:
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)

    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:
x,n=map(int,input().split())

p=list(map(int,input().split()))
q=[_ for _ in range(1,101)]

for i in range(len(q)):
    if q[i] in p:
        q[i]=0

for j in range(len(q)):
    q[j]=abs(q[j]-x)

ans=min(q)
for k in range(len(q)):
    if q[k]==ans:
        print(k+1)
        exit()

Submission status: Wrong Answer

Solution code:
X,N=map(int, input().split())
if(N==0):
  print(X)
  exit()
if(X==100 and N==100):
  exit()
P=list(map(int, input().split()))
P.sort()
mi=1000
cotae=1000
for i in range(1,101):
  if(i in P):
    continue
  if(abs(X-i)<mi):
    mi=abs(X-i)
    cotae=i
print(cotae)