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()))
if n==0:
    print(x)
    exit()
res = []
for num in range(1,101):
    if x!=num and num not in p:
        res.append(abs(x-num))
if x-min(res) not in p:
    print(x-min(res))
else:
    print(x+min(res))

Submission status: Runtime Error

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

if  n==0:
 print(x)
else:
 P =list(map(int,input().split()))
 l = list(range(2*x))
 result = list(set(l) - set(P))
 abs = list(np.abs(np.array(result)-x))
 abs.remove(0)
 min = min(abs)
 print(abs)
 print(result[abs.index(min)])

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if(n == 0):
    print(x)
elif(n == 100):
    ff = 101-x
    gg = x
    if(ff < gg):
        print(101)
    else:
        print(0)
else:
    p = list(map(int, input().split()))
    if(not(x in p)):
        print(x)
    else:
        m = [i for i in range(1, 101)]

        o = list(set(m) - set(p))
        ans = 100
        dif = 100-x
        for i in range(len(o), 0, -1):
            if(dif >= abs(x-o[i])):
                ans = o[i]
                dif = abs(x-o[i])
        print(ans)

Submission status: Runtime Error

Solution code:
A, B = map(int, input().split())
if B == 0:
    print(A)
else:
    L=list(map(int,input().split()))
    L = [abs(i - A) for i in L]
    L +=[0]
    L=sorted(L)
    x=0
    i,j=0,1
    while True:
        if L[i] == x and L[j] == x :
            i,j = i+2,j+2
            x += 1
        else:
            break
    print(A+x)

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
if n==0:
    print(x)
    exit()
elif x==1:
    print(0)
    exit()
res = []
for num in range(1,101):
    if x!=num and num not in p:
        res.append(abs(x-num))
if x-min(res) not in p:
    print(x-min(res))
else:
    print(x+min(res))

Submission status: Runtime Error

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

p_ = [i for i in range(101)]
p_ = list(set(p_) - set(p))

list = []
list_ = []
for j in p_:
  C = abs(X-j)
  list.append(C)
  list_.append(X-j)
list.sort()

elif list_.count(list[0]) == 0:
  print(X-list[0])
else:
  print(X+list[0])

Submission status: Runtime Error

Solution code:
x, n = input().split(' ')
line = input()
if line == '':
    print(x)
    exit()

x = int(x)

alist = line.split(' ')
for i in range(int(n)):
    alist[i] = int(alist[i])
if not x in alist:
    print(x)
    exit()

blist = [i for i in range(1,101)]
bset = set(blist)
aset = set(alist)
cset = bset-aset
clist = list(cset)
clist.append(x)
clist.sort()

count = 0
for i,v in enumerate(clist):
    if v == x:
        count = i
        print(len(clist),i,v,x)
if count == 0:
    print(clist[1])
elif count == len(clist)-1:
    print(clist[-2])
else:
    minx = x - clist[count-1]
    maxx = clist[count+1]-x
    if minx > maxx:
        print(clist[count+1])
    else:
        print(clist[count-1])

Submission status: Runtime Error

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

ans1 = int()
ans2 = int()

p.sort()

if x not in p:
    print(x)
    sys.exit()

for i in range(n):
    if x == p[i]:
        for j in range(x + 1, 100):
            if j not in p:
                ans1 = j
                break
        for k in reversed(range(x,)):
            if k not in p:
                ans2 = k
                break

if ans1 - x < x - ans2:
    print(ans1)
else:
    print(ans2)

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, n = 10, 5
# p =  [4, 7, 10, 6, 5]
# ->9が解
# x, n = 6, 5
# p = [4, 7, 10, 6, 5]

# x, n = 1, 1
# # p = list(range(1, 101))
# p = [1]

# pに含まれない整数リストを、最小値-1最大値+1も含めて求める
pl = min(p)-1
pr = max(p)+2
npl = list(range(pl, pr))
np = list(set(npl) - set(p))
np.sort()

# np内で最もxに近い数値を算出する
mx = x
res = np[0]
for k in np:
  t = abs(k - x)
  if t < mx:
    mx = t
    res = k
 
