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()))
p = list(map(int, input().split())) 
import numpy as np

if x not in p:
    print(x)
else:
    t = [i for i in range(1,101)]
    for i in range(n):    
        t.remove(p[i])
#         print(t)

    res = 100
    s = 1000
    for i in range(len(t)):
#         print(t[i])
        if s >= abs (x - t[len(t)-1-i]):
            s = abs (x - t[len(t)-1-i])
            res = t[len(t)-1-i]
    print(res)

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
  print(x + ans)

Submission status: Wrong Answer

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

pset = set([abs(X-p) for p in ps])

for i in range(50):
  if i in pset:
    print(X-i)

Submission status: Wrong Answer

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

if x not in v:
    print(x)
    exit()

# for i in range(1,103):
#     if ((x - i) >= 0) and ((x - i) <= 100) and (x - i) not in v:
#         print(x-i)
#         exit()
#     elif ((x + i) >= 0) and ((x + i) <= 100) and (x + i) not in v:
#         print(x+i)
#         exit()

nmin = -1000
nmax = 1000

list = []
for i in range(1,101):
    if i not in v:
        list.append(i)

for i in range(1,101):
    if (x - i) in list:
        nmin = x - i
        break

for i in range(1,101):
    if (x + i) in list:
        nmax = x + i
        break

if nmin >= 0 and nmax <= 100:
    mians = abs(x-nmin)
else:
    print(nmax)
    exit()
if nmax >= 0 and nmax <= 100:
    maans = abs(nmax-x)
else:
    print(nmin)
    exit()

if (mians <= maans):
    print(nmin)
else:
    print(nmax)

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,100):
  if(i in P):
    continue
  if(abs(X-i)<mi):
    mi=abs(X-i)
    cotae=i
print(cotae)

Submission status: Wrong Answer

Solution code:
def linked_merge_sort(l): #マージソート
    if len(l) == 1:
        return
    q, r = divmod(len(l), 2)
    left = [l.pop() for _ in range(q)]
    right = [l.pop() for _ in range(q + r)]
    
    linked_merge_sort(left)
    linked_merge_sort(right)
    
    left.reverse()
    right.reverse()
    while left and right:
        if left[-1] <= right[-1]:
            l.append(left.pop())
        else:
            l.append(right.pop())
    while left:
        l.append(left.pop())
    while right:
        l.append(right.pop())
    return

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans=0
min_ans=200
t=0

if n==0:
    print(x)
    exit
elif n==100:
    print(0)
else:
    p= list(map(int,input().split()))
    for i in range(101):
        if p.count(i)==0:
            ans=abs(x-i)
            if ans<min_ans:
                min_ans=ans
                t=i

    print(t)

Submission status: Wrong Answer

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

q = set(range(min(p),max(p)+1,1))
r = q - p - set([X])
diff = 100
ans = 0
for i in r:
    if diff > abs(X-i):
        diff = abs(X-i)
        ans = i
print(ans)

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
    ans1 = x - x1
    ans2 = x2 - x

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

Submission status: Wrong Answer

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

i = 0
while True:

    a = (x + i) in p
    b = (x - i) in p

    if a == False:
        if b == False:
            print(x - i)
            break
        else:
            print(x + i)
            break

    i += 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()))
  con=0
  anco=0
  
  for _ in range(1, 100):
    for i in range(n):
      if x-_==p[i]:
        con=1
      elif x+_==p[i]:
        anco=1
    if con==0:
        print(x-_)
        break
    elif anco==0:
      print(x+_)
      break
    con=0
    anco=0

Submission status: Wrong Answer

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

if n!=0:
    a=list(map(int,input().split()))
    a.sort
    x_p=x
    x_n=x
    
    while True:
        x_n-=1
        x_p+=1
        if all(elem != x_p for elem in a) and all(elem != x_n for elem in a):
            print(x_n)
            break;
        elif all(elem != x_p for elem in a):
            print(x_p)
            break;
        elif all(elem != x_n for elem in a):
            print(x_n)
            break;
            
