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: Runtime Error

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

pl=[]
if n==0:
    print(x)
else:
    for i in range(n):
        pl.append(abs(p[i]-x))
    sort_p=sorted(pl)
    #print(sort_p)
    if n==1:
        if sort_p[0]!=0:
            print(x)
        else:
            print(x-1)
    else:
        num=0
        for i in range(1,n):
            if i%2!=0:
                num+=1
            if sort_p[i]!=num:
                ans=num
                break
        small=x-ans
        big=x+ans
        if (small not in p)&(big not in p):
            print(small)
        elif small in p:
            print(big)
        elif big in p:
            print(small)

Submission status: Runtime Error

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

if n ==0:
  print(x)
  
if x not in i:
  print(x)
  
  else:
    p = 1
    while True:
      z = x - p
      if z not in i:
        print(z)
        break
        
      z = x + p
      if z not in i:
        print(z)
        break
        
      p = p +1

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
x, N = map(int, input().split())

if N != 0:
    num_list = list(map(int, input().split()))

min_abs = 100
min_num = 0

for num in range(1, 101):
    if not num_list:
        min_num = x
        break
    if num in num_list:
        continue
    else:
        b = abs(num-x)
        if b < min_abs:
            min_abs = b
            min_num = num
            
print(min_num)

Submission status: Runtime Error

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

result = 0
if N == 0:
    result = X
else:
    list = [i for i in range(101)]
    for i in P:
        list.remove(i)
    for i in range(len(list)):
        list[i] = abs(list[i] - X)
    list.sort()
    if list[0] == list[1]:
        result = X - list[0]
    else:
        result = X + list[0]
print(result)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

P = list(map(int, input().split()))
minmin = []
minn = 101
for i in range(1, 101):
    if i in P:
        continue
    abs1 = abs(i - X)
    if minn >= abs1:
        minn = abs1
        minmin.append(i)

if len(minmin) > 2 and abs(X - minmin[-1]) == abs(X - minmin[-2]):
    print(minmin[-2])
    exit()
print(minmin[-1])

Submission status: Runtime Error

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

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    d = []
    c=0
    for e in p:
        d.append( abs(e-x))
    d1 = d[0]
    for i in range(len(d)):
        if d[i] < d1:
            d1 = d[i]
            z = p[i]
    for j in range(1,100):
        for g in p:
            if z+j != g:
                c +=1
                w1 = z+j
        if c == n:
            break
        c = 0
    c=0
    for j in range(1,100):
        for g in p:
            if z-j != g:
                c +=1
                w2 = z-j
        if c == n:
            break
        c = 0

    if w2 < 0:
        print(w1)
    elif abs(w1-x) < abs(w2-x):
        print(w1)
    elif abs(w1-x) >= abs(w2-x):
        print(w2)

Submission status: Runtime Error

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

ans = 101
ls = []

if N == 0:
    print(X)
else:
    for i in range(1, 100):
        if i not in p:
            ls.append(i)
    ls.append(X)
    ls = sorted(ls)
    for i in range(len(ls)):
        if ls[i] == X:
            if X - ls[i - 1] <= ls[i + 1] - X:
                print(ls[i - 1])
                break
            else:
                print(ls[i + 1])
                break

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect_right
def main():
    x,n=map(int,input().split())
    if n==0:
        print(x)
        sys.exit()
    P=list(map(int,input().split()))
    set_P=set(range(101))
    set_P-=set(P)
    P=list(set_P)
    P.sort()
    for p in P:
        if p>=x:
            P_right=p
            break
        P_left=p
    if abs(P_left-x)<=abs(P_right-x):
        print(P_left)
    else:
        print(P_right)

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
x,n = map(int, input().split())
a = []
for i in range(n):
    a.append(input())
c = -1
b = 0
d = 101
e = 0
for w in range(103):
  if c not in a:
    b = abs(x - c)
    if b < d:
      d = b
      e = c
      c += 1
    else:
      c += 1
  else:
    c += 1
print(e)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
if n == 0:
    print(x)
    exit()
lst = [int(i) for i in input().split()]
n_lst = [int(i) for i in range(1,101)]

