Problem:


Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Wrong Answer

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

idx = -1
for i in range(n):
    if p[i] == 0:
        idx = i
if idx == -1:
    print(x)
    exit()
sa = 1
while 1:
    if idx-sa<0:
        print(x-sa)
        exit()
    if idx+sa>n-1:
        print(x+sa)
        exit()
    if p[idx-sa] != -sa:
        print(x -sa)
        exit()
    elif p[idx+sa] != sa:
        print(x+sa)
        exit()
    sa +=1

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = set(map(int, input().split()))
    if not x in p:
        print(x)
    else:
        a = [abs(x-i) if not i in p else 1000 for i in range(-1, 102)]
        print(a)
        print(a.index(min(a))-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = set(map(int, input().split()))
    if not x in p:
        print(x)
    else:
        a = [abs(i-x) if not i in p else 1000 for i in range(-1, 102)]
        print(a.index(min(a))+1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = set(map(int, input().split()))
    if not x in p:
        print(x)
    else:
        a = [abs(i-x) if not i in p else 1000 for i in range(11, 102)]
        print(a.index(min(a))+1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = set(map(int, input().split()))
    if not x in p:
        print(x)
    else:
        a = [abs(i-x) if not i in p else 101 for i in range(1, 101)]
        print(a.index(min(a))+1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


def func(near):
    if near not in p_list:
        print(near)
        quit()


while(True):
    near = X - abs_num
    func(near)
    near = X + abs_num
    func(near)
    abs_num += 1

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
p = [int(i) for i in input().split()]

for i in range(int(y/2) + 1):
  d = x + (i * -1)
  u = x + i
  if not d in p:
    print (d)
    break
  elif not u in p:
    print (u)
    break

Submission status: Wrong Answer

Solution code:
def workC():
    
    u=999
    d=999
    minx = 1-1
    maxx = 100+1
    
    
    x,n = map(int,input().split())
    l = list(map(int,input().split()))
    
    l.sort()

    if n == 0:
        return x
    
    if n == 100:
        return 0
    
    for i in range(x,maxx):
        if not i in l:
            u = i
            #dic.setdefault(i,abs(i-x))
            break
    
    for i in range(x,minx,-1):
        if not i in l:
            d = i
            #dic.setdefault(i,abs(x-i))
            break
    
    if abs(x-u) == abs(x-d):
        return min(u,d)
    elif abs(x-u) < abs(x-d):
        return u
    else:
        return d

ans = workC()
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
x,n = [int(i) for i in input().split()]
l = {int(i) for i in input().split()}

xl = {int(i) for i in range(x+2)}

ans_list = list(xl - l)

ans = bisect.bisect_right(ans_list,x)

print(ans_list[ans-1] if ans != 0 else ans[1])

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

x, n = map(int, input().split())
if(n==0):
  print(x)
  sys.exit()
p = list(map(int, input().split()))
q = [0]*n
l = 1000
for i in range(n):
  q[i] = abs(p[i]-x)
for j in range(120):
  for k in range(n):
    l = min(abs(q[k]-j),l)
  if(not(l ==0)):
    for m in range(n):
      if(x + j -p[i] == abs(x + j -p[i])):
        print(x-j)
        sys.exit()
      else:
        print(x+j)
        sys.exit()

Submission status: Wrong Answer

Solution code:
def workC():
    
    u=999
    d=999
    minx = 1-1
    maxx = 100+1
    
    
    x,n = map(int,input().split())
    l = list(map(int,input().split()))

    if n == 0:
        return x
    
    if n == 100:
        return x
    
    for i in range(x,maxx):
        if not i in l:
            u = i
            #dic.setdefault(i,abs(i-x))
            break
    
    for i in range(x,minx,-1):
        if not i in l:
            d = i
            #dic.setdefault(i,abs(x-i))
            break
    
    if abs(x-u) == abs(x-d):
        return min(u,d)
    elif abs(x-u) < abs(x-d):
        return u
    else:
        return d

ans = workC()
print(ans)

Submission status: Wrong Answer

Solution code:
def workC():
    
    u=999
    d=999
    minx = 1-1
    maxx = 100+1
    
    
    x,n = map(int,input().split())
    l = list(map(int,input().split()))

    if n == 0:
        return x
    
    if n == 100:
        return 0
    
    for i in range(x,maxx):
        if not i in l:
            u = i
            #dic.setdefault(i,abs(i-x))
            break
    
    for i in range(x,minx,-1):
        if not i in l:
            d = i
            #dic.setdefault(i,abs(x-i))
            break
    
    if abs(x-u) == abs(x-d):
        return min(u,d)
    elif abs(x-u) < abs(x-d):
        return u
    else:
        return d

ans = workC()
print(ans)

Submission status: Wrong Answer

Solution code:
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# atcoder.main
# Date: 2020/06/18
# Filename: main 
# Author: acto_mini

def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))

    if not X in P:
        print(X)
        exit()

    min_num = 0
    min_dist = 101
    P.sort()
    for i in range(0, 101):
        if i in P: continue

        dist = abs(X - i)

        if dist < min_dist:
            min_dist = dist
            min_num = i

    print(min_num)

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# atcoder.main
# Date: 2020/06/18
# Filename: main 
# Author: acto_mini

def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))

    if not X in P:
        print(X)
        exit()

    min_num = 0
    min_dist = 101
    for i in range(0, 101):
        if i in P: continue

        dist = abs(X - i)

        if dist < min_dist:
            min_dist = dist
            min_num = i

    print(min_num)

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# atcoder.main
# Date: 2020/06/18
# Filename: main 
# Author: acto_mini

