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:
xn = input().split()
data = input().split()
data_2 = []

x = xn[0] #これに近い値
data.sort() #小さい順

#dataにない値が出るまでxから１引き続ける　１引き続けた値をaとする

a = x-1
while True:
    #check
    for i in range(len(data)):
        if data[i] == a:
            a = a - 1
            break
        else:
            data_2.append(a)
            break
    if a == data_2[0]:
        break

#dataにない値が出るまでxから１足し続ける　１足し続けた値をbとする
b = x + 1
while True:
    #check
    for i in range(len(data)):
        if data[i] == a:
            a = a + 1
            break
        else:
            data_2.append(a)
            break
    if b == data_2[1]:
        break

#aとbの小さい方をprint
if a < b:
    print(a)
else:
    print(b)

Submission status: Runtime Error

Solution code:
# abc171_c.py
# https://atcoder.jp/contests/abc171/tasks/abc171_c

# C - One Quadrillion and One Dalmatians /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# ロジャーは、彼のもとに突如現れた 1000000000000001匹の犬をすべて飼うことを決意しました。
# 犬たちにはもともと 1 から 1000000000000001までの番号がふられていましたが、ロジャーは彼らに以下のルールで名前を授けました。
#     1,2,⋯,26番の番号がついた犬はその順に a,b,...,z と命名されます。
#     27,28,29,⋯,701,702番の番号がついた犬はその順に aa,ab,ac,...,zy,zz と命名されます。
#     703,704,705,⋯,18277,18278番の番号がついた犬はその順に aaa,aab,aac,...,zzy,zzz と命名されます。
#     18279,18280,18281,⋯,475253,475254番の番号がついた犬はその順に aaaa,aaab,aaac,...,zzzy,zzzz と命名されます。
#     475255,475256,⋯    番の番号がついた犬はその順に aaaaa,aaaab,... と命名されます。
#     (以下省略)

# つまり、ロジャーが授けた名前を番号順に並べると:
# a,b,...,z,aa,ab,...,az,ba,bb,...,bz,...,za,zb,...,zz,aaa,aab,...,aaz,aba,abb,...,abz,...,zzz,aaaa,... 
# のようになります。
# ロジャーはあなたに問題を出しました。
# 「番号 Nの犬の名前を答えよ。」

# 制約
#     Nは整数
#     1≤N≤1000000000000001

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N

# 出力
# ロジャーの問題に対する答えを、英小文字のみからなる文字列として出力せよ。

# 入力例 1
# 2

# 出力例 1
# b

# 入力例 2
# 27

# 出力例 2
# aa

# 入力例 3
# 123456789

# 出力例 3
# jjddja


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    alp = 'abcdefghijklmnopqrstuvwxyz'

    # １起点なので一つずらす
    q = N - 1
    result = ''

    # 下１桁ずつ加算
    while True:
        q, mod = divmod(q, 26)
        result = alp[mod] + result
        if q == 0:
            return [result]
        q -= 1

    return ['error']


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['2']
        lines_export = ['b']
    if pattern == 2:
        lines_input = ['27']
        lines_export = ['aa']
    if pattern == 3:
        lines_input = ['123456789']
        lines_export = ['jjddja']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
Q = [i for i in range(1, 101)]
P = list(set(Q) - set(P))
dif = 100
for p in P:
    if abs(X-p) < dif:
        dif = abs(X-p)
        ans = p
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if N == 0:
    ans = X
else:
    for i in range(N):
        if not X - i in p:
            ans = X - i
            break
        elif not X + i in p:
            ans = X + i
            break
        else:
            continue

print(ans)

Submission status: Runtime Error

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

if N == 0:
    ans = X
else:
    for i in range(N):
        if not X - i in p:
            ans = X - i
            break
        elif not X + i in p:
            ans = X + i
            break

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()))
  if N==101:
    if X<=101-X:
      print(0)
    else:
      print(101)
  else:
    a=list(range(1,101))
    b=[1]*100
    c=[]
    for i in a:
      if i in p:
        b[i-1]=0
    for j in range(100):
      if b[j]==1:
        c.append(a[j])
    lower=[i for i in c if i<=X]
    upper=[i for i in c if i>=X]
    if lower==[]:
      print(upper[0])
    elif upper==[]:
      print(lower[-1])
    elif(X-lower[-1])<=(upper[0]-X):
      print(lower[-1])
    else:
      print(upper[0])

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
a=set(map,int(input().split()))
print(min([i for i in range(102) if i not in a],key=lambda y:abs(x-y)))