else:
  print(x)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
num1 = []
num1 = input().split(" ")
ans=int(num1[0])
count=int(num1[1])

if count != 0:
    num2 = []
    num2 = input().split(" ")
#print(num2)

    num3 = []
    for i in range(count):
        num3.append(int(num2[i]))
    num3.sort()
#print(num3)
#print(ans)
    up=1
    down=1
    for i in range(count//2+2):
        if up == 1 and down == 1:
            num_up=ans+i
            num_down=ans-i
            up=0
            down=0
        elif up ==1:
            print(num_down)
            break
        elif down == 1:
            print(num_up)
            break
        else:
            print(num_down)
            break
        
        for k in range(count):
            if num_up == num3[k]:
                up=1
            #print("up")
            if num_down == num3[k]:
                down=1
                #print("down")
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
p = readints()
tmp = list(range(-100, 101))
# print(tmp)
for i in range(n):
    tmp.remove(p[i])
#print('tmp', tmp)
ans = [None]*200

for i in range(len(tmp)):
    ans[tmp[i]] = abs(tmp[i]-x)
# print(ans)
x = 10**5
for i in range(len(ans)):
    if ans[i] != None:
        x = min(x, ans[i])
# print(x)
print(ans.index(x))

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

    other_integer = [i for i in range(min(p)-1, max(p)+2)]

    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:
def forbidden(x,p):
    res = []
    for num in range(101):
        if num not in p:
            if x!=num:
                res.append(abs(x-num))
    if x-min(res) not in p:
        return x-min(res)
    return x+min(res)

if __name__ == "__main__":
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    if n==0:
        print(x-1)
        exit()
    print(forbidden(x,p))

Submission status: Wrong Answer

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

def judge(p_,x_):
    p_d = list(set(sorted(map(lambda y: np.abs(x_-y),p_))))
    if p_d == []:
        return x_
    for delta in range(p_d[-1]):
        if (x_-delta not in p_):
            return x_-delta
        if (x+delta not in p_):
            return x_+delta
    return x_

print(judge(p,x))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

t = [0] * (101)
t[0] = 1
for p in P:
    t[p] = 1

a = 1
for i in range(X, 101):
    if t[i] == 0:
        a = i
        break
b = 1
for i in range(X, 0, -1):
    if t[i] == 0:
        b = i
        break

if abs(X - a) < abs(X - b):
    print(a)
else:
    print(b)

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=p+[100000000]
p=list(map(lambda i:abs(x-i),p))

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

Submission status: Wrong Answer

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

ab = 100
num = []
for i in range(101):
    if p.count(i)>0:
        continue
    abst = abs(i-x)
    if abst < ab:
        ab = abst
        num = [i]
    elif abst == ab:
        ab = abst
        num += [i]
print(min(num))

Submission status: Wrong Answer

Solution code:
X, N = map(int, input("").split(" "))
p = list(map(int,input().split()))
p.sort()
q = [i+1 for i in range(100)]

ans = 0
diff = 100

for i in q:
    if (abs(X - i) < diff and (not i in p)):
        ans = i
        diff = abs(X-i)
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 100:
    print("")
    exit()
elif n > 0:
    ps = list(map(int, input().split()))
else:
    print(x)
    exit()
nums = [n for n in range(1, 101) if n not in ps]

abs_plus = sorted([n-x for n in nums if n-x >= 0])
abs_minus = sorted([-(n-x) for n in nums if n-x < 0])
if abs_plus == []:
    print(x-abs_minus[0])
elif abs_minus == []:
    print(x+abs_plus[0])
elif abs_plus[0] >= abs_minus[0]:
    print(x-abs_minus[0])
else:
    print(x+abs_plus[0])

Submission status: Wrong Answer

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

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


    ans_candi = [i+X for i in range(-min_abs, min_abs+1) if not i+X in P]
    ans = min(ans_candi)
    print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
cnt = 0
s = 0
o = 0
while True:
    if not(x - cnt in p):
        s = x - cnt
    if not(x + cnt in p):
        o = x + cnt
    if s != 0 or o != 0:
        break
    cnt += 1
if s != 0 and o != 0:
    if s < o:
        print(s)
    else:
        print(o)
elif s != 0:
    print(s)
elif o != 0:
    print(o)

Submission status: Wrong Answer

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

if x not in p:
    print(x)
else:
    t = [i for i in range(1,101)]
    for i in range(n):    
        t.remove(p[i])
#         print(t)

    res = 100
    s = 1000
    print(len(t))
    for i in range(len(t)):
#         print(t[i])
        if s >= abs (x - t[len(t)-1-i]):
            s = abs (x - t[len(t)-1-i])
            res = t[len(t)-1-i]
    print(res)

Submission status: Wrong Answer

Solution code:
x,y= map(int,input().split())
flag = 0

for turu in range(1,x+1):
    turu = turu
    kame = x - turu
    print(turu,kame)
    if kame*4 + turu*2 == y:
        print("Yes")
        frag = 1
        break
print("No" if flag == 0 else "")

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if(n > 0):
  p = list(map(int, input().split()))
  lists = list(range(101))
  del lists[0]
  sa = []
  for i in lists:
    if(i in p):
      sa.append(999)
    else:
      sa.append(abs(x-i))
    ind = sa.index(min(sa))
    ans = lists[ind]
else :
  ans = x
if (x <= ans - x):
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=p+[100000000]
p=list(map(lambda i:abs(x-i),p))

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

Submission status: Wrong Answer

Solution code:
temp1 = input().split(" ")
temp1 = [int(i) for i in temp1]
x = temp1[0]
n = temp1[1]

if not n == 0:
    temp2 = input().split(" ")
    temp2 = [int(i) for i in temp2]
else:
    temp2 = []

pn = temp2

counter = 1
while True:
    if n == 0:
        print(x)
        break

    mx = x - counter
    px = x + counter

    if not mx in pn:
        print(mx)
        break
    if not px in pn:
        print(px)
        break

    counter += 1

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
if n != 0:
  p = sorted(map(int,input().split()))
aa = []
for i in range(1,101):
  if not i in p:
    aa.append(i)
bb = []
if len(aa) == 0:
  if abs(x-(-1)) <= abs(x-101):
    print(-1)
    exit()
  else:
    print(101)
    exit()
else:
  for A in aa:
    eee = abs(x-A)
    bb.append(eee)

ans = bb.index(min(bb))
if abs(x-(-1)) <= min(bb):
  print(-1)
  exit()
elif abs(x-101) <= min(bb):
  print(101)
  exit()
else:
  print(aa[ans])
  exit()

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)

