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()))
mini = 100
for i in range(1,101):
    if not i in p:
        if mini>abs(x-i):
            ans = i
            mini=abs(x-i)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
X, N=map(int,input().split())
ps=map(int,input().split())

ps_sort=sorted(ps)

ind_crit=N-1
for p in ps_sort:
  if p>=X:
    ind_crit=ps_sort.index(p)
    break
    
if not ps_sort[ind_crit]==X:
  ans=X
else:
  diff=0
  while(True):
    diff+=1
    if not X-diff in ps_sort:
      ans=X-diff
      break
    if not X+diff in ps_sort:
      ans=X+diff
      break

print(ans)

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
n=list(map(int,input().split()))
if X<min(n) or X>max(n):
  print(X)
  exit()

key=min(n)-1
Key=max(n)+1
l=list(range(key,Key+1))
ll=[x for x in l if x not in n]
ll.append(X)
ll.sort()
i=ll.index(X)
if abs(X-ll[i-1])>abs(X-ll[i+1]):
  print(ll[i+1])
else:
  print(ll[i-1])

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
if N >0:
  p = list(map(int,input().split()))
a = 100
ans = []
for i in range(1,101):
  if N == 0:
    ans = X
    break
  if p.count(i) == 0 and a >= abs(X - i):
    a = abs(X - i)
    ans = i
if N > 0:
  for i in range(1,101):
    if abs(X-i) == abs(X-ans) and p.count(i) == 0:
      ans = i
      break
print(ans)

Submission status: Runtime Error

Solution code:
# coding:utf-8
x, n = map(int, input().split())
p = list(map(int, input().split()))


if n == 0:
    print(x)
else:
    ps = sorted(p)
    tmp = [_ for _ in range(ps[0], ps[-1] + 1)]
    ans_list = list(set(tmp) ^ set(ps))
    # print(tmp, ans_list)
    diff = []

    for i in ans_list:
        diff.append(abs(i - x))
    print(ans_list[diff.index(min(diff))])

Submission status: Runtime Error

Solution code:
import numpy as np
X,N = map(int,input().split())
p = list(map(int,input().split()))
p2 = sorted(p)
idx = np.abs(np.asarray(p) - X).argmin()
print(idx+1)

Submission status: Runtime Error

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

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

i = 0
if X not in p:
    r = bisect_left(p, X)
    l = r-1
    if abs(p[l]-X) <= abs(p[r]-X):
        print(p[l])
    else:
        print(p[r])
else:
    i = 1
    while p[p.index(X)] + i in p:
        i += 1
    up = p[p.index(X)] + i
    
    i = 1
    while p[p.index(X)] - i in p:
        i += 1
    down = p[p.index(X)] - i

    if abs(down-X) <= abs(up-X):
        print(down)
    else:
        print(up)

Submission status: Runtime Error

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

p.sort()
tmp = [i for i in range(1, 101)]
for i in p:
        tmp.remove(i)

ans_num = float("Inf")
ans_i = 0
for i in range(len(tmp)):
        if abs(X - tmp[i]) < ans_num:
                ans_num = abs(X - tmp[i])
                ans_i = i

print(tmp[ans_i])

Submission status: Runtime Error

Solution code:
n,m=[int(n) for n in input().split()]
arr=list(map(int,input().strip().split()))
if(m==0):
    print(n)
else:
    j=n
    while(j>=1):
        flag=0
        for i in range(m):
            if(arr[i]==j):
                flag=1
        if(flag==1):
            j=j-1
        else:
            s1=j
            break
    j=n
    while(j<101):
        flag=0
        for i in range(m):
            if(arr[i]==j):
                flag=1
        if(flag==1):
            j=j+1
        else:
            s2=j
            break
    a=abs(n-s1)
    b=abs(n-s2)
    if(a<=b):
        print(s1)
    else:
        print(s2)

Submission status: Runtime Error

Solution code:
x,N=map(int,input().split())
p=list(map(int,input().split()))
p_set=set(p)
flag=0
if x not in p_set:
    ans=x