for i in range(x-1,99):
    if not(n_lst[i] in lst):
        mn1 = n_lst[i]
        break
n_lst = n_lst[::-1]
for i in range(100 - x, 99):
    if not(n_lst[i] in lst):
        mn2 = n_lst[i]
        break
if mn1-x >= mn2-x:
    print(mn2)
else:
    print(mn1)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math
from collections import deque
from collections import defaultdict
from math import gcd


def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    P = np.array(P)
    
    P = np.sort(P)
    ind = bisect.bisect_right(P, X)

    if len(P) == 0 or P[ind-1] != X:
        return X
    
    if len(P) == 1:
        if P[0] != X:
            return X
        else:
            return X-1
    
    Left = P[:ind-1] - X
    Right = P[ind:] - X

    Left = abs(Left[::-1])
    diff = 1
    Left_over = False
    Right_over = False
    while True:
        if not Left_over and Left[0] != diff:
            return X - diff
        elif Left_over:
            return P[0] - 1
        elif not Right_over and Right[0] != diff:
            return X + diff
        elif Right_over:
            return P[-1] + 1
        diff += 1
        if len(Left) >= 2:
            Left = Left[1:]
        else:
            Left_over = True
        if len(Right) >= 2:
            Right = Right[1:]
        else:
            Right_over = True

        if Left_over and Right_over:
            return P[0]-1


print(main())

Submission status: Runtime Error

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

Submission status: Runtime Error

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


def main():
    x, n = [int(i) for i in input().split()]
    p = set([int(i) for i in input().split()])

    for i in range(1, 101):
        if i in p:
            continue

        if i <= x:
            ans = i
        elif x - ans > i - x:
            ans = i
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

not_p_list = list(set(all_list)-set(p_list))
ans_list = []

for i in not_p_list:
    j = abs(i - X)
    ans_list.append(j)

# print(ans_list)

ans = min(ans_list)
minus_ans = -1 * ans

#print(ans, minus_ans)

if (minus_ans + X) in not_p_list:
    print(minus_ans + X)
else:
    print(ans + X)

Submission status: Runtime Error

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 x - i != p[y - i]:
            print(x - i)
            break
        if x + i != p[y + i]:
            print(x + i)
            break
        i = i + 1

Submission status: Runtime Error

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

A = [0]*101
for i in P:
    A[i] = 1

if A[X] == 0:
    print(X)
    exit()

count = 1
while(1):
    if (X - count) <= 101 and (X - count) >= 0:
        if A[X - count] == 0:
            print(X - count)
            exit()

    if count > 0:
        count = -count
    else:
        count = -count
        count += 1

Submission status: Runtime Error

Solution code:
import numpy as np

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

if N == 0:
    print(X)
else:
    A = [i for i in range(1,101)]

    for i in P:
        A.remove(i)

    a = (np.array(A) - X)**2
    j = np.argmin(a)
    print(A[j])

Submission status: Runtime Error

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
m = float("inf")
if x<int(p[0]) or int(p[n-1])<x:
  print(x)
else:
  for y in [y for y in range(p[0]-1,p[n-1]) if not y in p]:
    if abs(x-y)<m:
      m = abs(x-y)
      ans_y = y
  print(ans_y)

Submission status: Runtime Error

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

flags = [True] * N

count = 0
for i in range(N):
    if flags[i]:
        for j in range(i+1, N):
            if A[j] % A[i] == 0:
                flags[j] = False
            if A[j] == A[i]:
                flags[i] = False
        if flags[i]:
            count += 1
print(count)

Submission status: Runtime Error

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

if N == 0:
  print(X)
  exit()
  
p = list(map(int, input().split()))
m = [i for i in range(0, 101)]
for n in p:
  m.remove(n)
m.append(X)
m.sort()
i = m.index(X)
mi = len(m)
if i == 0:
  print(m[1])
  exit()
elif i == mi:
  print(m[mi - 1])