answer = 101
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:
import numpy as np

def main():
    x, n = [int(x) for x in input().split()]
    if n > 0:
        ps = [int(x) for x in input().split()]
        s = set(list(range(1, 101)))
        notps = s - set(ps)
        if len(notps) == 0:
            print(x)
            return
        ps = np.array(list(notps))
        ps = ps - x
        ps = [abs(p) for p in ps]
        ps.sort()
        m = ps[0]
        if x - m in notps:
            print(x - m)
            return
        else:
            print(x + m)
            return
    else:
        print(x)
    

main()

Submission status: Wrong Answer

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

if y == 0:
    print(x)
    quit()

ans=[]
for i in range(max(li)):
    if not i in li:
        ans.append(abs(i - x))

if not x - min(ans) in li:
    print(x-min(ans))
elif not min(ans) + x in li:
    print(min(ans) + x)

Submission status: Wrong Answer

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

arr = []
incc = []
for i in range(100):
    for j in range(n):
        incc.append(p[j])
    if i in incc:
        continue
    else:
        arr.append(i)
for i in range(len(arr)):
    if n == 0:
        print(x)
        break
    elif x-i in arr:
        print(x-i)
        break
    elif x+i in arr:
        print(x+i)
        break

Submission status: Wrong Answer

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

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