print(res)

Submission status: Runtime Error

Solution code:
import sys
import math

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

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

p_list.sort()

for i in range(n):
    if p_list[i] == x:
        j = i
        k = 1
        while j <= n-1:
            if p_list[i-k] != x-k and i != 0:
                print(x-k)
                sys.exit()
            elif p_list[i+k] != x+k and i != n-1:
                print(x+k)
                sys.exit()
            j += 1
            k += 1
    if p_list[i] > x:
        print(x)
        sys.exit()

if p_list[-1] < x:
    print(x)


#sub = min(abs(p_list[j] - x), abs(p_list[j-1] -x))

Submission status: Runtime Error

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

sorted_list = sorted(li)

if X in sorted_list:
    X_place = sorted_list.index(X)
    for i in range(1, 100):
        try:
            if sorted_list[X_place - i] < int(X - i):
                minimum_number = int(X - i)
                break
        except IndexError:
            minimum_number = int(X - i)

    for i in range(1, 100):
        try:
            if sorted_list[X_place + i] > int(X + i):
                max_number = int(X + i)
                break
        except IndexError:
            max_number = int(X + i)

    if abs(X - minimum_number) <= abs(X - max_number):
        print(minimum_number)
    else:
        print(max_number)

else:
    print(X)

Submission status: Runtime Error

Solution code:
A, B = map(int, input().split())
L=list(map(int,input().split()))
L = [abs(i - A) for i in L]
L +=[0]
L=sorted(L)
x=0
i,j=0,1
while True:
    if L[i] == x and L[j] == x :
        i,j = i+2,j+2
        x += 1
    else:
        break
print(A+x)

Submission status: Runtime Error

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


if n <= 0:
    print(x)
else:
    p = list(map(int,input().split()))
    p2 = [x for x in range(1,100+1)]

    p_p2_diff = set(p)^set(p2)
    p_p2_diff_list = list(p_p2_diff)

    min_list = []
    for i in range(len(p_p2_diff_list)):
        val = abs(x - p_p2_diff_list[i])
        min_list.append(val)

    print(p_p2_diff_list[min_list.index(min(min_list))])

Submission status: Runtime Error

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

p_ = [i for i in range(101)]
p_ = list(set(p_) - set(p))

list = []
list_ = []
for j in p_:
  C = abs(X-j)
  list.append(C)
  list_.append(X-j)
list.remove(X)
list.sort()
if list[0] == list[1]:
  print(X-list[0])
elif list_.count(list[0]) == 0:
  print(X+list[0])
else:
  print(X-list[0])

Submission status: Runtime Error

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

# x, n = 10, 5
# p =  [4, 7, 10, 6, 5]
# ->9が解
# x, n = 6, 5
# p = [4, 7, 10, 6, 5]

# x, n = 1, 1
# # p = list(range(1, 101))
# p = [1]

# pに含まれない整数リストを、最小値-1最大値+1も含めて求める
pl = min(p)-1
pr = max(p)+2
npl = list(range(pl, pr))
np = list(set(npl) - set(p))
np.sort()

# np内で最もxに近い数値を算出する
mx = x
res = np[0]
for k in np:
  t = abs(k - x)
  if t < mx:
    mx = t
    res = k
 
print(res)

Submission status: Runtime Error

Solution code:
X, N = map(int,input().split())
if N == 0:
    print(X)
    exit()
else:
    P = list(map(int,input().split()))
L = [i for i in range(-1,100) if i not in P]


if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    l = len(L)

    if (0 < n < l):
        if (L[n+1]-L[n] < L[n] - L[n-1]):
            ANS = L[n+1]
        else:
            ANS = L[n - 1]
    elif (n == 0):
        ANS = L[1]
    elif (n == l):
        ANS = L[l - 1]

print(ANS)

Submission status: Runtime Error

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

ans = X
for j in range(N):
    if ans == P[j]:
        judge = 1
        cri = j
if judge == 0:
    print(ans)
    exit()
