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())
if n!=0:
    p=list(map(int,input().split()))
    dif=1000
    ans=-1
    for i in range(1,101):
        if i not in p:
            if abs(x-i)<dif:
                ans=i
                dif=abs(x-i)
    print(ans)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    X, N = ZZ()
    P = set(ZZ())
    sa, ans = 200, -1
    for i in range(101):
        if i in P: continue
        if abs(X-i) < sa:
            sa = abs(X-i)
            ans = i
    print(ans)

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, N = MAP()
p = LIST()

s = set(p)

mi = INF
ans = None
for i in range(-1, 101):
	if i in s:
		continue
	if abs(X-i) < mi:
		mi = abs(X-i)
		ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    X, N = map(int, rl().split())
    p = set(map(int, rl().split()))
    
    ans = -1
    d_min = 1000
    for i in range(101):
        if i not in p:
            if abs(X - i) < d_min:
                d_min = abs(X - i)
                ans = i
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
def main():

    X, N = map(int, input().split())
    if N == 0: return X
    p = list(map(int, input().split()))

    p = set(p)
    ans = 1
    l = float('inf')
    for i in range(1, 102):
        if i not in p and abs(i-X) < l:
            l = abs(i-X)
            ans = i
    return ans



if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

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

res = 10000

for i in range(-100, 101):
    if i in P:
        continue

    if abs(res - X) >= abs(X - i):
        if abs(res - X) == abs(X - i):
            res = min(i, res)
        else:
            res = i

print(res)

Submission status: Wrong Answer

Solution code:
def examA():
    X = LI()
    for i in range(len(X)):
        if X[i]==0:
            ans = i+1
    print(ans)
    return

def examB():
    X, Y = LI()
    ans = "No"
    for i in range(X+1):
        if i*2+(X-i)*4==Y:
            ans = "Yes"
    print(ans)
    return

def examC():
    X, N = LI()
    P = LI()
    P = set(P)
    cur = inf
    ans = -1
    for i in range(1,101):
        if i in P:
            continue
        now = abs(i-X)
        if now<cur:
            ans = i
            cur = now
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Wrong Answer

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

diff = 1e9
ans = -1
for i in range(1,101):
    if i not in arr:
        d = abs(x-i)
        if d < diff:
            diff = d
            ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
a=[999]*101
for i in range(101):
    if i not in p:
        a[i]=abs(x-i)
print(a.index(min(a)))

Submission status: Wrong Answer

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
x,n=map(int,input().split())
P=set([int(i) for i in input().split()])
ans=0
for i in range(1,101):
  if i in P:
    continue
  else:
    if abs(i-x)<abs(ans-x):
      ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p=set(list(map(int,input().split())))
val=10**20
ans=-1
for i in range(1,102):
    if i not in p:
        if val>abs(X-i):
            val=abs(X-i)
            ans=i

print(ans)

Submission status: Wrong Answer

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

res, diff = 0, float("inf")
for i in range(0, 101):
    if i in P:
        continue
    if diff > abs(X - i):
        res = i
        diff = abs(X - i)

print(res)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
lis = list(map(int,input().split()))
ans = 100000000000
for i in range(0,102):
  if i not in lis:
    ans = min(ans,abs(i-n))
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    val = 1000
    ans = -1
    for x in range(0, 101):
        if x in P:
            continue
        if abs(X - x) < val:
            ans = x
            val = abs(X - x)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


ans = 0
check = 100000000000000000000000
for i in range(1,101):
    if i in p:pass
    else:
        if check > abs(x-i):
            ans = i
            check = abs(x-i)
print(ans)

Submission status: Time Limit Exceeded

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

i = 0

if X not in p:
  print(X)

else:
  while True:
    i += 1
    if X - i not in p:
      print(X-i)
    if X+i not in p:
      print(X+i)

Submission status: Time Limit Exceeded

Solution code:
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
plus_flag = 1
minus_flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
plus_index = key_index
minus_index = key_index

if n == 0:
    print(x)