def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))

    if not X in P:
        print(X)
        exit()

    min_num = 0
    min_dist = 101
    for i in range(-1, 101):
        if i in P: continue

        dist = abs(X - i)

        if dist < min_dist:
            min_dist = dist
            min_num = i

    print(min_num)

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
a = list(map(int, input().split()))
ans = 1
min_diff = float('inf')
for i in range(1, 101):
    if i in a:
        continue
    if (abs(i - X) < min_diff) or (abs(i - X) == min_diff and i < ans):
        min_diff = abs(i - X)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
min_diff = float('inf')
for i in range(101):
    if i in a:
        continue
    if (abs(i - X) < min_diff) or (abs(i - X) == min_diff and i < ans):
        min_diff = abs(i - X)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = {*map(int, input().split())}

ans = 1000
diff = 1000
for i in range(101):
  if i in p:
    continue
  if abs(x - i) < diff:
    diff = abs(x - i)
    ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

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


X, Y = map(int, input().split())
list = list(map(int, input().split()))
list = sorted(list)


listHandred = []
for i in range(0,101):
    listHandred.append(i)
    
ansList = listHandred

for i in list:
    if i in ansList:
        ansList.remove(i)

print(getNearestValue(ansList,X))

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
a =  set(map(int, input().split()))
print(a)
d = 0

while True:
  if not X - d in a:
    print(X - d)
    break
  
  if not X + d in a:
    print(X + d)
    break
  
  d += 1

Submission status: Wrong Answer

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

if n == 0:
    print(x)