else:
  l = m[i + 1]
  r = m[i - 1]
  dl = abs(X - l)
  dr = abs(X - r)
  if dr <= dl:
    print(r)
  else:
    print(l)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    if x in p:
        for i in range(-1000, 1001):
            print(i)
            if i == -100:
                mini = i
            if i in p:
                pass
            else:
                if abs(x - mini) > abs(x - i):
                    mini = i
                elif abs(x - mini) == abs(x - i):
                    mini = min(mini, i)
        else:
            print(mini)
    else:
        print(x)
else:
    print(x)

Submission status: Runtime Error

Solution code:
import math

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

p.sort()
pnt_big = 0
pnt_small = 0
for i in range(100):
    if p.count(x+i) == 0:
        ans_big = x+i
        pnt_big = 1
    if p.count(x-i) == 0:
        ans_small = x-i
        pnt_small = 1
    if pnt_small == 1 or pnt_big == 1:
        break

if pnt_big == pnt_small:
    print(ans_small)
else:
    print(ans_big)

Submission status: Runtime Error

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(203, dtype = np.int)
a[p+103] = 0
m = X
n = 0
for i in range(203):
    if a[i] == 1:
        if m>abs(i-X-103):
            if i-X-103 != 0:
                m = abs(i-X-103)
                n = i-103
print(n)

Submission status: Runtime Error

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

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

for i in range(50):
    up = X+i
    down = X-i
    if lis[down-1] == 1:
        print(down)
        exit()
    elif lis[up-1] == 1:
        print(up)
        exit()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
x, n = map(int, input().split())
aa = 0
if n == 0:
  aa = 1
if aa == 0:
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    flg = 0
    dis = []
    while flg == 0:
        if i > 100:
            flg = 1
        if i in p:
            dis.append(5000)
        else:
            dis.append(abs(x-i))
        i += 1
    for i in dis:
        if dis[i] == min(dis):
            print(i)
            break
else:
    print(x)

Submission status: Runtime Error

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:
  for A in aa:
    eee = abs(x-A)
    bb.append(eee)

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
x,n = map(int, input().split())
if n > 0:
    p = list(map(int , input().split()))
else:
    p  = []
a = list(set(list(range(1,101))) - set(p))
values = []
for i in a:
    values = values +  [[abs(x-i), i]]
values.sort(key=lambda x: x[0])
mins = values[0][0]
b = []
for i in values:
    if i[0] > mins:
        break
    b += [i[1]]
b.sort()
print(b[0])

Submission status: Runtime Error

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 = 100
ans=[]
ans0 = 100
 
for i in range(N):
  diff0 = abs(p[i]-X)
  if diff0 < diff:
    diff = diff0
for i in range(N):
  if abs(p[i]-X)==diff
  ans.append(p[i])
if int(len(ans)) > 1:
  for i in range(int(len(ans))):
    if ans[i] < ans0:
      ans0 = ans[i]
else:
  ans0 = ans[0]
print(ans0)

Submission status: Runtime Error

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 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)
      
        
    
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: Runtime Error

Solution code:
#C
X,N = map(int,input().split())
p = list(map(int,input().split()))
r = 100
for i in range(100,min(min(p)-2,-1),-1):
    if i in p:
        pass
    else:
        if abs(r-X) >= abs(i-X):
            r = i
        else:
            pass
print(r)

Submission status: Runtime Error

Solution code:
import numpy as np
X,N = map(int, input().split())
p = list(map(int, input().split()))
all_num = list(range(1,101))

mi = 1000
for i in p:
    all_num.remove(i)

least = []
for i in all_num:
    if abs(X-i) < mi:
        least = []
        mi = abs(X-i)
        least.append(i)
    elif abs(X-i) == mi:
        least.append(i)
if len(least) >=0:
    print(sorted(least)[0])
else:
    print()

Submission status: Runtime Error

Solution code:
x,n = map(int, input().split())
a = []
for i in range(n):
    a.append(input())
c = -1
b = 0
d = 101
e = 0
for w in range(103):
  if c not in a:
	b = abs(x - c)
    if b < d:
      d = b
      e = c
      c += 1
    else:
      c += 1
  else:
    c += 1
print(e)

Submission status: Runtime Error

Solution code:
import numpy as np
oin = input()
x, n = int(oin.split(" ")[0]), int(oin.split(" ")[1])
p = input().split(" ")
xpo = x+1
xdetect = list(range(1, 101))
if n == 0:
  print(x)