Submission status: Runtime Error

Solution code:
import numpy as np

x, n = input().split()
P = input().split()
l = list(range(1,101))

for i in range(n+1):
	if P[i] in l:
		l = l.remove(P[i])

def subtract(n):
	return n - x

l2 = map(subtract, l)
arr2 = np.array(l2)
arr2_abs = np.abs(arr2)
arr2_sorted = np.sort(arr2_abs)

f = x - int(arr2_sorted[0])
if 'f' in l:
	print(f)
else:
	print(f+2)

Submission status: Runtime Error

Solution code:
import sys



def check_number(p,numbers):
  for plis in p:
    if plis == numbers:
      return 1
  return 0


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

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


after_ans = X
i = 100


for i in range(X+1,101,1):#前半
  if check_number(p,i) == 0:
    after_ans = i
    after_abs = abs(X-i)
    break

for i in range(X-1,-1,-1):#後半
  if check_number(p,i) == 0:
    before_ans = i
    before_abs = abs(X-i)
    break

if abs(after_abs) == abs(before_abs):
  answer = before_ans
elif abs(after_abs) > abs(before_abs):
  answer = before_ans
else:
  answer = after_ans

print( answer )

Submission status: Runtime Error

Solution code:
import sys



def check_number(p,numbers):
  for plis in p:
    if plis == numbers:
      return 1
  return 0


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

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


after_ans = X
i = 100


for i in range(X+1,100,1):#前半
  if check_number(p,i) == 0:
    after_ans = i
    after_abs = abs(X-i)
    break

for i in range(X-1,0,-1):#後半
  if check_number(p,i) == 0:
    before_ans = i
    before_abs = abs(X-i)
    break

if abs(after_abs) == abs(before_abs):
  answer = before_ans
elif abs(after_abs) > abs(before_abs):
  answer = before_ans
else:
  answer = after_ans

print( answer )

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if n == 0:
    ans = x

d = float('inf')

for i in range(n+1):
    tmpx = x + 1 + n//2 - i
    if not tmpx in p:
        tmpd = abs(x -tmpx) 
        if d >= tmpd:
            d = tmpd
            if ans >= tmpx:
                ans = tmpx

print(ans)

Submission status: Runtime Error

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

if n == 0:
    ans = x

d = float('inf')

for i in range(n+1):
    tmpx = x + 1 + n//2 - i
    if not tmpx in p:
        tmpd = abs(x -tmpx) 
        if d >= tmpd:
            d = tmpd
            if ans > tmpx
                ans = tmpx

print(ans)

Submission status: Runtime Error

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

if n == 0:
    ans = x

d = float('inf')

for i in range(n):
    tmpx = x + n//2 - i
    if not tmpx in p:
        tmpd = abs(x -tmpx) 
        if d >= tmpd:
            d = tmpd
            ans = tmpx

print(ans)

Submission status: Runtime Error

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

d = float('inf')

for i in range(n):
    tmpx = x + n//2 - i
    if not tmpx in p:
        tmpd = abs(x -tmpx) 
        if d >= tmpd:
            d = tmpd
            ans = tmpx

print(ans)

Submission status: Runtime Error

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

d = float('inf')

for i in range(n):
    tmpx = x + n//2 - i
    if not tmpx in p:
        tmpd = abs(x -tmpx) 
        if d >= tmpd:
            d = tmpd
            ans = tmpx

print(ans)

Submission status: Runtime Error

Solution code:
from _typeshed import ReadableBuffer
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

X, N = LI()
P = LI().sort()

# Pに含まれない整数（負も含まれる）で最もXに近くて最小の値を探す

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

elif (X not in P) and (N != 0):
    print(X)
    sys.exit()

else:
    while X in P:
        X = X - 1
    print(X)
    sys.exit()

Submission status: Runtime Error

Solution code:
x,n = map(int,input().split())
l = list(map(int,input().split()))
s = set(l)
o = []
d = {}
for i in range(1,101):
    if i not in s:
        g = abs(i-x)
        o.append(g)
        if g in d:
            h = d[g]
            h.append(i)
            d[g] = h

        else:
            d[g] = [i]

o.sort()
k = o[0]
n = d[k]
n.sort()
print(n[0])