else:
    l = list(map(int, input().split()))
    tmp = x
    while x:
        if not x in l:
            print(x)
            break
        elif not tmp in l:
            print(tmp)
            break
        x -= 1
        tmp += 1

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i-1==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True
  for i in range(n):
    for j in range(n):
      if(x+i+1==p[j]):
        check=False
    if(check):
      l_list.append(x+i)
    check=True
  if(abs(x-min(l_list)) > abs(x-max(s_list))):
    ans = max(s_list)
  elif(abs(x-min(l_list))==abs(x-max(s_list))):
    ans=max(s_list)
  else:
    ans=min(l_list)

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i-1==p[j]):
        check=False
    if(check):
      s_list.append(x-1-i)
    check=True
  for i in range(n):
    for j in range(n):
      if(x+i+1==p[j]):
        check=False
    if(check):
      l_list.append(x+i+1)
    check=True
  if(abs(x-min(l_list)) > abs(x-max(s_list))):
    ans = max(s_list)
  elif(abs(x-min(l_list))==abs(x-max(s_list))):
    ans=max(s_list)
  else:
    ans=min(l_list)

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n+1):
    for j in range(n):
      if(x-i-1==p[j]):
        check=False
    if(check):
      s_list.append(x-1-i)
    check=True
  for i in range(n+1):
    for j in range(n):
      if(x+i+1==p[j]):
        check=False
    if(check):
      l_list.append(x+i+1)
    check=True
  if(abs(x-min(l_list)) > abs(x-max(s_list))):
    ans = max(s_list)
  elif(abs(x-min(l_list))==abs(x-max(s_list))):
    ans=max(s_list)
  else:
    ans=min(l_list)

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n+1):
    for j in range(n):
      if(x-i-1==p[j] or x-i-1==0):
        check=False
    if(check):
      s_list.append(x-1-i)
    check=True
  for i in range(n+1):
    for j in range(n):
      if(x+i+1==p[j]):
        check=False
    if(check):
      l_list.append(x+i+1)
    check=True
  if(abs(x-min(l_list)) > abs(x-max(s_list))):
    ans = max(s_list)
  elif(abs(x-min(l_list))==abs(x-max(s_list))):
    ans=max(s_list)
  else:
    ans=min(l_list)

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
P = list(map(int, input().split()))
if not P:
    print(x)
exit(0)
for i in range(x, 102):
    if i not in P:
        upper = i
        break
    else:
        upper = 102
for i in range(x, -1, -1):
    if i not in P:
        lower = i
        break
    else:
        lower = 0
print(lower if x-lower <= upper - x else upper)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p = list(map(int, input().split()))
 
for i in range(0,N):
  if(X-i)not in p:
    print(X-i)
    break
  elif (X+i)not in p:
        print(X+i)
        break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
P = list(map(int, input().split()))
if not P:
    print(x)
for i in range(x, 102):
    if i not in P:
        upper = i
        break
    else:
        upper = 102
for i in range(x, -1, -1):
    if i not in P:
        lower = i
        break
    else:
        lower = 0
print(lower if x-lower <= upper - x else upper)

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i-1==p[j]):
        check=False
    if(check):
      s_list.append(x-1-i)
    check=True

  for i in range(n):
    for j in range(n):
      if(x+i+1==p[j]):
        check=False
    if(check):
      l_list.append(x+i+1)
    check=True
  if(abs(x-min(l_list)) > abs(x-max(s_list))):
    ans = max(s_list)
  elif(abs(x-min(l_list))==abs(x-max(s_list))):
    ans=max(s_list)
  else:
    ans=min(l_list)
print(ans)

Submission status: Wrong Answer

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

for i in range(0,N):
 if(X-i)not in p:
    print(X-i)
    break
 elif (X+i)not in p:
        print(X+i)
        break

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
retsu = list(map(int, input().split()))
# X, N = 6, 5
# retsu = [4,7,10,6,5]

hanbetsu = []
for i in range(101):
    hanbetsu.append(i)

retsu = set(retsu)
hanbetsu = set(hanbetsu)
hikaku = hanbetsu.difference(retsu)

if X in hikaku:
    print(X)
else:
    for i in range(1,101):
        if X - i in hikaku and X - i >= 0:
            print(X-i)
            break
        elif X + i in hikaku and X + i < 101:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
retsu = list(map(int, input().split()))
# X, N = 6, 5
# retsu = [4,7,10,6,5]

hanbetsu = []
for i in range(101):
    hanbetsu.append(i)

retsu = set(retsu)
hanbetsu = set(hanbetsu)
hikaku = hanbetsu.difference(retsu)

