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:
if __name__ == "__main__":
    X, N = list(map(int, input().split()))
    p = list(map(int, input().split()))
    q = p
    for i in range(N):
        q[i] = abs(X-p[i])
    
    if q.count(0) == 0:
        print(X)
    else:
        j = 1
        while True:
            if q.count(j) != 2:
                if q.count(j) == 0:
                    print(X - j)
                    break
                else:
                    if X - j in p:
                        print(X + j)
                    else:
                        print(X - j)
                    break
            j += 1

Submission status: Wrong Answer

Solution code:
x,n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
ans = []
mini = 101
maxi = 101
if n == 0 :
    print(x)
    exit()
elif not x in p :
    print(x)
    exit()
p.sort()
indenxX = p.index(x)
for i in range(1,indenxX+1) :
    if p[indenxX-i] !=  x-i :
        mini = i
        break
for i in range(1,n-indenxX) :
    if p[indenxX+i] != x+i :
        maxi = i
        break
if mini <= maxi :
    print(x-mini)
else :
    print(x+maxi)

Submission status: Wrong Answer

Solution code:
def resolve():
    X, N = [int(i) for i in input().split()]
    if N == 0:
        print(X)
        return
    p_list = [int(i) for i in input().split()]
    min_len_with_X = 100
    min_len_i = 0
    for i in range(1, 101):
        if i in p_list:
            continue
        if abs(i - X) < min_len_with_X:
            min_len_with_X = abs(i - X)
            min_len_i = i
    print(min_len_i)

resolve()

Submission status: Wrong Answer

Solution code:
import sys
def main():
    x, n = map(int, input().split())
    p = list(map(int,input().split()))
    
    if (n==0):
        print(x)
    else:
        for i in range(n):
            low = x - i
            if (low not in p):
                print(low)
                sys.exit()
            
            up = x + i
            if (up not in p):
                print(up)
                sys.exit()
    
main()

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
import math
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007
# ani,total = iia()
# if ani==1:
#     print('No')
# elif total % 2==0:
#     if 2<=(4*ani-total)<=(2*ani-2):
#         print('Yes')
#     else:
#         print('No')
# else:
#     print('No')
x,n=iia()
if n==0:
    print(x)
else:
    arr=iia()
    arr.sort()
    dp = []
    l=arr[0]
    r=arr[-1]
    res=inf
    for i in range(1,101):
        if i not in arr:
            dp.append(i)
    ans=0
    for j in dp:
        if abs(j-x)<res:
            ans = j
            res=abs(j-x)
    print(ans)

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(XN[1] + 1):
    if not XN[0] - d in p:
      print(XN[0] - d)
    if not XN[0] + d in p:
      print(XN[0] + d)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  numbers=list(range(-1,102))
  ans=0

  for i in range(len(p)):
    numbers.remove(p[i])

    for j in range(101):
      for k in range(len(numbers)):
        if abs(X-numbers[k]) == 101-j:
          ans=numbers[k]
          break
  print(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 not in pset:
    print(X-i)
    break

Submission status: Wrong Answer

Solution code:
# X:整数　N:長さ
# p1 ... pN
# 含まれない整数のうちXに近いものを答える
import sys
X, N = map(int, input().split())
p = []
for i in sys.stdin:
    p = list(map(int, i.split()))
#p = list(map(int, input().split()))
for i in range(X, -51, -1):
    l = i
    if i not in p:
        break
for j in range(X, 151):
    r = j
    if j not in p:
        break
print(l if abs(l-X) < abs(r-X) else r)

Submission status: Wrong Answer

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

# 数列内の最大最小値幅のリストを新たに作る
base = list(range(-1, 100 + 1))
# 数列内に無い数値を抽出する
diff = list(set(base) - set(ls))

diff = sorted(diff)

ans = 1000
for i in diff:
    if abs(x - ans) > abs(x - i):
        ans = i

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 = n
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 numpy as np
import sys
X, N = np.array(list(map(int, input().split())))
if N == 0:
    print(X)
    sys.exit()
p = np.array(list(map(int, input().split())))
p = np.sort(p)
a = np.ones(304, dtype = np.int)
a[p+102] = 0
m = X+102
n = 0
for i in range(304):
    if a[i] == 1:
        if m>abs(i-X-102):
            if i-X-102 != 0:
                m = abs(i-X-102)
                n = i-102
print(int(n))

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = (int(i) for i in input().split())
p = sorted([int(i) for i in input().split()])
if X in p:
    s = p.index(X)
    i = 1
    while True:
        if (s-i)<0:
            print(p[0]-1)
            break
        elif (s+i)>=N:
            print(p[N-1]+1)
            break

        if p[s-i] != (X-i):
            print(X-i)
            break
        if p[s+i] != (X+i):
            print(X+i)
            break
        i = i + 1
else:
    print(X)

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:
        print(X)
        break
    elif N == 100:
        print(-1)
        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:
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-(0)) <= abs(x-101):
    print(0)
    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-(0)) <= min(bb):
  print(0)
  exit()