else:
    while(1):
        if minus_index <= 0:
            minus_flag = 0
            
        if minus_flag == 1:
            if pN[minus_index] - 1 != pN[minus_index-1]:
                print(pN[minus_index] - 1)
                break
            else:
                minus_index = minus_index - 1

        

        if plus_index >= n-1:
            plus_flag = 0

        if plus_flag == 1:
            if pN[plus_index] + 1 != pN[plus_index+1]:
                print(pN[plus_index] + 1)
                break
            else:
                plus_index = plus_index + 1

Submission status: Time Limit Exceeded

Solution code:
X, N = map(int, input().split())
if not N == 0:
  p_l = list(map(int, input().split()))
if N == 0:
  print(X)
  exit()
a = b = X
while True:
  if a in p_l and b in p_l:
    continue
  if not a in p_l:
    if not b in p_l:
      if a > b:
        print(b)
        exit()
      else:
        print(a)
        exit()
    print(a)
    exit()
  elif not b in p_l:
    if not a in p_l:
      if a > b:
        print(b)
        exit()
      else:
        print(a)
        exit()
    print(b)
  a += 1
  b -= 1

Submission status: Time Limit Exceeded

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

    if n == 0:
        minimum = x
    else:
        if x not in p_lst:
            minimum = x

        else:
            lst = []
            flag = False

            while True:
                x1 = x
                x2 = x
                x1 += 1
                x2 -= 1

                if x1 not in p_lst:
                    lst.append(x1)
                    flag = True
                if x2 not in p_lst:
                    lst.append(x2)
                    flag = True

                if flag:
                    break

            minimum = min(lst)

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
#from numba import njit

def getVar():
    return map(int, input().split())
def getArray():
    return np.array(list(map(int, input().split())))

(X,N) = getVar()
p = getArray()

if (len(p) == 0):
  print(X)
else:
  subp = p - X
  i = 0
  while (True):
    if (not i in subp):
      break
  print(X - i)

Submission status: Time Limit Exceeded

Solution code:
x, n = map(int,input().split())
lst = set(map(int,input().split()))
df = 0
while True:
    if not (x + df) in lst: print(x + df)
    df = -df
    if not (x + df) in lst: print(x + df)
    df = -df
    df += 1

Submission status: Time Limit Exceeded

Solution code:
X, N = map(int, input().split())
if N == 0:
  print(X)
  exit()
P = list(map(int, input().split()))
 
i = 0
while 1:
  for d in [-1, +1]:
    if not X+i*d in P:
      print(X+i*d)
      break
  i += 1

Submission status: Time Limit Exceeded

Solution code:
x, n = map(int, input().split())
 
if n == 0:
    print(x)
    exit()
 
nums = list(map(int, input().split()))
 
if not nums or x not in nums:
    print(x)
    exit()
 
nums.sort()
 
x_index = nums.index(x)
left_pointer, right_pointer = x_index - 1, x_index + 1
expected_small, expected_big = x - 1, x + 1
 
while True:
    if 0 <= left_pointer < len(nums) and expected_small != nums[left_pointer]:
        print(expected_small)
        exit()
    else:
        expected_small -= 1
        left_pointer -= 1
 
    if 0 <= right_pointer < len(nums) and expected_big != nums[right_pointer]:
        print(expected_big)
        exit()
    else:
        expected_big += 1
        right_pointer += 1

Submission status: Time Limit Exceeded

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

_x = x 
x_ = x
while True:
  if _x not in p:
    print(_x)
    break
    if x_ not in p:
      print(x_)
      break
      _x -= 1
      x_ += 1

Submission status: Time Limit Exceeded

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

_x = x 
x_ = x
while True:
  if _x not in p:
    print(_x)
    break
    if x_ not in p:
      print(x_)
      break
      _x -= 1
      x_ += 1

Submission status: Time Limit Exceeded

Solution code:
X,N = map(int,input().split())
Z = list(str(input()).split())
lists=[]
n=1
if N > 0:
    for i in Z:
        i= int(i)
        lists.append(i)
    while True:
        if X+n not in lists:
            if X-n not in lists:
                print(X-n)
                quit()
            else:
                print(X+n)
                quit()
    n+=1
else:
    print(X)
    quit()

Submission status: Time Limit Exceeded