else:
    for i in range(1,X):
        ans = X - i
        if ans != P[cri-i]:
            print(ans)
            exit()
        ans = X + i
        if ans != P[cri+i]:
            print(ans)
            exit()
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    lists = list(map(int, input().split()))
    lists_arr = np.array(lists)

    max = lists_arr.max()
    min = lists_arr.min()
    number_lists = list(range(min, max+1, 1))
    existing = number_lists.copy()
    for i in lists:
        existing.remove(i)
    existing_arr = np.array(existing)
    if x > max or x < min:
        print(x)
    else:
        if x <= existing_arr.min():
            print(existing_arr.min())
        elif x >= existing_arr.max():
            print(existing_arr.max())

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
if N > 0:
    l = list(map(int, input().split()))
    A = [0] * N

    for i in range(N):
        A[i] = abs(l[i] - X)

    S = A.count(0)
    if S == 0:
        print(X)

    for i in range(1, N + 1):
        S = A.count(i)
        if S == 0:
            print(X-1)
        if S == 1:
            if l.count(X - i) == 0:
                print(X - i)
                break
            else:
                print(X + i)
                break
        else:
            pass

else:
    print(X)
print(A)

Submission status: Runtime Error

Solution code:
a=input().split(' ')
X=int(a[0])
N=int(a[1])

if N!=0:
  Ls=input().split(' ')
  L=[]
  for i in range(N):
    L.append(int(Ls[i]))
else:
  s=X

for i in range (N):
  if X-i in L and X+i in L:
    pass
  elif X-i not in L:
    s=X-i
    break
  elif X-i in L and X+i not in L:
    s=X+i
    break
print(s)

Submission status: Runtime Error

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


else:
    p = list(map(int, input().split()))
    abs_list = []
    re_list = []
    min = 1000
    min_index = 0

    for i in range(100):
        abs_list.append(i + 1)
    for j in p:
        abs_list.remove(j)
    for i in range(len(abs_list)):

        re_list.append(abs(abs_list[i] - X))
    for i in range(len(re_list)):
        if min > re_list[i]:
            min = re_list[i]
            min_index = i
    print(abs_list[min_index])

Submission status: Runtime Error

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

for j in range(n):
    q.remove(p[j])

b=101
min=999
for k in range(len(q)):
    a=x-q[k]
    if min>=abs(a):
        min=abs(a)
        b=k
        
print(b)

Submission status: Runtime Error

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

for i in p:
    p_change.append(abs(i-x))

if x in p:
	pass
else:
  print(x)
    
for i in range(n):
    if i != 0 and p_change.count(i) != 2:
        m = i
        break
if x-m in p_change:
    print(x+m)
else:
    print(x-m)

Submission status: Runtime Error

Solution code:
X, N = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    Ps = [int(i) for i in input().split()]
    coords = set(range(min(Ps), max(Ps)+1))
    for p in Ps:
        coords.remove(p)
    if X in coords:
        print(X)
    else:
        ret = [ (v, abs(X-v)) for v in coords ]
        minval = min(ret, key=lambda elm: elm[1])[0]
        print(
            min([ elm[0] for elm in ret if minval == elm[0] ])
        )

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

x, y = map(int, input().split())

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

p = [list(map(int, input().split()))]
p_n = np.array(p)
p_n = p_n.reshape(-1)
pp = np.arange(1, 100)
for i in p_n:
    pp[i-1] = 10000
sa = min(abs(pp-x))
if pp[x-sa-1] == 10000:
    print(pp[x+sa-1])
else:
    print(pp[x-sa-1])

Submission status: Runtime Error

Solution code:
def forbidden(x,p):
    res = []
    if x==1:
        return 0
    for num in range(1,101):
        if x!=num and num not in p:
            res.append(abs(x-num))
    if x-min(res) not in p:
        return x-min(res)
    return x+min(res)

if __name__ == "__main__":
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    if n==0:
        print(x)
        exit()
    print(forbidden(x,p))

Submission status: Runtime Error

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

array = [[0]]*100
if n == 0:
    print(x)