elif abs(x-101) <= min(bb):
  print(101)
  exit()
else:
  print(aa[ans])
  exit()

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

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

for i in range(1,101):
    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()

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    li = list(map(int,input().split()))
    for i in range(1, 101):
        up = x + i
        down = x - i
        if down not in li:
            print(down)
            break
        if up not in li:
            if down == up:
                print(down)
                break
            else:
                print(up)
                break

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

    pmax = 0
    pmin = 101
    for pr in p:
        if pmax < pr:
            pmax = pr
        if pmin > pr:
            pmin = pr

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

if (x == 1 and y == 2) or (x == 1 and y == 4):
    print('Yes')
    quit()

for i in range(-101,201):
    if i * 2 + (x - i) * 4 == y:
        print('Yes')
        quit()
print('No')

Submission status: Wrong Answer

Solution code:
A1 = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
 
X = A1[0]
N = A1[1]
diff = []
ans=[]
if N==0:
  print(X)
elif N>0:
  for i in range(N):
    diff.append(abs(p[i]-X))
  min_diff=min(diff)
  for i in range(N):
    if abs(p[i]-X)==min_diff:
      ans.append(p[i])
  if int(len(ans))==1:
    print(ans[0])
  else:
    print(min(ans))

Submission status: Wrong Answer

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

#print(valid)

for j in range(100):
#	print(x,j,x-j,x+j)
#	print(valid[x-j])
#	print(valid[x+j])
	if((x-j) >= 1):
		if(valid[x-j] == 1):
			print(x-j)
			break
	if((x+j) <= 100):
#		print("aaa")
		if(valid[x+j] == 1):
			print(x+j)
			break