else:
    count=1
    while flag==0:
        if x+count not in p_set:
            ans=x+count
            flag=1
        if x-count not in p_set:
            ans=min(ans,x-count)
            flag=1
        count+=1
print(ans)

Submission status: Runtime Error

Solution code:
import copy
[x,n] = list(map(int, input().split()))
pList = list(map(int, input().split()))
dict = {1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0,18:0,19:0,20:0,21:0,22:0,23:0,24:0,25:0,26:0,27:0,28:0,29:0,30:0,31:0,32:0,33:0,34:0,35:0,36:0,37:0,38:0,39:0,40:0,41:0,42:0,43:0,44:0,45:0,46:0,47:0,48:0,49:0,50:0,51:0,52:0,53:0,54:0,55:0,56:0,57:0,58:0,59:0,60:0,61:0,62:0,63:0,64:0,65:0,66:0,67:0,68:0,69:0,70:0,71:0,72:0,73:0,74:0,75:0,76:0,77:0,78:0,79:0,80:0,81:0,82:0,83:0,84:0,85:0,86:0,87:0,88:0,89:0,90:0,91:0,92:0,93:0,94:0,95:0,96:0,97:0,98:0,99:0,100:0}
for i in pList:
    dict[i] = 1
goUp = True
goDown = True
run = True
upTar = copy.copy(x)
lowTar = copy.copy(x)
theAns = copy.copy(x)
while run:
    if dict[lowTar] == 0:
        theAns = lowTar
        break
    if dict[upTar] == 0:
        theAns = upTar
        break
    if goUp:
        upTar += 1
    if goDown:
        lowTar -= 1
    if upTar == 100:
        goUp = False
    if lowTar:
        goDown = False
print(theAns)

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(-100,100)]
    for i in P:
        list.remove(i)
    min = 100
    for i in list:
        if min > abs(X-i):
            min = abs(X - i)
            result = i

print(result)

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
P = [int(i) for i in input().split()]
for i in range(1,101):
    if i in P:
        pass
    else:
        if "ans" in locals():
          if abs(X-ans) > abs(X-i):
            ans = i
        else:
            ans = i
print(ans) if N != 0 else print(X)

Submission status: Runtime Error

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

p = []
for i in range(N):
  p.append(int(input()))

# p = list(map(int, input().split(" ")))

go = True
absolute = 1
plus = True

if X not in p:
  print(X)
else:
  while go:
    if plus:
      target = X - absolute
      if target not in p:
        print(target)
        go = False
      plus = False
    else:
      target = X + absolute
      if target not in p:
        print(target)
        go = False
      absolute += 1
      plus = True

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
if N!=0:
    p=list(map(int,input().split()))
    p.sort()
    for i in range(X,101):
        if i not in p:
            min_=i
            dif_min=i-X
            break;
    for i in range(X,0,-1):
        if i not in p:
            max_=i
            dif_max=X-i
            break;
    if dif_max<=dif_min:
          print(max_)
    else:
          print(min_)
else:
    print(X)

Submission status: Runtime Error

Solution code:
from bisect import bisect

X, N = [int(n) for n in input().split()]
if N==0:
    print(X)
else:
    P = sorted([int(n) for n in input().split()])
    idx = bisect(P, X)
    for i in range(P[idx-1], 101):
        if i not in P:
            ans_r = i
            break
    for j in range(1, P[idx-1]):
        if j not in P:
            ans_l = j
    if abs(X-ans_l) == abs(ans_r-X):
        print(min(ans_l, ans_r))
    else:
        print(ans_l if abs(X-ans_l) < abs(ans_r-X) else ans_r)

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
if N >0:
  p = list(map(int,input().split()))
a = 100
ans = []
for i in range(1,101):
  if N == 0:
    ans = X
    break
  if p.count(i) == 0 and a >= abs(X - i):
    a = abs(X - i)
    ans = i
for i in range(1,101):
  if abs(X-i) == abs(X-ans) and p.count(i) == 0:
    ans = i
    break
print(ans)

Submission status: Runtime Error

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