else:
    for i in range(100):
        array[i] = 0
    tmp = input().split(' ')
    for i in range(n):
        array[int(tmp[i])] += 1
    
    dif_tmp = 999
    ret = 999
    for i in range(100):
        if array[99-i] == 0:
            if abs(x-(99-i)) <= dif_tmp:
                ret = 99-i
                dif_tmp = abs(x-(99-i))
    for i in range(1,100):
        if abs(x+i) <= dif_tmp:
            ret = -i
            dif_tmp = abs(x+i)
    print(ret)

Submission status: Runtime Error

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

for j in range(n):
    q=q.remove(p[j])

b=101
min=999
for k in range(len(q)):
    a=x-q[k]
    if min>=abs(a):
        min=abs(a)
        b=k
        
print(b)

Submission status: Runtime Error

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

p.sort()
Max = 101
li_p = [i for i in range(1, Max)]
diff_p = list(set(p) ^ set(li_p))

if x in diff_p == False:
    print(x)
    exit(0)
    
d = abs(diff_p[0] - x)
ans = diff_p[0]
for i in range(1, len(diff_p)):
    d1 = abs(diff_p[i] - x)
    if d1 < d:
        d = d1
        ans = diff_p[i]
    else:
        break
print(ans)

Submission status: Runtime Error

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

if n > 0:
  l = sorted(p)
  a = [num for num in range(1, 101)]
  s = set(a) - set(l)
  s2 = list(s)
  s2.append(x)
  s3 = sorted(s2)
  i = s3.index(x)
  if i != 0:
    m = s3[i] - s3[i-1] 
    j = s3[i+1] - s3[i]
    if m > j:
      print(s3[i+1])
    else:
      print(s3[i-1])
  else:
    print(s3[i+1])
  
else:
  print(x)

Submission status: Runtime Error

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

p_list = sorted(p_list)
all_range = list(range(1, 101))
A = [i for i in all_range if i not in p_list]
B = [abs(i - X) for i in A]

low = X - min(B)
high = X + min(B)

output = 0
if high > 100:
  output = low
if low < 1:
  output = high

if N == 0:
  print(X)
elif output != 0:
  print(output)
elif high in p_list:
  print(low)
elif low in p_list:
  print(high)
else:
  print(low)

Submission status: Runtime Error

Solution code:
import numpy as np
X,N = map(int, input().split())
p = list(map(int, input().split()))
p = sorted(p)
lista = list(range(1,101))
for i in p:
    if i in lista:
        lista.remove(i)
lista = np.array(lista)
def find_nearest(array, value):
    array = np.asarray(array)
    idx = (np.abs(array - value)).argmin()
    print(array[idx])
find_nearest(lista,X)

Submission status: Runtime Error

Solution code:
n, ls = [int(x) for x in input().strip().split(' ')]
if ls==0:
    print(n)
else:
    x = [int(x) for x in input().strip().split(' ')]
    x.sort()
    a = []
    for y in range(1,x[-1]):
        if y not in x:
            a.append(y)
    # print(a)
    b = {}
    for y in range(len(a)):
        b.update({a[y]: abs(n-a[y])})
    print(min(b.keys(), key=(lambda k: b[k])))

Submission status: Runtime Error

Solution code:
n = int(input())
lis = list(map(int,input().split()))
lis.sort()
p = 0
counter = n
for i in range(n):
    if i>0 and lis[i] == lis[i-1]:
        counter -=1
    elif i>0 and lis[i]<lis[0]*2:
        p += 1
    else:
        for j in range(n):
            if i != j and lis[i]%lis[j] ==0:
                counter -=1
                break
print(counter)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int X,N;
  cin >> X >> N;
  vector<int> p(N);

  for(int i = 0; i < N; i++){
    cin >> p.at(i);
  }
  
  int dmem = 100;
  int ans = 0;
  for(int i = 0; i< 100; i++){
    int dis = abs(X - i);
    int count = 0;
    for(int j = 0; j < N; j++){
      if(i == p.at(j)){
        break;
      }
      else{
        count++;
        //cout << count << " ";
      }
      if(count == N){
        if(dis < dmem){
          ans = i;
          dmem = dis;
          //cout << i << " " << dmem << endl;
        }
        else{
          break;
          break;
        }
      }
    }
    //cout << endl;
  }
  cout << ans << endl;
}