Submission status: Wrong Answer

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

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(-101,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:
#H, W = map(int,input().split())
#N = int(input())
#al = list(map(int,input().split()))
X, N = map(int,input().split())
pl = list(map(int,input().split()))

lst = [i for i in range(-101,101)]

anslst = []
for n in lst:
    if not n in pl:
        anslst.append(n)



an = 1000
idx = 0
for i in range(len(anslst)):
    tmp = abs(X - anslst[i])
    if tmp < an:
        an = tmp
        idx = i


ans = anslst[idx]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    if p == []:
        print(x)
    else:
        for i in range(0, 100):
            if not x-i in p:
                if x-i >= 0:
                    print(x-i)
                    break
            else:
                if not x+i in p:
                    if x+i <= 100:
                        print(x+i)
                        break
        

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# 数列内の最大最小値幅のリストを新たに作る
base = list(range(0, 100 + 1))
# 数列内に無い数値を抽出する
diff = list(set(base) - set(ls))

diff = sorted(diff)

ans = 1000
for i in diff:
    if abs(x - ans) > abs(x - i):
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
sub_list=[0]*n

if n == 0:
    print(x)
else:
    number_list = list(map(int,input().split()))
    number_list.sort()
    for tmp in range(0,n):
        sub_list[int(tmp)]=abs(number_list[int(tmp)]-x)
    sub_list.sort()
    #print(sub_list)

    if sub_list.count(0) == 0:
        print(x)
    else:
        for tmp in range(1,51):
            if sub_list.count(tmp) < 2:
                break
        #print(tmp)

    Ans1=x-tmp
    Ans2=x+tmp
    if number_list.count(Ans1) == 0:
        print(Ans1)
    else:
        print(Ans2)

Submission status: Wrong Answer

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

if N == 1:
    if not (X - 1) in P:
        print(X - 1)
        exit()
    if not (X + 1) in P:
        print(X + 1)
        exit()

for n in range(1, (N // 2) + 1):
    if not (X - n) in P:
        print(X - n)
        exit()
    if not (X + n) in P:
        print(X + n)
        exit()
if min(P) - 1 < 0:
    print(max(P) + 1)
    exit()
print(min(P) - 1)

Submission status: Wrong Answer

Solution code:
X,N = input().split()
X = int(X)
N = int(N)
if N == 0:
  print(X)
else:
  a = []
  a = input().split()

  ans1 = 0
  ans2 = 0
  for i in range(N):
    count = 0
    ans = X - i
    for j in range(0,N):
      #print("X-i = {}".format(ans))
      if ans == int(a[j]):
        ans = 0
        break
      else:
        count += 1
        #print("count = {}".format(count))
    if count == N:
      ans1 = ans
    count2 = 0
    for k in range(0,N):
      ans= X + i
      #print("X+i = {}".format(ans))
      if ans == int(a[k]):
        ans = 0
        break
      else:
        count2 += 1
    if count2 == N:
      ans2 = ans
      #print("ans2 = {}".format(ans2))
      break
  
    if ans != 0:
      break
  
  
  #print(ans1,ans2)
  dis1 = X - ans1
  dis2 = ans2 - X
  #print(dis1,dis2)
  if dis1 > dis2:
    ans = ans2
    #print(ans2)
  else:
    ans = ans1
    #print(ans1)
  
  print(ans)

Submission status: Wrong Answer

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

a = 100
num = 0

for i in range(201):
    if (i-100) not in p:
        b = (i-100)-X
        if abs(b) < a:
            a = abs(b)
            num = (i-100)

print(num)

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)
else:
  print(high)

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)
    if not XN[0] + d in p:
      print(XN[0] + d)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    quit()
p=list(map(int,input().split()))
p.sort()
if p[-1]<x:
    print(x)
    quit()
ans=[]
#本題
if x not in p:
    print(x)
    quit()
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:
def forbidden(x,p):
    res = []
    for num in range(101):
        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)
        exit()
    print(forbidden(x,p))

Submission status: Wrong Answer

Solution code:
x, n = map(int,input().split())
a = list(map(int, input().split()))
l = x
r = x
while(True):
    r += 1
    l -= 1
    if not l in a:
        print(l)
        break
    elif not r in a:
        print(r)
        break

Submission status: Wrong Answer

Solution code:
x,n  = map(int, input().split())
p = list(map(int, input().split()))
if x in p:
    diff = 1000
    index = 1000
    for i in range(101):
        if i != x and i not in p:
            if abs(x-i) <diff:
                diff = abs(x-i)
                index = i
    if index != 1000:
        print(index)
    else:
        print(x)
else:
    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 = input()
    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()

p = list(map(int, input().split()))
l = []
for i in range(0,101):
  l.append(i)

L = []
for i in l:
  if i not in p:
    L.append(i)

l = []
for i in L:
  l.append([i, abs(x-i)])
a = min(l, key = lambda t: t[1])
print(list(a)[0])

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]+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:
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit(0)
a = [int(x) for x in input().split()]
num_2 = 100
for i in range(1, 101):
    if i not in a:
        num = abs(i - x)
        if num_2 == num:
            print(sub)
            exit(0)
        if num > num_2: 
            print(i-1)
            exit(0)
        sub = i
        num_2 = num

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:
            print(L)
            break
        if H not in P:
            print(H)
            break
        L -= 1
        H += 1