p2 = [i for i in range(1, 101)]
p3 = list(set(p2) - set(p))

minv = 1000
for i in p3:
    if abs(i-x) < minv:
        minv = abs(i-x)
        ans = i

print(ans)

Submission status: Runtime Error

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

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

num=[i for i in range(1,101)]
for i in p:
    num[i-1]=0

num.sort()
while True:
    if num[0]!=0:
        break
    num.pop(0)
# print(num)

min=1000
for i in num:
    if min>abs(x-i):
        min=abs(x-i)
        ans=i
print(ans)

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())
    PP=list(map(int,input().split()))
    P=[]
    cunt=0
    for xx in range(101):
        if xx in PP:continue
        P.append(xx)
        cunt+=1
    P_left=P[max(bisect_left(P,x)-1,0)]
    P_right=P[bisect_left(P,x)]
    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())
p = list(map(int, input().split()))


p.sort()

tmp = [i for i in range(1, 101)]
for i in p:
        tmp.remove(i)


ans_num = float("Inf")
ans_i = 0
for i in range(len(tmp)):
        if abs(X - tmp[i]) < ans_num:
                ans_num = abs(X - tmp[i])
                ans_i = i

print(tmp[ans_i])

Submission status: Runtime Error

Solution code:
import sys
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit(1)
p = [int(x) for x in input().split()]
k = 0
while x in p:
    if not x - k in p:
        print(x - k)
        exit(1)
    elif not x + k in p:
        print(x + k)
        exit(1)
    else:
        k += 1
        continue
print(x)

Submission status: Runtime Error

Solution code:
x,n= list(map(int, input().split()))
p = list(map(int, input().split())) 
import numpy as np
def getNearestValue(list, num):
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
if x not in p:
    print(x)
else:
    t = [i for i in range(100)]
    for i in range(n):    
        t.remove(p[i])
    print(getNearestValue(t, x))

Submission status: Runtime Error

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

x = a[0]
n = a[1]
d = list(map(int,input().split()))

if (n == 0):
    print(x)
else:
    min_int = d[np.argmin(d)]
    max_int = d[np.argmax(d)]

    p = []
    for var in range(min_int,max_int):
        if var not in d:
            p.append(var)
        else:
            continue




    ans = []

    for pp in p:
        ans.append(np.abs(pp - x))
    ans = np.array(ans)
    print(p[np.argmin(ans)])

Submission status: Runtime Error

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
mini = 100
for i in range(101):
    if not i in p:
        if mini>abs(x-i) and i!=0:
            ans = i
            mini=abs(x-i)
print(ans)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
if n!=0:
  p=list(int(i) for i in input().split())

  for i in range(100):
    kouho1=x+i
    kouho2=x-i
    if kouho2 not in p:
      print(kouho2)
      break
    elif kouho1 not in p:
      print(kouho1)
      breaak
else:
  print(x)

Submission status: Runtime Error

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

diff_1 = abs(X-p[-1])
diff_2 = abs(X-p[1])
diff = max(diff_1,diff_2)

for x in range(1,diff+1):
	if X+x not in p:
		ans.append(X+x)
		
	if X-x not in p:
		ans.append(X-x)

ans.sort()
print(ans[1])

Submission status: Runtime Error

Solution code:
need, lens = [int(x) for x in input().split()]
if lens == 0:
    print(need)
else:
    arrs = [int(x) for x in input().split()]
    left = [x for x in list(range(min(arrs), max(arrs) + 1)) if x not in arrs]
    diffs = 1000000
    value = left[0]
    for i in left:
        diff = abs(i - need)
        if diff < diffs:
            diffs = diff
            value = i
    print(value)

Submission status: Runtime Error

Solution code:
import numpy as np

def resolve():
    import sys
    input = sys.stdin.readline
    xn = [int(x) for x in input().rstrip().split()]
    x = xn[0]
    n = xn[1]
	
    if n == 0:
      print(x)
      exit()
    
    p = [int(x) for x in input().rstrip().split()]
    num_list = [i for i in range(1, 101) if not i in p]

    idx = np.abs(np.asarray(num_list) - x).argmin()
    print(num_list[idx])