Submission status: Runtime Error

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

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

# 1から100のリスト
num_li = [i for i in range(101)]

# num_liのリストにpiに含まれていたら0にする
for i in pi:
	if i<0:
		continue
	else:
		num_li[i]=0
	
a = X
for i in range(1,101):
	if i%2==1: a+=(-1)*i
	else: a+=i
	if num_li[a] != 0:
		print(num_li[a])
		exit()

Submission status: Runtime Error

Solution code:
import sys
import math

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

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

p_list.sort()

for i in range(n):
    if p_list[i] == x:
        j = i
        k = 1
        while j <= n-1:
            if p_list[i-k] != x-k and i != 0:
                print(x-k)
                sys.exit()
            elif p_list[i+k] != x+k and i != n-1:
                print(x+k)
                sys.exit()
            j += 1
            k += 1
    if p_list[i] > x:
        print(x)
        break


#sub = min(abs(p_list[j] - x), abs(p_list[j-1] -x))

Submission status: Runtime Error

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

array = [[0]]*100

for i in range(100):
    array[i] = 0
tmp = input().split(' ')
for i in range(n):
    array[int(tmp[i])] += 1

dif_tmp = 999
ret = 999
for i in range(100):
    if array[99-i] == 0:
        if abs(x-(99-i)) <= dif_tmp:
            ret = 99-i
            dif_tmp = abs(x-(99-i))
for i in range(1,100):
    if abs(x+i) <= dif_tmp:
        ret = -i
        dif_tmp = abs(x+i)
print(ret)

Submission status: Runtime Error

Solution code:
def forbidden(x,p):
    res = []
    for num in range(1,101):
        if x!=num and num not in p:
            res.append(abs(x-num))
    if x-min(res) not in p:
        return x-min(res)
    return x+min(res)

if __name__ == "__main__":
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    if n==0:
        print(x)
        exit()
    elif x==1:
        print(0)
        exit()
    print(forbidden(x,p))

Submission status: Runtime Error

Solution code:
X, N = map(int,input().split())
if N == 0:
    print(X)
    exit()
else:
    P = list(map(int,input().split()))
L = [i for i in range(1,100) if i not in P]


if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    l = len(L)

    if (0 < n < l):
        if (L[n+1]-L[n] < L[n] - L[n-1]):
            ANS = L[n+1]
        else:
            ANS = L[n - 1]
    elif (n == 0):
        ANS = L[1]
    elif (n == l):
        ANS = L[l - 1]

print(ANS)

Submission status: Runtime Error

Solution code:
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
x,n=get_ints()
p=get_array()
for j in range(x,0,-1):
    if j not in p:
        ans1=j 
        break
        
for k in range(x,102):
    if k not in p:
        ans2=k 
        break
if ans2-x<x-ans1:
    print(ans2)
elif x-ans1<ans2-x:
    print(ans1)
else:
    print(ans1)

Submission status: Runtime Error

Solution code:
import numpy as np

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

lists_arr = np.array(lists)

max = lists_arr.max()
min = lists_arr.min()
number_lists = list(range(min, max+1, 1))
existing = number_lists.copy()
for i in lists:
    existing.remove(i)
existing_arr = np.array(existing)
if x > max or x < min:
    print(x)
else:
    if x <= existing_arr.min():
        print(existing_arr.min())
    elif x >= existing_arr.max():
        print(existing_arr.max())

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())
if b != 0:
    c = input()
    l = c.split()
    cc = [int(s) for s in l]
    ccc =list(cc)
    for i in range(a,101):
        if i in ccc:
            continue
        else:
            x = i
            break
    for i in reversed(range(0, a)):
        if i in ccc:
            continue
        else:
            y = i
            break
    if x-a<a-y:
        print(x)
    else:
        print(y)
else:
    d = input()
    print(a)

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
Q = [i for i in range(-100, 101) if i not in P]

c = 0
R = 1000
if N == 0:
    print(X)