else:
    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(101,-1,-1))
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())
import sys
if n==0:
    print(x)
    sys.exit()
a=list(map(int,input().split()))
l=0
c=101
d=0

for i in range(1,101):
    for j in range(n):
        if i==a[j]:
            l=1
            break
    if l==1:
        l=0
        continue
    if abs(i-x)<c:
        c=abs(i-x)
        d=i
print(d)

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 = -1
  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:
s = list(map(int,input().split()))
d = 0
u = 0
t = 0
         
for i in range(s[0],s[0]+s[1]+1):
  for k in range(s[1]):
    if k ==s[0]:
      continue
    if k ==s[1]:
      continue  
    if i == k:
      d==0
      break
  if d == 1:
    t = i
    break
for i in range(s[0],s[0]-s[1]-1):
  for k in range(s[1]):
    if k ==s[0]:
      continue
    if k ==s[1]:
      continue  
    if i == k:
      d==0
      break
  if d == 1:
    t = i
    break
print(max(u,t))

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def getNearestValue(list, num):
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

x, n = map(int, readline().split())

if n == 0:
    print(x)
    exit()
p = set(map(int, readline().split()))
s = [i for i in range(-1, 101) if i not in p]
print(getNearestValue(s, x))

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(-101,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 = map(int, input().split())
p_list = [str(e) for e in input().split()]

for i in range(N + 1):
    x = X - i
    y = X + i
    if str(x) in p_list == 0:
        print(x)
        break
    elif str(y) in p_list == 0:
        print(y)
        break

Submission status: Wrong Answer

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

nun_list = list(map(int, input().split()))
answer = nun_list[0]
for i in nun_list:
    if abs(x - answer) >= abs(x - i):
        if abs(x - answer) == abs(x - i):
            if answer > i:
                answer = i
        else:
            answer = i
tmp = 0
for i in range(0,1000):
    if not nun_list.__contains__(answer -i):
        tmp = answer -i
        break
    if not nun_list.__contains__(answer + i):
        # print(answer + i)
        tmp = answer + i
        break
print(tmp)
if abs(x - tmp) <= abs(x - 0):
    print(tmp)
else :
    print(tmp)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
p = list(map(int, input().split()))
ar1 = list(range(101))
ar2 = list(set(ar1) - set(p))
ar3 = sorted(ar2, reverse = True)
diff = 100
for i in ar3:
  if abs(x - i) <= diff:
    diff = abs(x - i)
    ans = i
  else:
    break

print(ans)

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)
        ps = np.array(list(notps))
        ps = ps - x
        ps = [abs(p) for p in ps]
        ps.sort()
        if len(ps) > 0:
            m = ps[0]
        else:
            m = 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,n = map(int, input().split())
valid = [1] *101
p = list(map(int, input().split()))
for i in range(n):
	valid[p[i]] = 0

#print(valid)

for j in range(50):
#	print(x,j,x-j,x+j)
#	print(valid[x-j])
#	print(valid[x+j])
	if((x-j) >= 1):
		if(valid[x-j] == 1):
			print(x-j)
			break
	if((x+j) <= 100):
#		print("aaa")
		if(valid[x+j] == 1):
			print(x+j)
			break

Submission status: Wrong Answer

Solution code:
int_num, length = map(int, input().split())
if length == 0:
    print(int_num)
else:
    num_list = (list(map(int, input().split())))
    up_int = int_num
    down_int = int_num
    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:
kazulist = []
for i in range(101):
    kazulist.append(i)
 
a = list(input().split(" "))
target = int(a[0])
syokyo = int(a[1])

if syokyo != 0:
    b = list(input().split(" "))
    for i in b:
        kazulist.remove(int(i))
 
saisyosa = 100
kotae = 0
for i in kazulist:
    sa = target - int(i)
    #print(sa)
    if sa < 0:
        sa *= -1
    if sa < saisyosa:
        saisyosa = sa
        kotae = i
 