if X in hikaku:
    print(X)
else:
    for i in range(1,101):
        if X - i in hikaku:
            print(X-i)
            break
        elif X + i in hikaku:
            print(X+i)
            break

Submission status: Wrong Answer

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

if not X in retsu:
    print(X)
else:
    i = 1
    for i in range(101):
        if not X - i in retsu and X - i > 1:
            print(X-i)
            break
        elif not X + i in retsu and X + i <= 100:
            print(X+i)
            break

Submission status: Wrong Answer

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

if not X in retsu:
    print(X)
else:
    i = 1
    for i in range(101):
        if not X - i in retsu and X - i > 0:
            print(X-i)
            break
        elif not X + i in retsu and X + i <= 100:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
def search_near(X, N, nums):
    for n in range(1,N+1):
        if n % 2 ==0:
            diff = n//2 *(-1)
        else:
            diff = n//2
        target = X+diff
        if target in nums:
            pass
        else:
            print(target)
            break

X, N = map(int, input().split(" "))
if N ==0:
    print(X)
else:
    nums = [i for i in map(int, input().split(" "))]
    search_near(X,N,nums)

Submission status: Wrong Answer

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

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

p = [int(i) for i in input().split()]
  
q = set(range(101)) - set(p)  
  
r = sorted(q,key=lambda x:(abs(x-X),x))

print(r[0])

Submission status: Wrong Answer

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

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

p = [int(i) for i in input().split()]
  
q = set(range(101)) - set(p)  
  
r = sorted(q,key=lambda x:abs(x-X))

print(r[0])

Submission status: Wrong Answer

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

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

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

if X not in p:
  print(X)
  exit();

if N == 1 and p[0] == X:
  print(X-1)
  exit();

for j in range(100):
  if X-j not in p and X-j >=0:
    print(X-j)
    exit();
  if X+j not in p and X+j <= 100:
    print(X+j)
    exit();

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
flag = [False] * 101
for value in p:
    flag[value] = True
minAbs = 100
for i in range(101):
    ab = abs(x - i)
    if not flag[i]:
        minAbs = min(minAbs, ab)
for i in range(101):
    ab = abs(x - i)
    if not flag[i] and ab == minAbs:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
flag = [False] * 101
for value in p:
    flag[value] = True
minAbs = 100
for i in range(1, 101):
    ab = abs(x - i)
    if not flag[i]:
        minAbs = min(minAbs, ab)
for i in range(1, 101):
    ab = abs(x - i)
    if not flag[i] and ab == minAbs:
        print(i)
        break

Submission status: Wrong Answer

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

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

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

if X not in p:
  print(X)
  exit();

if N == 1 and p[0] == X:
  print(X-1)
  exit();

q = max(abs(max(p)-X),abs(min(p)-X))

for j in range(1,q+1):
  if X-j not in p:
    print(X-j)
    exit();
  if X+j not in p:
    print(X+j)
    exit();

Submission status: Wrong Answer

Solution code:
import sys