else:
    while True:
        if R <= abs(X-Q[c]):
            break
        else: 
            R = abs(X-Q[c])
            c += 1
    print(Q[c-1])

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
if N > 0:
    A = list(map(int,input().split()))
    d = {}
    for i in range(101):
        d[i] = 0
    for a in A:
        d[a] = 1
    for i in range(0,100):
        x = X - i
        y = X + i
        if d[x] == 0:
            print(x)
            quit()
        if d[y] == 0:
            print(y)
            quit()
else:
    print(X)

Submission status: Runtime Error

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

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

p.sort()
#print(p)
for i in range(n):
    if p[i] == x:
        index = i
        break

right = x + 1
for i in p[index + 1:]:
    #print(i)
    if i != right:
        #print('aaaa')
        #print(right)
        break
    right += 1

left = x - 1
for i in reversed(p[:index]):
    #print(i)
    if i != left:
        #print('bbbb')
        #print(left)
        break
    left -= 1

if x - left <= right - x:
    print(left)
else:
    print(right)

Submission status: Runtime Error

Solution code:
xn=input()
x,n=xn.split()
if n=='0':
  print(int(x))
else:
  p=input()
  p={int(i) for i in p.split()}
  s={i for i in range(1,100)}
  s_p=list(s-p)
  d=[abs(i-int(x)) for i in s_p]
  print(s_p[d.index(min(d))])

Submission status: Runtime Error

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

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

min_value = min(p)
max_value = max(p)

if x < min_value:
    print(x)
    exit()
if x > max_value:
    print(x)
    exit()

tmp_min_value = 100

for i in range(x, 101):    
    flag = 0
    for j in range(n):
        if i == p[j]:
            flag = 1
    if flag == 1:
        continue

    if tmp_min_value > i:
        tmp_min_value = i
        tmp_min_dif = i-x

tmp_max_value = 0

for i in range(x, 0, -1):    
    flag = 0
    for j in range(n):
        if i == p[j]:
            flag = 1
    if flag == 1:
        continue

    if tmp_max_value < i:
        tmp_max_value = i
        tmp_max_dif= x-i



if tmp_min_dif < tmp_max_dif:
    print(tmp_min_value)
    exit()
elif tmp_min_dif > tmp_max_dif:
    print(tmp_max_value)
    exit()
else:
    print(min(tmp_min_value, tmp_max_value))

Submission status: Runtime Error

Solution code:
def print_req(before_val,after_val,arr,k,indx):
  if before_val!=arr[indx]-k and arr[indx-k]-k not in arr:
    return arr[indx]-k
  elif after_val!=arr[indx+k]+k and arr[indx+k]+k not in arr:
    return arr[indx]+k
  else:
    return print_req(before_val,after_val,arr,k+1,indx)
x,n=list(map(int,input().split()))
arr=list(map(int,input().split()))
if n==0:
  print(x)
else:
  arr.sort()
  indx=arr.index(x)
  before_val=arr[indx-1]
  after_val=arr[indx+1]
  print_req(before_val,after_val,arr,1,indx)

Submission status: Runtime Error

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

p_list = sorted(p_list)
all_range = list(range(1, 101))
A = [i for i in all_range if i not in p_list]
B = [abs(i - X) for i in A]

low = X - min(B)
high = X + min(B)

output = 0
if high > 100:
  output = low
if low < 1:
  output = high

if N == 0:
  print(X)
elif output != 0:
  print(output)
elif high in p_list:
  print(low)
elif low in p_list:
  print(high)

Submission status: Runtime Error

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

array = [[0]]*100

for i in range(100):
    array[i] = 0
tmp = input().split(' ')
for i in range(n):
    array[int(tmp[i])] += 1
dif_tmp = 999
ret = 999
for i in range(100):
    if array[99-i] == 0:
        if abs(x-(99-i)) <= dif_tmp:
            ret = 99-i
            dif_tmp = abs(x-(99-i))
for i in range(100):
    if abs(x+i) <= dif_tmp:
        ret = -i
        dif_tmp = abs(x+i)
print(ret)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python
# -*- Coding: utf-8 -*-

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

if n == 0:
    print(x)