print(kotae)

Submission status: Wrong Answer

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

if Y == 0:
    print(X)
if Y != 0:
    for i in range(1, 100):
        if abs(X-i) not in p :
            print(X-i)
            break
        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()))
if x in p:
    diff = 1000
    index = 0
    for i in range(101):
        if i != x and i not in p:
            if abs(x-i) <diff:
                diff = abs(x-i)
                index = i
    if index:
        print(index)
    else:
        print(x)
else:
    print(x)

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

p_ = [i for i in range(101)]
p_ = list(set(p_) - set(p))

list = []
list_ = []
for j in p_:
  C = abs(X-j)
  list.append(C)
  list_.append(X-j)
list.sort()
if list_.count(list[0]) == 0:
  print(X+list[0])
else:
  print(X-list[0])

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p_d  = [x-int(i) for i in input().split()]
p_sorted = sorted(p_d,key= lambda x: (-x+0.1, x)[x > 0])

l = [x-k for k in range(-100,101)]
l_sorted = sorted(l,key= lambda x: (-x+0.1, x)[x > 0])

for i in range(n):
    ans = l_sorted[i]
    if p_sorted[i] != ans:
        print(x-ans)
        break
if n == 0:
    print(x)

Submission status: Wrong Answer

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

if N == 1:
    if not (X - 1) in P:
        print(X - 1)
        exit()
    if not (X + 1) in P:
        print(X + 1)
        exit()

for n in range(1, (N // 2) + 1):
    print(X - n)
    print(X + n)
    if not (X - n) in P:
        print(X - n)
        exit()
    if not (X + n) in P:
        print(X + n)
        exit()
if min(P) - 1 < 0:
    print(max(P) + 1)
    exit()
print(min(P) - 1)

Submission status: Wrong Answer

Solution code:
#!/usr/local/bin/python3
# coding: utf-8

ha = input()
kita = ha.split(" ")
roop = 0
isR = False
if(int(kita[1]) == 0):
    print(kita[0])
else:
    koi = input()
    n = koi.split(" ")

    while(True):
        roop += 1
        a = True
        for num in n:
            if(int(kita[0])-roop == int(num)):
                a = False
        if(a):
            print(int(kita[0])-roop)
            break
        a = True
        for num in n:
            if(int(kita[0])+roop == int(num)):
                a = False
        if(a):
            print(int(kita[0])+roop)
            break

Submission status: Wrong Answer

Solution code:
X,N=[int(x) for x in input().strip().split(" ")]
P=list(map(int,input().split()))
if len(P)==0:
    print(X)
else:
    for i in range(int(N/2)+1):
        if X-i not in P:
            print(X-i)
            break
        elif X+i not in P:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
X,N = [int(i) for i in input().split()]

p = [int(i) for i in input().split()] if N > 0 else [-10**9]

p = sorted(p, key=lambda x: x)

minDistance = 10**9
minNum = -10**9

for i in range(min(p), max(p)+1, 1):
  if i not in p and minDistance > abs(X - i):

     minNum = i 
     minDistance = abs(X - i)

print(minNum if minNum > -10**9 else X )

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(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())
if n==0:
    print(x)
    exit()
p=list(map(int,input().split()))
a=x-1
b=x+1
while a in p:
    a-=1
while b in p:
    b+=1
if abs(x-a)>abs(x-b):
    print(b)
elif abs(x-a)==abs(x-b):
    print(min(a,b))
else:
    print(a)

Submission status: Wrong Answer

Solution code:
# coding: utf-8


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

for i in range(N // 2 + 1):
  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, n = map(int, input().split())
p = sorted(list(map(int, input().split())))
a = 250
b = []
if n == 0:
    print(x)
else :
    for i in range(-100, 101):
        if not i in p:
            diff = abs(x-i)
            if diff < a:
                a = min(a, diff)
                b.append(i)
            else :
                print(b[-1])
                break