def check(x,n):
    # そもそも配列の数が0の場合は中断
    if int(n) == 0:
        print(x)
        return

    # 与えられた変数の配列
    p_list = input().split()

    # 差数を１ずつ上昇させていってみる
    for i in range(0, 50):
        min_x = str(x - int(i))
        max_x = str(x + int(i))

        # 片方
        if min_x not in p_list or max_x not in p_list:
            if min_x not in p_list:
                print(min_x)
                return
            
            if max_x not in p_list:
                print(max_x)
                return
        # 片方
        if min_x not in p_list and max_x not in p_list:
            print(min_x)
check(x,n)

Submission status: Wrong Answer

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

if N!=0:
	P=sorted(list(map(int, input().split())))
	pabs=[]
	for p in P:
		pabs.append(abs(X-p))
	pabs.sort()
	
	if 0 in pabs:
		for i in range(1,max(pabs)+1):
			if i in pabs:
				
				if pabs.count(i)==1:
					if X-i not in P:
						ans=X-i
						flag=1
						break
					else:
						ans=X+i
						flag=1
						break
					
				else:
					continue
				
			else:
				ans=X-1
				flag=1
				break
		
		print(X-max(pabs)-1 if flag==0 else ans)
										
	else:
		print(X)
		
else:
	print(X)

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)

for i in range(-x,100):
    if i not in nlist:
        Nlist.append(i)
abslist=[abs(x-i) for i in Nlist]
#print(abslist)
if x-min(abslist)  not in nlist:
    print(x-min(abslist))
else:
    print(x+min(abslist))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left,bisect

x,N,*p = map(int,open(0).read().split())
dif = 300
near = 300
all_ = set(range(0,101))

for i in p:
    d = abs(i - x)
    if dif > d:
        dif = d
        near = i
left = list(all_ - set(p))        

dif2 = 300
near = 300
for i in left:
    d = abs(x-i)
    if d < near:
        near = d
        dif2 = i
print(dif2)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
li1 = list(map(int,input().split()))
if n == 0:
    print(x)
    exit()
b=100
c=0
li = []
li = list(range(min(li1)-1,max(li1)+1))
for ii in range(n):
    if li1[ii] in li:
        li.remove(li1[ii])
for i in range(len(li)):
    a=li[i]
    if a<=x:
        c=a
        if b>x-a:
            b=x-a
            c=a
    else:
        if b>a-x:
            b=a-x
            c=a
print(c)

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 = 0
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(min_p, max_p + 1):
    tmp_break = False
    challenge_plus += 1
    challenge_minus -= 1
    #print("比較対象は{0}, {1}".format(challenge_plus, challenge_minus))
    if(challenge_plus in p_list):
      p_list.remove(challenge_plus)
    else:
      goal = challenge_plus
      found = True
      tmp_break = True
      
    if(challenge_minus in p_list):
      p_list.remove(challenge_minus)
    else:
      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 = list(map(int,input().split()))
for i in range(1,100):
    if N == 0 or N == 100:
        print(X)
        break
    elif not X-i in p_list:
        print(X-i)
        break
    elif not X+i in p_list:
        print(X+i)
        break

Submission status: Wrong Answer

Solution code:
int_num, length = map(int, input().split())
num_list = (list(map(int, input().split())))
up_int = int_num
down_int = int_num
if length == 0:
    print(int_num)