# x = list(map(int, input().split()))

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
if(n!=0):
    a=list(map(int,input().split()))
else:
    a=[]
if not x in a:
    print(x)
else:
    a.sort()
    i=a.index(x)-1
    j=i+2
    d=1
    ans=0
    while(True):
        if(a[i]!=x-d):
            ans=a[i]
            break
        else:
            i-=1
        if(a[j]!=x+d):
            ans=a[j]
            break
        else:
            j+=1
        d+=1
    print(ans)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
q = [i for i in range(1, 101)]
if n != 0:
  p = list(map(int, input().split()))
  for i in p:
    q[i-1] = -100

if x in q:
  print(x)
  exit()

l = []

for i in range(100):
  if x+i in q:
    l.append(x+i)
    break
for j in range(100):
  if x-i in q:
    l.append(x-i)
    break

if len(l) == 1:
  print(l[0])
  exit()

if abs(l[0]-x) < abs(l[1]-x):
  print(l[0])
elif abs(l[0]-x) > abs(l[1]-x):
  print(l[1])
else:
  print(l[1])

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
try:
    p=list(map(int,input().split()))
    p.sort()
    min=abs(p[0])
    for i in range(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:
    p = set(map(int,input().split()))
mini = float('inf')
ans = float('inf')
for i in range(-400,400):
    if i not in p:
        if abs(x-i)<mini:
            mini = abs(x-i)
            ans = i
        elif abs(x-i)==mini and ans>i:
            ans=i
print(ans)

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

kouho = list(range(1, max(p) + n))
# print(kouho)

for i in range(len(p)):
  if p[i] != x:
    del kouho[kouho.index(p[i])]

kouho_num = kouho.index(x)
right = kouho_num + 1
left = kouho_num - 1


if kouho[right] - kouho[kouho_num] > kouho[kouho_num] - kouho[left]:
  print(kouho[left])
elif kouho[right] - kouho[kouho_num] == kouho[kouho_num] - kouho[left]:
  print(kouho[left])
else:
  print(kouho[right])

Submission status: Runtime Error

Solution code:
x , n= map(int,input().split())
p = list(map(int,input().split()))
ans = []
if n == 0:
    print(x)
else:
    for i in range(1,101):
        if i in p:
            pass
        else:
            ans.append(i)
    sa = []
    for i in range(0,len(ans)):
        sa.append(abs(ans[i]-x))
    MIN=min(sa)
    for i in range(n):
        if MIN == abs(ans[i]-x):
            print(ans[i])

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split(" "))
if n != 0:
  p=list(map(int, input().split(" ")))
else:
  p=[]
lst = list(range(0, x * 2))
for i in p:
  lst.remove(i)
for i in range(x + 2):
  if x - i in lst or x - i < 0:
    print(x - i)
    break
  elif x + i in lst:
    print(x + i)
    break

Submission status: Runtime Error

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

if N == 100:
    print(-1)
    exit()


for i in range(X+1):
    if not i in p:
        x = i

for i in range(X,101):
    if not i in p:
        y = i
        break

if (X-x) == (y-X):
    print(x)
elif (X-x) > (y-X):
    print(y)
else:
    print(x)

Submission status: Runtime Error

Solution code:
x,n=map(int, input().split())
if n == 0:
  print(x)
  exit()
p=list(map(int, input().split()))
all=set(range(1,101))
s_p=set(p)

min_dis=100
for i in all-s_p:
  dis=abs(i-x)
  if min_dis > dis:
    min_i=i
    min_dis=dis
print(min_i)

Submission status: Runtime Error

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

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

p_set = set(P)

if not (X in p_set):
    print(X)
    sys.exit()

for i in range(1, 100):
    if not (X-i in p_set):
        print(X-i)
        break
    if not (X+i in p_set):
        print(X+i)
        break

Submission status: Runtime Error

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

integers = [i for i in range(1, 101)]  # この中の整数をxと比較
for i in list:
    integers.remove(i)