Submission status: Runtime Error

Solution code:
import collections
x, n= map(int, input().split())
P = list(map(int, input().split()))
 
PX = list(map(lambda p: p-x,P))
CPX = collections.Counter(PX)
ans = 0
 
for i in range(100):
  elif CPX[-i] == 0:
    ans = x -i
    break
  elif CPX[i] == 0:
    ans = x +i
    break

print(ans)

Submission status: Runtime Error

Solution code:
import collections
x, n= map(int, input().split())
P = list(map(int, input().split()))
 
PX = list(map(lambda p: p-x,P))
CPX = collections.Counter(PX)
ans = 0
 
for i in range(max(max(P),x)):
  if P == []:
    ans = x
    break
  elif CPX[-i] == 0:
    ans = x -i
    break
  elif CPX[i] == 0:
    ans = x +i
    break

print(ans)

Submission status: Runtime Error

Solution code:
import collections
x, n= map(int, input().split())
P = list(map(int, input().split()))
 
PX = list(map(lambda p: p-x,P))
CPX = collections.Counter(PX)
ans = 0
 
for i in range(max(max(P),x)):
  if P = []:
    ans = x
    break
  elif CPX[-i] == 0:
    ans = x -i
    break
  elif CPX[i] == 0:
    ans = x +i
    break

print(ans)

Submission status: Runtime Error

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

PX = list(map(lambda p: p-x,P))
CPX = collections.Counter(PX)
ans = 0

for i in range(max(max(P),x)):
  if CPX[-i] == 0:
    ans = x -i
    break
  elif CPX[i] == 0:
    ans = x +i
    break

print(ans)

Submission status: Runtime Error

Solution code:
import collections
x, n = map(int,input().split())
P = list(map(int, input().split()))
 
PX = list(map(lambda p: p-x,P))
CPX = collections.Counter(PX)
ans = 0
 
for i in range(max(max(P),x)):
  if CPX[-i] == 0:
    ans = x -i
    break
  elif CPX[i] == 0:
    ans = x +i
    break

print(ans)

Submission status: Runtime Error

Solution code:
import collections
x, n = map(int,input().split())
P = list(map(int, input().split()))
 
PX = list(map(lambda p: p-x,P))
CPX = collections.Counter(PX)
ans = 0
 
for i in range(max(max(P),x)):
  if CPX[-i] == 0:
    ans = x -i
    break
  elif CPX[i] == 0:
    ans = x +i
    break
 
print(ans)

Submission status: Runtime Error

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

PX = list(map(lambda p: p-x,P))
CPX = collections.Counter(PX)
ans = 0

for i in range(max(max(P),x))
  if CPX[-i] == 0:
    ans = x -i
    break
  elif CPX[i] == 0:
    ans = x +i
    break

print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
x, n = map(int, input().split())
if n != 0:
    P = list(map(int, input().split()))
    P = sorted(P)
else:
    P = []

flag = False
ans = []
if x not in P or n == 0:
    ans.append(x)
elif n == 100:
    ans.append(0)
else:
    idx = bisect_left(P, x)
    for i in range(n):
        for_num = P[idx] + i
        bac_num = P[idx] - i
        if for_num not in P:
            ans.append(for_num)
            flag = True
        if bac_num not in P:
            ans.append(bac_num)
            flag = True
        if flag:
            break

print(min(ans))

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
x, n = map(int, input().split())
if n != 0:
    P = list(map(int, input().split()))
    P = sorted(P)
else:
    P = []

flag = False
ans = []
if x not in P or n == 0:
    ans.append(x)
else:
    idx = bisect_left(P, x)
    for i in range(n):
        for_num = P[idx] + i
        bac_num = P[idx] - i
        if for_num not in P:
            ans.append(for_num)
            flag = True
        if bac_num not in P:
            ans.append(bac_num)
            flag = True
        if flag:
            break

print(min(ans))

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
x, n = map(int, input().split())
if n != 0:
    P = list(map(int, input().split()))
    P = sorted(P)
else:
    P = []

flag = False
ans = []
if x not in P or n == 0:
    ans.append(x)
else:
    idx = bisect_left(P, x)
    for i in range(n):
        for_num = P[idx] + 1
        bac_num = P[idx] - 1
        if for_num not in P:
            ans.append(for_num)
            flag = True
        if bac_num not in P:
            ans.append(bac_num)
            flag = True
        if flag:
            break