Solution code:
X,N = map(int,input().split())
Z = list(str(input()).split())
lists=[]
n=1
if N > 0:
    for i in Z:
        i= int(i)
        lists.append(i)
    while True:
        if X+n not in lists:
            if X-n not in lists:
                print(X-n)
                quit()
            else:
                print(X+n)
                quit()
    n+=1
else:
    print(X)

Submission status: Time Limit Exceeded

Solution code:
x,n = map(int,input().split())
p = set(map(int,input().split()))
i = 0
while i <= x:
  if (x-i) in p and (x+i) in p:
    i+=1
  elif (x-i) in p:
    print(x+i)
    break
  elif (x+i) in p:
    print(x-i)
    break
  else :
    print(x-i)

Submission status: Time Limit Exceeded

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

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

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

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

flag_p = True
flag_n = True

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

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

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

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

Submission status: Time Limit Exceeded

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

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

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

if X not in P:
    print(X)

flag_p = True
flag_n = True

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

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

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

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

Submission status: Time Limit Exceeded

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

ans = float('inf')
cont = True
if X in P:
    index = P.index(X)
    i = 1
    while cont:
        if index-i >= 0:
            if P[index-i] != X-i:
                ans = X-i
                cont = False
        if index+i < len(P):
            if P[index+i] != X+i:
                ans = min(ans, X+i)
                cont = False
        i += 1
    print(ans)
else:
    print(X)

Submission status: Time Limit Exceeded

Solution code:
x,y=map(int,input().split())
p=list(map(int,input().split()))
dic={}
for j in p:
    if j in dic:
        dic[j]+=1
    else:
        dic[j]=1
if y==0:
    print(x)
else:
    flag1=flag=0
    left=1
    right=1
    toogle=1
    while(flag==0 or flag1==0):
        if x-left>0:
            if x-left not in dic:
                flag1=1
            else:
                left+=1
        else:
            toogle=0
        if x+right not in dic:
            flag=1
        else:
            right+=1
    if toogle==0:
        print(x+right)
    else:
        if right<left and flag==1:
            print(x+right)
        else:
            print(x-left)

Submission status: Time Limit Exceeded

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

status = False
index = 0
r = float('inf')
for i, p in enumerate(P):
    if p == X:
        status = True
        index = i
        break

ans = float('inf')
cont = True
if status:
    i = 1
    while cont:
        if index-i >= 0:
            if P[index-i] != X-i:
                ans = X-i
                cont = False
        if index+i < len(P):
            if P[index+i] != X+i:
                ans = min(ans, X+i)
                cont = False
        i += 1
    print(ans)
else:
    print(X)

Submission status: Time Limit Exceeded

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

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

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

if not nums or x not in nums:
    print(x)
    exit()

nums.sort()

x_index = nums.index(x)
left_pointer, right_pointer = x_index - 1, x_index + 1
expected_small, expected_big = x - 1, x + 1

while True:
    if 0 <= left_pointer < len(nums) and expected_small != nums[left_pointer]:
        print(expected_small)
        exit()
    else:
        expected_small -= 1
        left_pointer -= 1

    if 0 <= right_pointer < len(nums) and expected_big != nums[right_pointer]:
        print(expected_big)
        exit()
    else:
        expected_big += 1
        right_pointer += 1

Submission status: Time Limit Exceeded

Solution code:
x,y=map(int,input().split())
p=list(map(int,input().split()))
if y==0:
    print(x)
else:
    flag1=flag=0
    left=1
    right=1
    toogle=1
    while(flag==0 or flag1==0):
        if x-left>0:
            if x-left not in p:
                flag1=1
            else:
                left+=1
        else:
            toogle=0
        if x+right not in p:
            flag=1
        else:
            right+=1
    if toogle==0:
        print(x+right)
    else:
        if right<left and flag==1:
            print(x+right)
        else:
            print(x-left)

Submission status: Time Limit Exceeded

Solution code:
x, n = map(int, input().split())
if n==0:
    print(x)
else:
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    while i < n and p[i] < x:
        i += 1

    if p[i] != x:
        print(x)
    else:
        j = 1
        up = x+j
        down = x-j
        while True:
            if i-j>=0 and p[i-j] != x-j:
                print(x-j)
                break
            if i+j<n and p[i+j] != x+j:
                print(x+j)
                break
            j += 1