if x == 1:
  print(0)
def closest(lst, K): 
     lst = np.asarray(lst) 
     idx = (np.abs(lst - K)).argmin()
     return lst[idx]
for b in p:
  try:
    xdetect.remove(int(b))
  except ValueError:
    continue
print(closest(xdetect, x))

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  p.sort()
  p1 = {i for i in range(p[0],p[-1]+1)}
  p = set(p)
  p2 = p1 - p
  p2 = list(p2)
  absv = x
  for i in range(len(p2)):
    if absv > abs(x - p2[i]):
      absv = abs(x - p2[i])
      value = x - p2[i]
  print(x - value)

Submission status: Runtime Error

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

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

for i in range(50):
    up = X+i
    down = X-i
    if lis[down-1] == 1:
        print(down)
        exit()
    elif lis[up-1] == 1:
        print(up)
        exit()

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
try:
    p=list(map(int,input().split()))
    p.sort()
    min=abs(p[n-1])
    for i in range(p[0]-2*x,p[n-1]):
        if i not in p:
            if min>abs(i-x):
                min=abs(i-x)
                ans=i
except:
    ans=x

print(ans)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split(" "))
if(n==0):
    print(x)
else:
    a=list(map(int,input().split(" ")))
    a.sort()
    c=a.index(x)
    for i in range(1,n):
        if(c-i<0):
            print(x-i)
            break
        else:
            if(a[c-i]!=x-i):
                print(x-i)
                break
        if(c+i==n):
            print(x+i)
            break
        else:
            if(a[c+i]!=x+i):
                print(x+i)
                break

Submission status: Runtime Error

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

  dtmp=100
  for i in range(1,101):
    continueflag=0
    for j in a:
      if j==i:
        continueflag=1
        break
    if continueflag==1:
      continue
    d=abs(x-i)
    if d<dtmp:
      dtmp=d
      ans=i

  print(ans)

Submission status: Runtime Error

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
X,N = (int(i) for i in input().split())
if N !=0:
    p = list(map(int, input().split()))
else:
    p=[-1]
#
ans =[]
for i in range(1,101):
    if i not in p:
        ans.append((abs(i-X),i))
ans.sort()
print(ans[0][1])
aa=0

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int X,N; cin >>X >>N;
  if (N==0) {cout <<X <<endl; return 0;}
  vector<int> p(N);
  rep(i,0,N) cin >>p[i];
  sort(p.begin(),p.end());
  int ans=0;
  int check=INT_MAX;
  rep_eq(i,p[0],p[N-1]) {
    bool check_flag=true;
    rep(j,0,N) {
      if (i==p[j]) {check_flag=false; break;}
    }
    if (check_flag) {
      if (abs(X-i)<check) {check=abs(X-i); ans=i;}
    }
  }
  cout <<ans <<endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np


def getNearestValue(li, num):
    idx = np.abs(np.array(li) - num).argmin()
    return li[idx]


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


ans = 0
print(p)
i = 0
while True:
    mi = getNearestValue(p, x - i)
    ma = getNearestValue(p, x + i)
    if mi or ma:
        break
    i += 1

print(mi if mi < ma else ma)

Submission status: Runtime Error

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

table = [0 for i in range(100)]
for i in p:
    table[i-1] = 1

mx = 10000
ans = mx
dis = mx
for i in range(len(table)):
    idx = 99-i
    if (table[idx] == 0) and (dis >= abs(idx+1-x)):
        ans = idx+1
        dis = abs(idx+1-x)
if ans == mx:
    if 50 >= x
        print(0)
    else:
        print(101)
else:
    print(ans)

Submission status: Runtime Error

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

not_p_list = list(set(all_list)-set(p_list))
ans_list = []

for i in not_p_list:
    j = abs(i - X)
    ans_list.append(j)

# print(ans_list)

ans = min(ans_list)
minus_ans = -1 * ans

print(ans, minus_ans)

if (minus_ans + X) in not_p_list:
    print(minus_ans + X)
else:
    print(ans + X)