print(min(ans))

Submission status: Runtime Error

Solution code:
from bisect import bisect
from bisect import insort
 
X,N=list(map(int,input().split()))
if N != 0:
	p=list(map(int,input().split()))
 
	not_list=[]
	for i in range(1,101):
		if i not in p and i != X:
			not_list.append(i)
 
	a=bisect(not_list,X)
	insort(not_list,X)
 
	ans1=not_list[a]-not_list[a-1]
	ans2=not_list[a+1]-not_list[a]
 
	if ans1 < ans2:
		print(not_list[a-1])
	elif ans1 == ans2:
		print(not_list[a-1])
	else:
		print(not_list[a+1])
            
else:
	print(X)

Submission status: Runtime Error

Solution code:
from bisect import bisect
from bisect import insort

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

	not_list=[]
	for i in range(1,101):
		if i not in p:
			not_list.append(i)

		a=bisect(not_list,X)
		insort(not_list,X)

		ans1=not_list[a]-not_list[a-1]
		ans2=not_list[a+1]-not_list[a]

		if ans1 < ans2:
			print(not_list[a-1])
		elif ans1 == ans2:
			print(not_list[a-1])
		else:
			print(not_list[a+1])
            
else:
	print(X)

Submission status: Runtime Error

Solution code:
import bisect
x,n=map(int,input().split())
P=list(map(int,input().split()))
Q=[]
for i in range(1,101):
    if i not in P:
        Q.append(i)

i=bisect.bisect_left(Q,x)

if abs(Q[i-1]-x)>abs(Q[i]-x):
    print(Q[i])