Submission status: Time Limit Exceeded

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

  flag=0
  i=0
  while flag==0:
    continueflag=0
    for j in a:
      if j==x-i:
        continueflag=1
        break
    if continueflag==0:
      print(x-i)
      break
      
    for j in a:
      if j==x+i:
        continueflag=1
        break
    if continueflag==0:
      print(x+i)
      break
  i=i+1

Submission status: Time Limit Exceeded

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

    p.sort()
    y = 0

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 1
    a = x-1
    b = x+1
    while ans == 0:
      if a < 0:
        a = 0
      if b > N-1:
        b = N-1
      if X-i != P[a]:
        ans = X-i
      elif X+i != P[b]:
        ans = X+i
        a -= 1
      else:
        a -= 1
        b += 1
        i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x, n = [int(x) for x in input().split()]
if n != 0:
    p = sorted([int(x) for x in input().split()])
    if sorted(p) == list(range(min(p), max(p)+1)):
        tn = p[0]
        tp = p[len(p) - 1]
    tn = x
    tp = x
    while True:
        if tn in p or tp in p:
            tn -= 1
            tp += 1
            if tn not in p:
                print(tn)
                break
            elif tp not in p:
                print(tp)
                break
else:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 0
    a = x
    b = x
    while ans == 0:
      if a < 0:
        a = 0
      if b > N-1:
        b = N-1
      if X-i != P[a]:
        ans = X-i
      elif X+i != P[b]:
        ans = X+i
        a -= 1
      else:
        a -= 1
        b += 1
        i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline

x,n=map(int,input().split())
if n==0:
    print(x)
else:
    p=list(map(int,input().split()))
    a=0
    d=0
    while a==0:
        if x-d in p:
            if x+d in p:
                d+=1
            else:
                a=x+d
        else:
            a=x-d
    print(a)

Submission status: Time Limit Exceeded

Solution code:
x, n = [int(x) for x in input().split()]
if n != 0:
    p = sorted([int(x) for x in input().split()])
    tn = x
    tp = x
    while True:
        if tn in p or tp in p:
            tn -= 1
            tp += 1
            if tn not in p:
                print(tn)
                break
            elif tp not in p:
                print(tp)
                break
else:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    p=list(map(int,input().split()))
    a=0
    d=0
    while a==0:
        if x-d in p:
            if x+d in p:
                d+=1
            else:
                a=x+d
        else:
            a=x-d
    print(a)

Submission status: Time Limit Exceeded

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
import math
x, n = map(int, input().split())
p = list(map(int, input().split()))

ans = [0]*100

if n == 0:
    print(x)

else:
    for i in range(100):
        ans[i] = i+1

    sort = sorted(p)
    for i in sort:
        ans.remove(i)

    big = 0
    j = -1
    while(big == 0):
        j = j+1
        big = ans.count(x+j)

    big = x+j

    small = 0
    k =-1
    while(small == 0):
        k = k+1
        small = ans.count(x-k)

    small = x-k

    if abs(x-big) < abs(x-small):
        print(big)
    else:
        print(small)

Submission status: Time Limit Exceeded

Solution code:
x,n = map(int,input().split())
l = [int(x) for x in input().split()]
mp = [False]*101
for i in range(n):
    mp[l[i]] = True



queue = [x]
while(len(queue)>0):
    now = queue.pop(0)
    if(now <= 0 or now >=101):
        print(now)
        break
    if(mp[now]==False):
        print(now)
        break
    
    
    queue.append(now-1)
    queue.append(now+1)

Submission status: Time Limit Exceeded

Solution code:
x,n = map(int,input().split())
P = list(map(int,input().split()))
i = 0
while True:
    ans = x - i
    if ans in P:
        ans = x + i
        if ans in P:
            continue
        else:
            print(ans)
            break
    else:
        print(ans)
        break
    i = i + 1

Submission status: Time Limit Exceeded

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

if N == 0:
    print(X)
else:
    ans = 0
    i = 1

    while ans == 0:
        if not(X - i in P):
            ans = X - i
        elif not(X + i in P):
            ans = X + i
        else:
            i += 1

    print(ans)

Submission status: Time Limit Exceeded

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

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

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