ans = integers[0]
minabs = abs(integers[0] - x)
for i in integers:
    if abs(i - x) < minabs:
        minabs = abs(i - x)
        ans = i

print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))

            l = [i for i in reversed(range(1, x))]
            r = [i for i in range(x+1, 101)]
            cur = 0
            if x not in p:
                return x
            while True:
                if cur<x:
                    if l[cur] not in p:
                        return l[cur]
                if cur<len(r):
                    if r[cur] not in p:
                        return r[cur]
                cur+=1
    print(main())


resolve()

Submission status: Runtime Error

Solution code:
lst = []
n = int(input())
no = int(input())
for i in range(0,no):
  inp = int(input())
  lst.append(inp)
  if inp==n:
    index = i
for i in range(1,100):
  if n-i not in lst:
    print(n-i)
    break
  if n+i not in lst:
    print(n+i)
    break

Submission status: Runtime Error

Solution code:
import numpy as np

def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    P = set(map(int, input().split()))
    if not x in P:
        print(x)
        return

    P_not = np.array(list(set(list(range(1, 101))) - P))
    diff = np.abs(P_not - x)
    print(P_not[diff.argmin()])

resolve()

Submission status: Runtime Error

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

check = [0] * max(p)
for i in range(n):
    check[p[i]-1] = 1

ans = []
d = 10**9
for i in range(1,len(check)+1):
    if d >= abs(i-x) and check[i-1] != 1:
        d = abs(i-x)
        ans.append([abs(i-x),i])

ans.sort()
print(ans[0][1])

Submission status: Runtime Error

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

for j in range(x):
	#print(x,j,x-j,x+j)
	if(valid[x-j] == 1):
		print(x-j)
		break
	elif(valid[x+j] == 1):
		print(x+j)
		break

Submission status: Runtime Error

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

smaller = 0
for i in range(x):
    if x - i in p:
        pass
    else:
        smaller = x-i
        break

bigger = 2*x
for j in range(x):
    if x + j in p:
        pass
    else:
        bigger = x + j
        break

ans = smaller if x - smaller <= bigger - x else bigger
#print(bigger)
print(ans)

Submission status: Runtime Error

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    X, N = mulinputs()
    ps = set(mulinputs())

    mins = [ [] for _ in range(100)]
    
    m = INF
    for p in range(1,101):
        if p in ps:
            continue
        tmp = abs(X-p)
        if tmp < m:
            m = tmp
            mins[m].append(p)
        elif tmp == m:
            mins[m].append(p)

    mins[m].sort()
    # 出力
    if mins[m] is not None:
        print(mins[m][0])
    else:
        print(X)

Submission status: Runtime Error

Solution code:
import sys
x,n=map(int,input().split())
if n==0:
    print(x)
    sys.exit()
else:
    p=list(map(int,input().split()))
    res=1000
    for i in range(1,101):
        p.append(i)
        if len(p)==len(set(p)):
            if res>=abs(x-i):
                res=abs(x-i)
                ans=i
        del p[-1]
    for i in range(n):
        if x+(x-ans)!=p[i]:
            print(x+(x-ans))
            sys.exit()
    print(ans)

Submission status: Runtime Error

Solution code:
import sys

def prepare(X):
    N = 101
    List = [X] * N
    for i in range(0, 50):
        List[2*i+1] -= i+1
        List[2*i+2] += i+1
    return List

def remove(List, N, PList):
    for Num in range(N):
        List.pop( List.index(PList[Num]) )
    print(List[0])
if(__name__ == "__main__"):

    XY = input().strip().split()
    X = int(XY[0])
    N = int(XY[1])

    PList = [0] * N
    if(N > 0):
        P_str = input().strip().split()

        for i in range(N):
            PList[i] = int( P_str[i] )

        List = prepare(X)
        remove(List, N, PList)
    else:
        print(X)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
lis=[i+1 for i in range(100)]
flag=True
if n==0:
  flag=False
  print(x)