def Forbidden_List(x,n,p):
  for i in range(n//2 + n%2):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i
  return x - n//2 - n%2

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

Submission status: Wrong Answer

Solution code:
import sys

def Forbidden_List(x,n,p):
  #k = [abs(s - x) for s in p]
  #print(k)
  print(x)
  for i in range(n):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

Submission status: Wrong Answer

Solution code:
import sys

def Forbidden_List(x,n,p):
  for i in range(n//2 + n%2):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i
  return x - n//2 + n%2

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

Submission status: Wrong Answer

Solution code:
import sys

def Forbidden_List(x,n,p):
  #k = [abs(s - x) for s in p]
  #print(k)
  print(x)
  for i in range(n//2 + n%2):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i
  return x - n//2 - n%2

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

Submission status: Wrong Answer

Solution code:
import sys

def Forbidden_List(x,n,p):
  print(x)
  for i in range(n//2 + n%2):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i
  return x - n//2 + n%2

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

Submission status: Wrong Answer

Solution code:
import sys

def Forbidden_List(x,n,p):
  #k = [abs(s - x) for s in p]
  #print(k)
  print(x)
  for i in range(n//2 + n%2):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i
  return x - n

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

Submission status: Wrong Answer

Solution code:
import sys

def Forbidden_List(x,n,p):
  k = [abs(s - x) for s in p]
  print(k)
  for i in range(n):
    if i not in k: 
      return x - i
  return x - n

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

Submission status: Wrong Answer

Solution code:
import sys

def Forbidden_List(x,n,p):
  k = [abs(s - x) for s in p]
  for i in range(n):
    if i not in k: 
      return 10 - i
  return 10 - n

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
        inp2 = input().rstrip().split()
        p = list(map(int,inp2))
        print(Forbidden_List(x,n,p))

Submission status: Wrong Answer

Solution code:
import sys

def Forbidden_List(x,n,p):
  k = [abs(s - x) for s in p]
  for i in range(n):
    if i not in k: 
      return 10 - i
  return 10 - n

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    inp2 = input().rstrip().split()
    
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else:
        p = list(map(int,inp2))

        print(Forbidden_List(x,n,p))

Submission status: Wrong Answer

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

if n==0:
  print(x);exit()
  
if x in Q:
  print(x) ; exit()

A=[]
for i in range(1,250):
  A.append(-i)
  A.append(i)
  
for i in A:
  if not x+i in Q:
    print(x+i)
    exit()

Submission status: Wrong Answer

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

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

A=[]
for i in range(1,107):
  A.append(-i)
  A.append(i)
  
for i in A:
  if not x+i in Q:
    print(x+i)
    exit()

Submission status: Wrong Answer

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

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

A=[]
for i in range(1,107):
  A.append(-i)
  A.append(i)
for i in A:
  if not i in Q:
    print(i)
    exit()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
minn = x
if n == 0:
    arr = []
else:
    arr = list(map(int, input().split()))
    a = min(arr)
    b = max(arr)
    for i in range(a, b + 1):
        if abs(x - i) < minn and (i not in arr):
            minn = i





print(minn)

Submission status: Wrong Answer

Solution code:
# 全探索
x, n = map(int, input().split())

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

    min_list = []
    
    for i in range(-100, 101):
        if i not in p:
            ans = abs(i-x)
            min_list.append(ans)
    
    minimum = min(min_list)
    minimum_right = x + minimum
    minimum_left = x - minimum

    if minimum_right and minimum_left not in p:
        print(minimum_left)
    elif minimum_right not in p:
        print(minimum_right)
    else:
        print(minimum_left)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
lol = [int(n) for n in input().split()]
if(b == 0):
    print(a)
else:
    i = 1 
    while(1):
        if((a - i) not in lol):
            print(a-i)
            break
        elif((a + i) not in lol):
            print(a+i)
            break
        else:
            i += 1

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
l = set(i for i in range(102))
ans = 0
for i in l-p:
    ans = min((x-ans, ans), (x-i, i))[1]
print(ans)

Submission status: Wrong Answer

Solution code:
a, b= map(int, input().split())
lista= [int (x) for x in input().split()]

for i in range(200):
    if a-i not in lista:
        print(a-1)
        exit()
    elif a+i not in lista:
        print(a+1)
        exit()

Submission status: Wrong Answer

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

if N == 100:
    input()
    print(X)
    exit(0)
else:
    p = list(map(int, input().split()))
    for i in range(10000):
        if X - i not in p:
            print(X - i)
            exit(0)
        elif X + i not in p:
            print(X + i)
            exit(0)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
A = [map(int, input().split())]
a = 0
while True:
  if X-a not in A:
      print(X-a)
      break
  if X+a not in A:
      print(X+a)
      break
  a += 1

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import os
from sys import stdin
import bisect

def solve(tc):
    x, n = map(int, stdin.readline().split())
    if n==0:
        print(x)
        return

    seq = list(map(int, stdin.readline().split()))
    cand = list()
    for i in range(101):
        if i+1 not in seq:
            cand.append(i+1)
    k = bisect.bisect_left(cand, x)
    ans = cand[k]
    if k>0 and x-cand[k-1]<=cand[k]-x:
        ans = cand[k-1]
    print(ans)


tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1

Submission status: Wrong Answer

Solution code:
import bisect
X,N=map(int,input().split())
P=list(map(int,input().split()))
hako=set(P)
P.sort()
kari=[]
if len(P)==0:
    print(100)
    exit()
if X<P[0]:
    print(X)
    exit()
if X>P[-1]:
    print(X)
    exit()
for i in range(103):
    if i not in hako:
        kari.append(i)
#print(kari)
tekitpu=kari[bisect.bisect_left(kari,X)]
aho=kari[bisect.bisect_left(kari,X)-1]
#print(tekitpu,aho)
if abs(tekitpu-X)<abs(X-aho):
    print(tekitpu)
else:
    print(aho)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import os
from sys import stdin
import bisect

def solve(tc):
    x, n = map(int, stdin.readline().split())
    if n==0:
        print(x)
        return

    seq = list(map(int, stdin.readline().split()))
    cand = list()
    for i in range(100):
        if i+1 not in seq:
            cand.append(i+1)
    k = bisect.bisect_left(cand, x)
    if k==len(cand):
        ans = x
    else:
        ans = cand[k]
        if k>0 and x-cand[k-1]<=cand[k]-x:
            ans = cand[k-1]
    print(ans)


tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1

Submission status: Wrong Answer

Solution code:
def findRightNumbers(integer,intArray):
    expectedRight=expectedLeft=integer
    for number in intArray[intArray.index(integer) :]:
        if number == expectedRight:
            expectedRight += 1
        else:
            break
    for number in (list(reversed(intArray[:intArray.index(integer)+1]))):
        if number == expectedLeft:
            expectedLeft -= 1
        else:
            break
    return [expectedLeft,expectedRight]

integer,size= map(int,input().split())
if size>0:
    intArray=sorted(list(map(int, input().split())))
    if integer in intArray:
        right,left=findRightNumbers(integer, intArray)
        differenceRight=abs(integer-right)
        differenceLeft=abs(integer-left)
        if differenceLeft==differenceRight or differenceLeft<differenceRight: print(left)
        else:print(right)
    else:print(integer)
else: print(integer)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import os
from sys import stdin
import bisect


def solve(tc):
    x, n = map(int, stdin.readline().split())
    if n==0:
        print(x)
        return

    seq = set()
    map(lambda x : seq.add(int(x)), stdin.readline().split())

    cand = list()
    for i in range(100):
        if i+1 not in seq:
            cand.append(i+1)
    k = bisect.bisect_left(cand, x)
    if k==len(cand):
        ans = x
    else:
        ans = cand[k]
        if k>0 and x-cand[k-1]<=cand[k]-x:
            ans = cand[k-1]
    print(ans)


tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1

Submission status: Wrong Answer

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

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

p_list = [0]*100

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

# print(p_list)
dis = 100
index = -1
for i, j in enumerate(p_list):
    if j == 1:
        continue
    # print(i+1, abs(x-(i+1)))
    if dis > abs(x-(i+1)):
        dis = abs(x-(i+1))
        index = i+1
        # index=i
if index == -1:
    if x >= 51:
        index = 101
    else:
        index = 0
print(index)

Submission status: Wrong Answer

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

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

p_list = [0]*100

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

# print(p_list)
dis = 100
index = -1
for i, j in enumerate(p_list):
    if j == 1:
        continue
    # print(i+1, abs(x-(i+1)))
    if dis > abs(x-(i+1)):
        dis = abs(x-(i+1))
        index = i+1
        # index=i
if index == -1:
    if x > 51:
        index = 101
    else:
        index = 0
print(index)