Submission status: Runtime Error

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

  dtmp=100
  for i in range(1,100):
    continueflag=0
    for j in a:
      if j==i:
        continueflag=1
        break
    if continueflag==1:
      continue
    d=abs(x-i)
    if d<dtmp:
      dtmp=d
      ans=i

  print(ans)

Submission status: Runtime Error

Solution code:
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
if n == 0:
    ans = x
else:
    p = sorted(p)
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = 0
    if x < min_p:
        ans = x
    elif x > max_p:
        ans = x
    elif x == min_p:
        if min_p+1 == p[1]:
            ans = min_p-1
        else:
            ans = min_p+1
    elif x == max_p:
        if max_p-1 == p[len(p)-2]:
            ans = max_p+1
        else:
            ans = max_p-1
    else:
        for i in range(min_p+1, max_p):
            if i == p[j+1]:
                j += 1
            else:
                if abs(ans-x) > abs(i-x):
                    ans = i
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

x,n = I2()
if n != 0:
    p = Intl()
else:
    p = []
p.sort()
if not x in p:
    print(x)
else:
    b,e = 0,n-1
    for i in range(n):
        if p[i] == x:
            b = max(b,i-1)
            e = min(e,i+1)
            break
    #print(b,e)
    r = []
    s = []
    for i in range(p[b]-1,p[e]+2):
        if i not in p:
            r.append(i)
            s.append(abs(x-i))
    print(r[s.index(min(s))])

Submission status: Runtime Error

Solution code:
import numpy as np
X,N = map(int, input().split())
p = list(map(int, input().split()))
all_num = list(range(1,101))

mi = 1000
for i in p:
    all_num.remove(i)

least = []
for i in all_num:
    if abs(X-i) < mi:
        least = []
        mi = abs(X-i)
        least.append(i)
    elif abs(X-i) == mi:
        least.append(i)
print(sorted(least)[0])

Submission status: Runtime Error

Solution code:
P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if x>=len(P):
    print(X)
    sys.exit()
if P[x]!=X:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)

    if x1<len(P) and P[x1]!=A:
        print(A)
        break
        
    if x2<len(P) and P[x2]!=B:
        print(B)
        break

Submission status: Runtime Error

Solution code:
import math

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

p.sort()
pnt_big = 0
pnt_small = 0
for i in range(x+1):
    if p.count(x+i) == 0:
        ans_big = x+i
        pnt_big = 1
    if p.count(x-i) == 0:
        ans_small = x-i
        pnt_small = 1
    if pnt_small == 1 or pnt_big == 1:
        break

if pnt_big == pnt_small:
    print(ans_small)
else:
    print(ans_big)

Submission status: Runtime Error

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

for i in range(1,101):
    if (i in p):
        continue
    else:
        tmp=(x-i)**2
        if tmp<ans:
            ans=tmp
            c=i
print(c)

Submission status: Runtime Error

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

L = list(range(1,101))
if y != 0:
    L2 = list(map(int,input().split()))
    
    #print(L)
    for i in range(len(L2)):
        L.remove(L2[i])
        
#print(L)
#L = sorted(L)

#print(L)

t = len(L)//2

for j in range(len(L)):
#    print(t,L[t])
    if L[t] >= x:
#        print("L[t] >= x")
        if t == 0:
            print(L[t])
            break
        elif L[t-1] <= x:
            if abs(L[t]-x) < abs(L[t-1]-x):
                print(L[t])
                break
            else:
                print(L[t-1])
                break
        
        t = t//2
    else:
        if t == y-1:
            print(L[t])
            break
        elif L[t+1] >= x:
            if abs(L[t]-x) > abs(L[t+1]-x):
                print(L[t+1])
                break
            else:
                print(L[t])
                break
        t = t + (len(L)-t)//2

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
num_list = list(map(int, input().split()))
dif = 101
o_list = []
num_list.sort(reverse=True)

if len(num_list) == 0:
    print(x)
    exit()
#
# for i in range(1, max(num_list)):
#     if i not in num_list:
#         o_list.append(i)

for i in range(1, 101):
    if i not in num_list:
        o_list.append(i)

o_list.sort(reverse=True)

for num in o_list:
    if abs(x - num) <= dif:
        # if x not in num_list:
        dif = abs(x -num)
        ans = num