if flag:
  p=list(map(int,input().split()))
  for i in p:
    lis.remove(i)
  for i in range(len(lis)):
    if lis[i]>x:
      id=i
      break
  if id>=1:
    if abs(x-lis[id])<abs(x-lis[id-1]):
      print(lis[id])
    else:
      print(lis[id-1])
  else:
    print(lis[0])

Submission status: Runtime Error

Solution code:
x,n=map(int, input().split())
if n == 0:
  print(x)
  exit()
p=list(map(int, input().split()))
all=set(range(1,101))
s_p=set(p)

min_dis=100
for i in all-s_p:
  dis=abs(i-x)
  if min_dis > dis:
    min_i=i
    min_dis=dis
print(min_dis, min_i)

Submission status: Runtime Error

Solution code:
import sys
X, N = map(int, input().split())
if (N==0):
    print(100)
    sys.exit()
p = list(map(int, input()))

n_ans = 1
sa = 100
for k in range(1,100,1):
    if (k in p):
        continue
    if(abs(k-X) < sa):
        n_ans = k
        sa = abs(k-X)
    else:
        break
print(n_ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
X,N=map(int,input().split())
P=[]
if N!=0:
    P=list(map(int,input().split()))
K=[]
for i in range(1,101):
    if not(i in P):
        K.append(i)

ans=[]

for i in range(len(K)):
    ans.append([abs(X-K[i]),K[i]])

ans.sort()

print(ans[0][1])

Submission status: Runtime Error

Solution code:
lst = []
n = int(input())
no = int(input())
for i in range(0,no):
  inp = int(input)
  lst.append(inp)
  if inp==n:
    index = i
for i in range(1,100):
  if n-i not in lst:
    print(n-i)
    break
  if n+i not in lst:
    print(n+i)
    break

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
a=list(map(int,input().split()))
if not x in a:
    print(x)
else:
    a.sort()
    i=a.index(x)-1
    j=i+2
    d=1
    ans=0
    while(True):
        if(a[i]!=x-d):
            ans=a[i]
            break
        else:
            i-=1
        if(a[j]!=x+d):
            ans=a[j]
            break
        else:
            j+=1
        d+=1
    print(ans)

Submission status: Runtime Error

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

smaller = 0
for i in range(x):
    if x - i in p:
        pass
    else:
        smaller = x-i
        break

bigger = 2*x
for j in range(x):
    if x + j in p:
        pass
    else:
        bigger = x + j
        break

ans = smaller if x - smaller <= bigger - x else bigger
#print(bigger)
print(ans)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    P=list(map(int,input().split()))
    N=[i for i in range(1,101)]

    for p in P:
        N.pop(N.index(p))

    L=[]
    for a in N:
        l=abs(a-x)
        L.append(l)
    
    m=L.index(min(L))
    print(N[m])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        x, n = map(int, input().split())
        if n == 0:
            return x
        else:
            p = list(map(int, input().split()))

            l = [i for i in reversed(range(1, x))]
            r = [i for i in range(x+1, 101)]
            cur = 0
            if x not in p:
                return x
            while True:
                if l[cur] not in p:
                    return l[cur]
                if r[cur] not in p:
                    return r[cur]
                cur+=1
    print(main())


resolve()

Submission status: Runtime Error

Solution code:
if N == 0:
    P = []
else:
    P = [int(x) for x in input().split()]

for i in range(100):
    q = X - i
    if q not in P:
        print(q)
        break
    q = X + i
    if q not in P:
        print(q)
        break

Submission status: Runtime Error

Solution code:
import numpy as np
X, N = map(int, input().split())
P = list(map(int, input().split()))
candidate = list(range(1, 101))
P = sorted(set(candidate).difference(set(P)))
i = np.argmin([abs(p - X) for p in P])
print(P[i])

Submission status: Runtime Error

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

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

result = []

i = 0

while len(result) == 0:
    if not (x - i in p):
        result.append(x - i)
    if not (x + i in p):
        result.append(x + i)
    
    i += 1

print(int(min(result)))

Submission status: Runtime Error

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