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:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x,n=n1()

if n==0:
    print(x)
else:
    P=n1()
    if (not x in P):
        print(x)
    else:
        d=[]
        d2=[]
        for i in range(1,101):
            if (not i in P):
                d.append(i)
                d2.append(abs(x-i))

        a=min(d2)
        if x-a in d:
            print(x-a)
        else:
            print(x+a)

Submission status: Runtime Error

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

if n == 0:
    print(x)
else:
    num = set(range(1, 101)) ^ set(p)
    num = sorted([[abs(i - x), i] for i in num])
    if num[0][0] == num[1][0]:
        print(min(num[0][1], num[1][1]))
    else:
        print(num[0][1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

l = list(range(1, 101))

p = list(set(l)-set(p))
sa = [abs(x - p[i]) for i in range(len(p))]
sa_min = min(sa)

for i in range(len(l)):
    if sa[i] == sa_min:
        print(p[i])
        break

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
  c=[0]*100
  for i in p:
    c[i-1]+=1
  ans=0
  while True:
    if c[x-ans-1]==0:
      ans=x-ans
      break
    elif c[x+ans-1]==0:
      ans=x+ans
      break
    else:
      ans+=1
  print(ans)
else:
  print(x)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
X, N = map(int, input().split())
P = sorted(list(map(int, input().split())))
i = 0
if N == 0:
  print(X)
else:
  while True:
    x = X-i
    idx = bisect_left(P, x)
    if idx < 0 or idx >= N or P[idx] != x:
      print(x)
      break
    else:
      x = X+i
      idx = bisect_left(P, x)
      if idx < 0 and idx >= N or P[idx] != x:
        print(x)
        break
    i += 1

Submission status: Runtime Error

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

res = []
for i in range(1, 101):
    if i not in p:
        res.append([abs(i-x), i])

res.sort(key=lambda x:x[0])
print(res[0][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()))
  p.sort()
  ans=0
  on=1
  dif=1
  if x in p:
    now=p.index(x)
    while on==1:
      if p[now-dif]!=x-dif:
        ans=x-dif
        on=0
      elif p[now+dif]!=x+dif:
        ans=x+dif
        on=0
      else:
        dif+=1
    print(ans)
  else:
    print(x)

Submission status: Runtime Error

Solution code:
#

import sys
input=sys.stdin.readline

def main():
    X,N=map(int,input().split())
    p=list(map(int,input().split()))
    p.sort()
    ans=[]
    for i in range(max(X,100-X)):
        if not X+i in p:
            ans+=[X+i]
        if not X-i in p:
            ans+=[X-i]
        if len(ans)>0:
            break
    print(min(ans))
    
if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
ab = min(abs(101 - x),abs(x+1))
for i in range(1,101):
    if i in p:
        continue
    else:
        if ab > abs(x - i):
            ab = abs(x - i)
            answer = i
print(answer)

Submission status: Runtime Error

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

m = -1
for a in p:
  if m == -1 or (abs(a - x) < abs(m - x)) or (abs(a - x) == abs(m - x) and a < m):
    m = a

print(m)

Submission status: Runtime Error

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

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

for s in range(1, 101):
    if s not in P:
        ans = s
        break

for s in range(1, 101):
    if s not in P:
        if abs(ans-x) > abs(s-x):
            ans = s
        elif abs(ans-x) == abs(s-x):
            ans = min(ans, s)

print(ans)

Submission status: Runtime Error

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

val = []
ans = []
if p:
    for i in range(1,101):
        if i not in p:
            val.append(abs(x-i))
    if x - min(val) not in p:
        ans.append(x - min(val))
    if x + min(val) not in p:
        ans.append(x + min(val))
    print(min(ans))

else:
    print(x)

Submission status: Runtime Error

Solution code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=list(map(int,input().split()))
p=set(p)
res=[]
for i in range(x,0,-1):
    if i not in p:
        res.append(i)
        break
for i in range(x+1,101):
    if i not in p:
        res.append(i)
if len(res)==1:
    print(res[0])
else:
    if x-res[0]>res[1]-x:
        print(res[1])
    else:
        print(res[0])

Submission status: Runtime Error

Solution code:
x,n=list(map(int, input().split()))
if n!=0:
    p=list(map(int, input().split()))
d=0
t=0
while t==0:
    if (x-d) not in p:
        print (x-d)
        t=1
    elif (x+d) not in p:
        print (x+d)
        t=1
    else:
        d+=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()))

    X_u = X - 1
    X_l = X + 1
    while judge:
        X_u += 1
        X_l -= 1
        if X_u not in p and X_l not in p:
            print(X_l)
            break
        elif X_u not in p:
            print(X_u)
            break
        elif X_l not in p:
            print(X_l)
            break
        else:
            if X_u == X_l:
                p.remove(X_u)
            else:
                p.remove(X_u)
                p.remove(X_l)

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
A=list(map(int,input().split()))
print(min(abs(A-N),N))

Submission status: Runtime Error

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x,n=n1()
P=n1()

if len(P)==0:
    print(x)
elif not x in P:
    print(x)
else:
    d=[]
    d2=[]
    for i in range(1,101):
        if not i in P:
            d.append(i)
            d2.append(abs(x-i))

    a=min(d2)
    if x-a in d:
        print(x-a)
    else:
        print(x+a)

Submission status: Runtime Error

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

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

p = set(p)
pp = set([item for item in range(0,101) if item not in p])
v = 3000
ans = -1
for item in pp:
    if v>abs(x-item):
        v = abs(x-item)
        ans = item
print(ans)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())))
l = [int(i) for i in range(1, 101)]
ll = []
for idx in l:
    if idx not in p:
        ll.append(idx)
mn = abs(ll[0] - x)
ans = ll[0]
for i in range(len(ll)):
    if abs(ll[i] - x) < mn:
        mn = abs(ll[i] - x)
        ans = ll[i]
print(ans)

Submission status: Runtime Error

Solution code:
X, N = [int(i) for i in input().split()]
if N==0:
    P = list(range(1, 101))
else:
    P = list(set(range(1, 101)) - {int(i) for i in input().split()})
P.sort()

D = [abs(P[i]-X) for i in range(len(P))]

print(P[D.index(min(D))])

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
*P, = map(int, input().split())
cand = set(range(101)) - set(P)
ans, temp = None, 10**10
for c in cand:
    t = abs(X - c)
    if t < temp:
        temp = t; ans = min(ans, c)
print(ans)

Submission status: Runtime Error

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

c = 100
for x in range(1, 101):
    if x in P:
        continue
    else:
        tmp = abs(X-x)
        if tmp < c:
            c = tmp
            ans = x
print(ans)

Submission status: Runtime Error

Solution code:
X,N = map(int, input().split())
A = list(map(int, input().split()))
Min = 101

for i in range(1,101):
    if i in A:
        continue
    if abs(i-X) < Min:
        ans = i
        Min = abs(i-X)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

X,N = I()
p = l()
p.sort()
for i in range(N):
    if p[i] > X:
        if abs(p[i]-X) > abs(p[i-1]-X):
            print(p[i-1])
            exit()
        else:
            print(p[i])
            exit()
print(p[-1])

Submission status: Runtime Error

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    X, N, *P = map(int, read().split())
    P = set(P)
    Q = [i for i in range(1, 101) if i not in P]
    Q.sort()
    error = INF
    for q in Q:
        if abs(X-q) < error:
            ans = q
            error = abs(X-q)
    
    print(ans)
    return


if __name__ == '__main__':
    main()