print(ans)

Submission status: Runtime Error

Solution code:
k,n=map(int,input().split())
if n==0:
    print(0)
else:
    l=list(map(int,input().split()))
    l.sort()
    k1=[i for i in range(min(l),max(l)+1) if i not in l]
    d={}
    for i in range(len(k1)):
        d[k1[i]]=abs(k1[i]-k)
    k2=min(d,key=d.get)
    print(k2)

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
nump = list(map(int,input().split()))
nump.sort()
x_ind = -1
nump_io = [0]*100
for i in range(n):
    nump_io[nump[i]-1] = 1
    if(nump[i]==x):
        x_ind = i
if(x_ind == -1):
    print(x)
else:            
    for i in range(1,50):
        if(nump_io[(x-1)-i] == 0):
            print(x-i)
            break
        if(nump_io[(x-1)+i] == 0):
            print(x+i)
            break

Submission status: Runtime Error

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

p.sort()
P = p[-1]
li_p = []
for i in range(1,P+1):
    count = 0
    for j in range(n):
        if i != p[j]:
            count += 1
    if count == n:
        li_p.append(i)
    
d = abs(li_p[0] - x)
ans = li_p[0]
for i in range(1, len(li_p) - 1):
    if abs(li_p[i] - x) < d:
        ans = li_p[i]
    else:
        break
print(ans)

Submission status: Runtime Error

Solution code:
x, n = gets.split(' ').map(&:to_i)
p = gets.chomp.split(' ').map(&:to_i)

q = p.map { |n| (n - x) }
ans = 0
(0..100).each { |i|
        if q.include?(i)
                if q.include?(-1 * i)
                        next
                else
                        ans = x - i
                        break
                end
        elsif q.include?(-1 * i)
                ans = x + i
                break
        else
                ans = x - i
                break
        end
}

puts ans

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline

def main():
    x, n = map(int, input().rstrip().split())
    if n == 0:
        print(x)
        sys.exit()
    else:
        p = list(map(int, input().rstrip().split()))
        if x > max(p):
            print(x)
            sys.exit()
        else:
            p_x = set(range(min(p), max(p)+1))
            p_temp = set(p)
            p_diff = p_x - p_temp
            p_temp = list(p_diff).sort()
            p_dir = []

        for i in range(len(p_temp)):
            p_dir.append(abs(p_temp[i] - x))
        print(p_temp[p_dir.index(min(p_dir))])
  
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  p.sort()
  p1 = {i for i in range(p[-1])}
  p = set(p)
  p2 = p1 - p
  p2 = list(p2)
  absv = x
  for i in range(len(p2)):
    if absv > abs(x - p2[i]):
      absv = abs(x - p2[i])
      value = x - p2[i]
  print(x - value)

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
if N>0:
    p=list(map(int,input().split()))
else:
    print(X)
    exit()
l=[]
for i in range(1,101):
    l.append(i)
for i in p:
    if i in l:
        l.pop(l.index(i))
L=list(map(lambda x:abs(X-x), l))
m=min(L)
if X-m in l:
    print(X-m)
else:
    print(X+m)

Submission status: Runtime Error

Solution code:
import bisect

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

p.sort()

index = bisect.bisect_left(p,x)

if n==0:
    print(x)
else:
    for i in range(n):
        # print(index-i, index+i)
        if p[index-i] != x-i:
            print(x-i)
            break
        elif p[index+i] != x+i:
            print(x+i)
            break

Submission status: Runtime Error

Solution code:
X,N = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
nlist = [0 for i in range(100)] 
for i in p:
    nlist[i-1]=1
for i in range(max(X+1,100-X+1)):
    
    if X-i-1>=0:
        if nlist[X-i-1] == 0:
            result = X-i
            break
    if X+i-1<=99:
        if nlist[X+i-1] == 0:
            result = X+i
            break
print(result)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
if(n!=0):
    a = list(map(int,input().split()))
flag=True
k = 0

while(True):
    b = x - k
    c = x + k
    if(not(b in a)):
        print(b)
        break
    elif(not(c in a)):
        print(c)
        break
    k = k + 1