else:
    p_li.sort()
    pst = p_li.index(x)
    if x not in p_li == True:
        print(x)
    else:
        for i in range(1,100):
            if x - i != p_li[pst - i]:
                print(x - i)
                break;
            elif x + i != p_li[pst + i]:
                print(x + i)
                break;

Submission status: Runtime Error

Solution code:
X,N=map(int,input().split())
l=[]
for i in range(100):
  l.append(i+1)
if N>0:
  p=list(map(int,input().split()))
  l1=[x for x in l if x not in p]
  d=abs(X-l1[0])
if N>0:
  for i in range(N):
    d=min(abs(X-l1[i]),d)
  print(l1[i])
else:
  print(X)

Submission status: Runtime Error

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


if n <= 0:
    print(x)
else:
    p = list(map(int,input().split()))
    q = p
    q.sort()
    p2 = [x for x in range(1,q[-1]+n)]

    p_p2_diff = set(p)^set(p2)
    p_p2_diff_list = list(p_p2_diff)

    min_list = []
    for i in range(len(p_p2_diff_list)):
        val = abs(x - p_p2_diff_list[i])
        min_list.append(val)

    print(p_p2_diff_list[min_list.index(min(min_list))])

Submission status: Runtime Error

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

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

p.sort()
print(p)
for i in range(n):
    if p[i] == x:
        index = i
        break

right = x + 1
for i in p[index + 1:]:
    print(i)
    if i != right:
        print('aaaa')
        print(right)
        break
    right += 1

left = x - 1
for i in reversed(p[:index]):
    print(i)
    if i != left:
        print('bbbb')
        print(left)
        break
    left -= 1

if x - left <= right - x:
    print(left)
else:
    print(right)

Submission status: Runtime Error

Solution code:
X,N = map(int,input().split())
if N > 0:
  p = list(map(int,input().split()))
a = 101
ans = 0
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 a == abs(X - i) and p.count(i) == 0:
    ans = i
    break
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

x,n = [int(i) for i in input().split()]
table = [int(i) for i in input().split()]
table.sort()
min = min(table)

a = np.array(table)
a = a - x
a = np.abs(a)
a = np.sort(a)
#print(a)

for i in range(n):
  if a[0] > 0:
    print(x)
    break
  elif a[i+1]-a[i]>1 and i>0:
    if a[i] > 0 and a[i] == a[i-1]:
      if x-a[i]-1 in b or x-a[i]-1 < min:
        print(x+a[i]+1)
        break
      else:
        print(x-a[i]-1)
        break
    else:
      if x-a[i] in b or x-a[i] < min:
        print(x+a[i])
        break
      else:
        print(x+a[i])
        break

Submission status: Runtime Error

Solution code:
import numpy as np


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

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


if __name__ == "__main__":
    x, n = map(int, input().split())
    if n > 0:
        li = list(map(int, input().split()))
        list = li
        near = getNearestValue(list, x)
        nearn = near
        nearp = near

        while nearn in list:
            nearn = nearn - 1
            while nearp in list:
                nearp = nearp + 1

        if abs(near - nearn) <= abs(near - nearp):
            ans = nearn
        else:
            ans = nearp

        print(ans)
    else:
        print(x)

Submission status: Runtime Error

Solution code:
import math
from sys import stdin

X,N=[int(x) for x in stdin.readline().rstrip().split()]
P=[int(x) for x in stdin.readline().rstrip().split()]
l=[i for i in range(1,101) if i not in P]
abslist = list(map(lambda a:abs(a-X),l))
result = min(abslist)

print(l[abslist.index(result)])

Submission status: Runtime Error

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

array = [[0]]*100

for i in range(100):
    array[i] = 0
tmp = input().split(' ')
for i in range(n):
    array[int(tmp[i])] += 1
dif_tmp = 999
ret = 999
for i in range(100):
    if array[99-i] == 0:
        if abs(x-(99-i)) < dif_tmp:
            ret = 99-i
            dif_tmp = abs(x-(99-i))
for i in range(100):
    if abs(x+i) <= dif_tmp:
        ret = -i
        dif_tmp = abs(x+i)
print(ret)