# high
high = 0
tmp = 0
while not high:
    if (X + tmp) in P:
        tmp += 1
        continue
    high = X + tmp

low = 0
tmp = 0
while not low:
    if (X - tmp) in P:
        tmp += 1
        continue
    low = X - tmp

if abs(X - low) == abs(X - high):
    print(low)
elif abs(X - low) < abs(X - high):
    print(low)
else:
    print(high)

Submission status: Time Limit Exceeded

Solution code:
import queue

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

if N!=0:
    p = list(map(int,input().split()))
else:
    p=[]

q = queue.Queue()

q.put(X)

while True:
    t = q.get()
    if t in p:
        q.put(t-1)
        q.put(t+1)
    else:
        print(t)
        break

Submission status: Time Limit Exceeded

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

up = x
down = x
ans = 0
while ans == 0:
    for i in range(n + 1):
        if p.count(down) == 0:
            ans = down
            break
        elif p.count(up) == 0:
            ans = up
            break
        else:
            up += 1
            down -= 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  i = 0
  ans = 0
  while ans == 0:
    if X-i not in P:
      ans = X - i
    elif X+i not in P:
      ans = X+i
    else:
      i += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

if x not in a:
  print(x)
else:
  sa = 1
  while True:
    if x-sa not in a:
      print(x-sa)
      break
    if x+sa not in a:
      print(x+sa)
      break

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

X, N = na()
p = na()
kouho = []
for i in range(-100, 200):
    if i in p:
        continue
    kouho.append((abs(X - i), i))
print(min(kouho)[1])

Submission status: Accepted

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

a = 100
b = 0
for i in range(0, 102):
    if i not in p and abs(x - i) < a:
        a = abs(x - i)
        b = i

print(b)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
l=list(map(int,input().split()))
flag=0
i=0
while flag==0:
    if x-i not in l:
        flag=1
        ansa=x-i
    i+=1
flag=0
i=0
while flag==0:
    if x+i not in l:
        flag=1
        ansb=x+i
    i+=1
if abs(ansa-x)<=abs(ansb-x):
    print(ansa)
else:
    print(ansb)

Submission status: Accepted

Solution code:
import sys

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

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

if x not in p:
    print(x)
    sys.exit()
    
q=list(i for i in range(p[0]-1,p[-1]+2))

for i in p:
    q.remove(i)

ans=[]
c=x+n
for i in q:
    if c>abs(x-i):
        c=abs(x-i)
        ans.clear()
        ans.append(i)
    if c==abs(x-i):
        ans.append(i)

print(min(ans))

Submission status: Accepted

Solution code:

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



result = x
for i in range(100):
    if x in l:
        pass
    else:
        result = x
        break

    if x - i in l:
        pass
    else:
        if x - i >= 0:
            result = x - i
            break

    if x + i in l:
        pass
    else:
        if x + i <= 101:
            result = x + i
            break



print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
temp=100
for i in range(x-51,x+51):
    a=abs(x-i)
    if a<temp and i not in p:
        temp=a
        ans=[i]
    if a==temp and i not in p:
        ans+=[i]
print(min(ans))

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=input()
def ans170(X:int, N:int, p:str):
    p_list=list(map(int,p.split()))
    count=1
    if len(p)==0:
        return X
    elif X not in p_list:
        return X
    else:
        while True:
            if X-count not in p_list:
                return X-count
                break
            elif X+count not in p_list:
                return X+count
                break
            else:
                count+=1
print(ans170(X,N,p))

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
ps = list(map(int, input().split()))
bgr, smr = X, X
while bgr <= 100:
	if bgr not in ps:
		break
	bgr += 1
while smr >= 1:
	if smr not in ps:
		break
	smr -= 1
print(bgr) if bgr - X < X - smr else print(smr)

Submission status: Accepted

Solution code:
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

x, n = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]

tmp = 0
res = 0

P = np.array(P) - x

while True:
    if not -res in P:
        res *= -1
        break
    if not res in P:
        break
    res += 1
res += x

print(res)

Submission status: Accepted

Solution code:
X, N=map(int,input().split())
p=list(map(int,input().split()))
for d in range(X+1):
  for s in [-1,+1]:
    a=X+s*d
    if p.count(a) == 0: 
      print(a)
      exit(0)