else:
    while True:
        up_int += 1
        down_int -= 1
        flg1 = up_int in num_list
        flg2 = down_int in num_list
        if not flg1 and not flg2:
            print(down_int)
            break
        elif flg1 and not flg2:
            print(down_int)
            break
        elif flg2 and not flg1:
            print(up_int)
            break

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)
  if x>a[-1]:
    print(x)
  
  b=list(range((a[0]),(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:
X,N=map(int,input().split())
P=list(map(int,input().split()))
m=100
ans=0
lis=list(range(100,0,-1))
if N==100:
    if X<=50:
        print(0)
    else:
        print(101)
else:
    for k in lis:
        for l in range(N):
            if k==P[l]:
                lis[100-k]=0
    for i in lis:
        if abs(i-X)<=m:
            m=abs(i-X)
            ans=i
    print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
X2=X
c=0
d=0
b=0
for i in range(1000):
    if X+i not in P and X+i <= 200 :
        c=X+i
    if X-i not in P and X-i >= -100: 
        d=X-i
    if c!=0:
        if d!=0:
            if abs(c-X)==abs(d-X):
                print(min(c,d))
            elif abs(c-X) > abs(d-X):
                print(d)
            else:
                print(c)
        else:
            print(c)
        break
    if d!=0:
        print(d)
        break

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

    other_integer = [i for i in range(min(p)-1, max(p)+1)]

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

if XN[1] == 0:
  print(XN[0])
else:
  p = list(map(int, input().split()))
  for d in range(1, XN[1] + 1):
    if not XN[0] + d in p:
      print(XN[0] + d)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
x, n = map(int, input().split())
if n != 0:
  p = list(map(int, input().split()))
  
  p.sort()
  x_plus = 0
  x_search = x
  for i in range(n):
    if p[i] == x_search:
      x_search += 1
    elif p[i] > x_search:
      x_plus = x_search
      break

  p.sort(reverse=True)
  x_minus = 0
  x_search = x
  for i in range(n):
    if p[i] == x_search:
      x_search -= 1
    elif p[i] < x_search:
      x_minus = x_search
      break

  if abs(x_plus - x) - abs(x_minus -x) >= 0:
    print(x_minus)
  else:
    print(x_plus)
else:
  print(x)

Submission status: Wrong Answer

Solution code:
a = input().split()
X = int(a[0])
N = int(a[1])
OK = []
list = []
if N ==0:
    print(X)
else:
    P = input().split()
    for i in range(101):
        OK.append(str(i))
    for i in range(len(P)):
        OK.remove(P[i])
    for i in range(len(OK)):
        list.append(abs(int(OK[i]) - X))
    Y = list.index(min(list))
    print(OK[Y])

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 100:
    print("")
elif n > 0:
    ps = list(map(int, input().split()))
else:
    print(x)
exit()
nums = [n for n in range(1, 101) if n not in ps]

abs_plus = sorted([n-x for n in nums if n-x >= 0])
abs_minus = sorted([-(n-x) for n in nums if n-x < 0])
if abs_plus == []:
    print(x-abs_minus[0])
elif abs_minus == []:
    print(x+abs_plus[0])
elif abs_plus[0] >= abs_minus[0]:
    print(x-abs_minus[0])
else:
    print(x+abs_plus[0])

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()
	if n == 100:
		lower = 0
		upper = 101
		if abs(x - lower) < abs(x - upper):
			print(lower)
		else:
			print(upper)
		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:
X, N = map(int, input().split())
P = list(map(int, input().split()))
if N == 0:
    print(100)

else:
    min_abs = 100
    min_abs = min([abs(X-i) for i in range(100) if not i in P])
    min_abs


    ans_candi = [i+X for i in range(-min_abs, min_abs+1) if not i+X in P]
    ans = min(ans_candi)
    print(ans)

Submission status: Wrong Answer

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

if n>0:
    a=list(map(int,input().split()))
    a.sort
    x_p=x
    x_n=x
    
    while True:
        x_n-=1
        x_p+=1
        if all(elem != x_p for elem in a) and all(elem != x_n for elem in a):
            print(x_n)
            break;
        elif all(elem != x_p for elem in a):
            print(x_p)
            break;
        elif all(elem != x_n for elem in a):
            print(x_n)
            break;
            
else:
  print(x)

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 = n
if n == 0:
  print(x)
else:
  for i in range(max(p)+1):
    if p.count(i) == 0:
      for j in range(i,100):
        #print('i=',i,abs(x-j))
        if abs(x-j) < y:
          ans = j
          y = abs(x-j)
  print(ans)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
if not a[1] ==0:
  b = list(map(int,input().split()))
  c = 0
  d = [a[0]]*a[1]
  b2 = sorted(b)##小さい順に並べる
  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])