else:
    print(Q[i-1])

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n+1):
	for x in [1,-1]:
		y = n + x*i
		if y not in a:
			print(y)
			exit(1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ls = [0] * 100
for i in range(0, 100):
    ls[i] = i+1

ls_in = [0] * n
if n > 0:
    ls_in = list(map(int, input().split(' ')))
    for i in ls_in:
        ls.remove(i)
    ls.reverse()
    for i in ls:
        min_num = min(abs(x-i), min_num)
        if abs(x-i) == min_num:
            ans = i 
    print(ans)
else:
    print(x)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
X,N = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

if N != 0:
    if X in p:
        sorted_p = sorted(p)

        for x in range(N-1):
            diff = abs(X - sorted_p[x])
            if diff < abs(X-sorted_p[x+1]):
                break
            elif x == N-2 and diff > abs(X-sorted_p[x+1]):
                x = N-1
        
            
        def checknum(d,loweridx,upperidx):
            upper = sorted_p[upperidx]
            lower = sorted_p[loweridx]
            if X-d == lower:
                if X+d == upper:
                    if loweridx == 0:
                        print(X-d-1)
                    elif upperidx == N-1:
                        print(X+d+1)
                    else:
                        checknum(d+1,loweridx-1,upperidx+1)
                elif X-d == lower and X+d != upper:
                    print(X+d)        
            else:
                return print(X-d)

        if x == 0:
            print(X-1)
        elif x == N-1:
            a=1
            while(sorted_p[x-a] == X):
                a += 1
            if sorted_p[x-a] != X-1:
                print(X-1)
            else:
                print(X+1)
        else:
            checknum(1,x-1,x+1)
    else:
        print(X)
else:
    print(X)

Submission status: Runtime Error

Solution code:
X,N = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

if N != 0:
    sorted_p = sorted(p)

    for x in range(N-1):
        diff = abs(X - sorted_p[x])
        if diff < abs(X-sorted_p[x+1]):
            break
        elif x == N-2 and diff > abs(X-sorted_p[x+1]):
            x = N-1
    
        
    def checknum(d,loweridx,upperidx):
        upper = sorted_p[upperidx]
        lower = sorted_p[loweridx]
        if X-d == lower:
            if X+d == upper:
                if loweridx == 0:
                    print(X-d-1)
                elif upperidx == N-1:
                    print(X+d+1)
                else:
                    checknum(d+1,loweridx-1,upperidx+1)
            elif X-d == lower and X+d != upper:
                print(X+d)        
        else:
            return print(X-d)

    if x == 0:
        print(X-1)
    elif x == N-1:
        a=1
        while(sorted_p[x-a] == X):
            a += 1
        if sorted_p[x-a] != X-1:
            print(X-1)
        else:
            print(X+1)
    else:
        checknum(1,x-1,x+1)
elif not(X in sorted_p):
    print(X)
else:
    print(X)

Submission status: Runtime Error

Solution code:
X,N = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

if N != 0:
    sorted_p = sorted(p)

    for x in range(N-1):
        diff = abs(X - sorted_p[x])
        if diff < abs(X-sorted_p[x+1]):
            break
        elif x == N-2 and diff > abs(X-sorted_p[x+1]):
            x = N-1
    
    print(x)
        
    def checknum(d,loweridx,upperidx):
        upper = sorted_p[upperidx]
        lower = sorted_p[loweridx]
        if X-d == lower:
            if X+d == upper:
                if loweridx == 0:
                elif upperidx == N-1:
                else:
                    checknum(d+1,loweridx-1,upperidx+1)
            elif X-d == lower and X+d != upper:
                print(X+d)        
        else:
            return print(X-d)

    if x == 0:
        print(X-1)
    elif x == N-1:
        a=1
        while(sorted_p[x-a] == X):
            a += 1
        if sorted_p[x-a] != X-1:
            print(X-1)
        else:
            print(X+1)
    else:
        checknum(1,x-1,x+1)
elif not(X in sorted_p):
    print(X)
else:
    print(X)

Submission status: Runtime Error

Solution code:
X,N = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

if N != 0:
    sorted_p = sorted(p)
    flag = 0

    for x in range(N-1):
        diff = abs(X - sorted_p[x])
        if diff == 0:
            flag = 1
            break
        if diff <= abs(X-sorted_p[x+1]):
            break

    def checknum(d,loweridx,upperidx):
        upper = sorted_p[upperidx]
        lower = sorted_p[loweridx]
        if X-d == lower:
            if X+d == upper:
                if loweridx == 0:
                    print(X-d-1)
                elif upperidx == N-1:
                    print(X+d+1)
                else:
                    checknum(d+1,loweridx-1,upperidx+1)
            elif X-d == lower and X+d != upper:
                print(X+d)        
        else:
            return print(X-d)

    if not(X in sorted_p):
        print(X)
    elif x == 0:
        print(X-1)
    elif x == N-1:
        a=1
        while(sorted_p[x-a] == X):
            a += 1
        if sorted_p[x] != X-1:
            print(X-1)
        else:
            print(X+1)
    else:
        checknum(1,x-1,x+1)
else:
    print(X)

Submission status: Runtime Error

Solution code:
X,N = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

if N != 0:
    sorted_p = sorted(p)
    flag = 0

    for x in range(N-1):
        diff = abs(X - sorted_p[x])
        if diff == 0:
            flag = 1
            break
        if diff <= abs(X-sorted_p[x+1]):
            break

    def checknum(d,loweridx,upperidx):
        upper = sorted_p[upperidx]
        lower = sorted_p[loweridx]
        if X-d == lower:
            if X+d == upper:
                if loweridx == 0:
                    print(X-d-1)
                elif upperidx == N-1:
                    print(X+d+1)
                else:
                    checknum(d+1,loweridx-1,upperidx+1)
            elif X-d == lower and X+d != upper:
                print(X+d)        
        else:
            return print(X-d)

    if not(X in sorted_p):
        print(X)
    elif x == 0:
        print(X-1)
    elif x == N-1:
        a=1
        while(sorted_p[x-a] == X):
            a -= 1
        if sorted_p[x] != X-1:
            print(X-1)
        else:
            print(X+1)
    else:
        checknum(1,x-1,x+1)
else:
    print(X)

Submission status: Runtime Error

Solution code:
X,N = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

if N != 0:
    sorted_p = sorted(p)
    flag = 0

    for x in range(N-1):
        diff = abs(X - sorted_p[x])
        if diff == 0:
            flag = 1
            break
        if diff <= abs(X-sorted_p[x+1]):
            break

    def checknum(d,loweridx,upperidx):
        upper = sorted_p[upperidx]
        lower = sorted_p[loweridx]
        if X-d == lower:
            if X+d == upper:
                if loweridx == 0:
                    print(X-d-1)
                elif upperidx == N-1:
                    print(X+d+1)
                else:
                    checknum(d+1,loweridx-1,upperidx+1)
            elif X-d == lower and X+d != upper:
                print(X+d)        
        else:
            return print(X-d)

    if not x in sorted_p:
        print(X)
    elif x == 0:
        print(X-1)
    elif x == N-1:
        a=1
        while(sorted_p[x-a] == X):
            a -= 1
        if sorted_p[x] != X-1:
            print(X-1)
        else:
            print(X+1)
    else:
        checknum(1,x-1,x+1)
else:
    print(X)

Submission status: Runtime Error

Solution code:
X,N = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

if N != 0:
    sorted_p = sorted(p)
    flag = 0

    for x in range(N-1):
        diff = abs(X - sorted_p[x])
        if diff == 0:
            flag = 1
            break
        if diff <= abs(X-sorted_p[x+1]):
            break

    def checknum(d,loweridx,upperidx):
        upper = sorted_p[upperidx]
        lower = sorted_p[loweridx]
        if X-d == lower:
            if X+d == upper:
                if loweridx == 0:
                    print(X-d-1)
                elif upperidx == N-1:
                    print(X+d+1)
                else:
                    checknum(d+1,loweridx-1,upperidx+1)
            elif X-d == lower and X+d != upper:
                print(X+d)        
        else:
            return print(X-d)

    checknum(1,x-1,x+1)
else:
    print(X)

Submission status: Runtime Error

Solution code:
X,N = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

if N != 0:
    sorted_p = sorted(p)
    flag = 0

    for x in range(N-1):
        diff = abs(X - sorted_p[x])
        if diff == 0:
            flag = 1
            break
        if diff <= abs(X-sorted_p[x+1]):
            break

    def checknum(d,loweridx,upperidx):
        upper = sorted_p[upperidx]
        lower = sorted_p[loweridx]
        if X-d == lower:
            if X+d == upper:
                checknum(d+1,loweridx-1,upperidx+1)
            elif X-d == lower and X+d != upper:
                print(X+d)        
        else:
            return print(X-d)

    checknum(1,x-1,x+1)
else:
    print(X)

Submission status: Runtime Error

Solution code:
X,N = [int(x) for x in input().split()]
if N == 0:
    print(X)
else:
    p = [int(x) for x in input().split()]

    sorted_p = sorted(p)
    flag = 0

    for x in range(N-1):
        diff = abs(X - sorted_p[x])
        if diff == 0:
            flag = 1
            break
        if diff <= abs(X-sorted_p[x+1]):
            break

    def checknum(d,loweridx,upperidx):
        upper = sorted_p[upperidx]
        lower = sorted_p[loweridx]
        if X-d == lower:
            if X+d == upper:
                checknum(d+1,loweridx-1,upperidx+1)
            elif X-d == lower and X+d != upper:
                print(X+d)        
        else:
            return print(X-d)

    checknum(1,x-1,x+1)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

num = int(input())

qm = 1000000000000001

alf = [chr(i) for i in range(97, 97+26)]
#print(alf)

ans = []
f = False

for i in reversed(range(12)):
    if (num-num//26)//26**i >= 1:
        f = True

    if f:
        ans.append(alf[(num-i)//26**i-1])
        num = num % 26**i
print("".join(ans))

Submission status: Runtime Error

Solution code:
X,N = map(int, input().split())
P = map(list,int(input.split()))
direction = -1
i = 0
while True:
    dist = i * direction

    if not (dist + X in P):
        print(dist + X)
        break
    i += 1
    if direction < 0: direction = 1
    else : direction = -1

Submission status: Runtime Error

Solution code:
import numpy as np
def getNearestValue(Q, num):
    idx = np.abs(np.asarray(Q) - num).argmin()
    return Q[idx]

XN = list(map(int,input().split()))
X = XN[0]
N = XN[1]
if N == 0:
    print(X)
else:
    P = list(map(int,input().split()))
    Q = list(range(1, 101, 1))
    for i in range(0,N):
        Q.remove(P[i])
    print(getNearestValue(Q,X))

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
if N>0:
  P = list(map(int, input().split()))
  P = [i for i in range(-1, 101) if i not in P]
  for i in range(len(P)):
    if abs(X-P[i])<=abs(X-P[i+1]):
      print(P[i])
      break
else:
  print(X)

Submission status: Runtime Error

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

c.sort()
a = c[N-1]
list_c = [0]*(a+1)
for i in c:
  mal = 2
  b = i
  while i<=a:
    list_c[i]+=1
    i = b*mal
    mal+=1
count = 0
for i in c:
  if list_c[i]==1:
    count+=1
print(count)