TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
try:
  p = list(map(int, input().split()))
except:
  p = []


l = [0]*100

for i in range(N):
  l[abs(p[i] - X)] += 1

#print(p.index(9))
if N == 0:
  print(X)
else:
  for i in range(N):
    if i == 0:
      if l[0] == 1:
        continue
      else:
        print(X)
        break
    else:
      if l[i] == 0:
        print(X-i)
        break
      elif l[i] == 1:
        try:
          p_index = p.index(X-i)
          print(X+i)
        except:
          print(X-i)
        break

X, N = map(int, input().split())
try:
  p = list(map(int, input().split()))
except:
  p = []


l = [0]*200

for i in range(N):
  l[abs(p[i] - X)] += 1

#print(p.index(9))

if N == 0:
  print(X)
else:
  for i in range(N+1):
    if i == 0:
      if l[0] == 1:
        continue
      else:
        print(X)
        break
    else:
      if l[i] == 0:
        print(X-i)
        break
      elif l[i] == 1:
        try:
          p_index = p.index(X-i)
          print(X+i)
        except:
          print(X-i)
        break

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys

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

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

arr = list(map(int, input().split()))
mainasu = X 
purasu = X 

def saiki():
  mainasu = mainasu - 1
  purasu = purasu + 1
  if X in arr:
    if mainasu in arr:
      if purasu in arr:
        saiki()
      else:
        print(purasu)
    else:
      print(mainasu)
  else:
    print(X)

saiki()

import sys

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

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

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

def saiki():
  mainasu = X - 1
  purasu = X + 1
  if X in arr:
    if mainasu in arr:
      if purasu in arr:
        saiki()
      else:
        print(purasu)
    else:
      print(mainasu)
  else:
    print(X)

saiki()

import sys

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

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

arr = list(map(int, input().split()))
mainasu = X 
purasu = X 

def saiki():
  mainasu - 1
  purasu + 1
  if X in arr:
    if mainasu in arr:
      if purasu in arr:
        saiki()
      else:
        print(purasu)
    else:
      print(mainasu)
  else:
    print(X)

saiki()

import sys

def saiki(l,r,lst):
  if (l - 1) not in lst:
      return (l - 1)
  
  if (r + 1) not in lst:
      return (r + 1)
  
  return saiki(l - 1, r + 1, lst)

def main():
  
  X,N = map(int, input().split())

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

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

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

  print(saiki(X,X,arr))

if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)))


x, n = map(int, input().split())
a = set(map(int, input().split()))
print(min(abs(i-x) for i in range(102) if i not in a))

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


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 1
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) in number_list:
        print(num2)
      else:
        print(num1)
      break
    n += 1
    

a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 0
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) not in number_list and str(num2) not in number_list:
        print(num2)
        break
      if str(num) in number_list:
        print(num2)
      else:
        print(num)
      break
    n += 1

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
a = list(map(int, input().split()))
if a[1] == 0:
    print(a[0])
else:
    b = list(map(int, input().split()))
    ans = 1
    out = 0
    res = abs(a[0] - ans)
    while (ans <= max(b) or abs(a[0] - ans) != res):
        if ans not in b:
            if (abs(a[0] - ans) < res):
                res = abs(a[0] - ans)
                out = ans
                if (out > max(b)):
                    break
        ans += 1
    print(out)

a = list(map(int, input().split()))
if a[1] == 0:
    print(a[0])
else:
    b = list(map(int, input().split()))
    c = []
    out = 0
    res = 10000001
    for i in range(102):
        if i not in b:
            c.append(i)
    for j in c:
        if (abs(j - a[0]) < res):
            res = abs(j - a[0])
            out = j
    print(out)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x,n, = map(int,input().split())
p = list(map(int,input().split()))

i = 0
ans = []
flag = 0
while True:
    if (x + i) not in p:
        ans += [x+i]
        print(ans)
        flag = 1
    if (x - i) not in p:
        ans += [x-i]
        print(ans)
        flag = 1
    if flag == 0:
        i += 1
        print(ans)
    else:
        break

print(min(ans))


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

i = 0
ans = []
flag = 0
while True:
    if (x + i) not in p:
        ans += [x+i]
        flag = 1
    if (x - i) not in p:
        ans += [x-i]
        flag = 1
    if flag == 0:
        i += 1
    else:
        break

print(min(ans))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
input_a= input().split(" ")
X=int(input_a[0])
N=int(input_a[1])
dis=X+3
if N!=0:
  array= input().split(" ")
else:
  array=[0,0]

num=X
num2=-100
for i in range(101-X):

  
  if str(num) not in array:
    dis=abs(X-num)
    num2=X-dis
    num1=num
    if str(num2) not in array:
    	numa=min([num,num2])
    else:
      numa=num1
    break
  num=num+1
    

num=X
i=0
for i in range(dis):
  
  if str(num) not in array:
    
    dis2=abs(X-num)
    num3=X+dis2
    #print(num,dis2,num3)
    if str(num3) not in array:
    	numb=min([num,num3])
    else:
      numb=num
      break
  num=num-1
#print(numa,numb,dis,dis2)
if dis<dis2:
  print(numa)
elif dis==dis2:
  print(numb)
else:
  print(numb)

import math
input_a= input().split(" ")
X=int(input_a[0])
N=int(input_a[1])
dis=X+3
if N!=0:
  array= input().split(" ")
else:
  array=[0,0]

num=X
num2=-100
for i in range(N+1):

  
  if str(num) not in array:
    dis=abs(X-num)
    num2=X-dis
    num1=num
    if str(num2) not in array:
    	numa=min([num,num2])
    else:
      numa=num1
    break
  num=num+1
    

num=X
i=0
for i in range(dis):
  
  if str(num) not in array:
    
    dis2=abs(X-num)
    num3=X+dis2

    if str(num3) not in array:
    	numb=min([num,num3])
    else:
      numb=num
      break
  num=num-1

if dis<dis2:
  print(numa)
elif dis==dis2:
  print(numb)
else:
  print(numb)

import math
input_a= input().split(" ")
X=int(input_a[0])
N=int(input_a[1])
dis=X+3
dis2=100
if N!=0:
  array= input().split(" ")
else:
  array=[0,0]

num=X
num2=-100
for i in range(N+1):

  
  if str(num) not in array:
    dis=abs(X-num)
    num2=X-dis
    num1=num
    if str(num2) not in array:
    	numa=min([num,num2])
    else:
      numa=num1
    break
  num=num+1
    

num=X
i=0
for i in range(dis):
  
  if str(num) not in array:
    
    dis2=abs(X-num)
    num3=X+dis2

    if str(num3) not in array:
    	numb=min([num,num3])
    else:
      numb=num
      break
  num=num-1

if dis<dis2:
  print(numa)
elif dis==dis2:
  print(numb)
else:
  print(numb)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
X, N = map(int, input().split())
P = [int(p) for p in input().split()]
A = X
B = X

while True:
  if B in P:
    B += 1
  else:
    break

while True:
  if A in P:
    A -= 1
  else:
    break


print(min(A, B))

X, N = map(int, input().split())
P = [int(p) for p in input().split()]
A = X
B = X

while True:
  if B in P:
    B += 1
  else:
    break

while True:
  if A in P:
    A -= 1
  else:
    break
a = abs(X - A)
b = abs(X - B)
if a < b:
  print(A)
elif a > b:
  print(B)
else:
  print(min(A, B))



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
str1 = input()
str2 = input()

A = str1.split(" ")
B = str2

res = 0
#print(A[1])
if A[1] == "0":
    res = A[0]
else:
#    print("A[1]!=0")
    B = B.split(" ")
    intB = []
    for i in B:
        intB.append(int(i))
    intB.sort(reverse=True)

    X = int(A[0])
    N = int(A[1])

    res = 0
    diff = 999999

    
    l = list(range(-101, 102))

    
    for i in range(0, N):
        l.pop(intB[i]+101)

    print(l)
    for i in l:
        if 0 == abs(X - int(i)):
            diff = 0
            res = i
            break
        elif diff > abs(X - int(i)):
            diff = abs(X - int(i))
            res = i
#            print(diff, res)


print(res)

str1 = input()
str2 = input()

A = str1.split(" ")
B = str2

res = 0
#print(A[1])
if A[1] == "0":
    res = A[0]
else:
#    print("A[1]!=0")
    B = B.split(" ")
    intB = []
    for i in B:
        intB.append(int(i))
    intB.sort(reverse=True)

    X = int(A[0])
    N = int(A[1])

    res = 0
    diff = 999999

    
    l = list(range(-101, 102))

    
    for i in range(0, N):
        l.pop(intB[i]+101)

 #   print(l)
    for i in l:
        if 0 == abs(X - int(i)):
            diff = 0
            res = i
            break
        elif diff > abs(X - int(i)):
            diff = abs(X - int(i))
            res = i
#            print(diff, res)


print(res)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy

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

a = numpy.abs(list(map(lambda z: z-x,p))).tolist()
print(a)

if n==0 or 0 not in a:
    print(x)
else:
    for i in range(1,n,1):
        if a.count(i) == 2:
            continue
        elif a.count(i) == 1:
            if x+i not in p:
                print(x+i)
                break
        print(x-i)
        break

import numpy

x,n = map(int,input().split())
try:
    p = list(map(int,input().split()))
except EOFError:
    p =[]

a = numpy.abs(list(map(lambda z: z-x,p))).tolist()
if 0 not in a:
    print(x)
else:
    i = 1
    while i <= n:
        if a.count(i) == 2:
            i += 1
            continue
        elif a.count(i) == 1:
            if x+i not in p:
                print(x+i)
                break
        if x > 0:
            print(x-i)
        else:
            print(x+i)
        break

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
else:
  ps = list(map(int, input().split()))
counters = [0 for _ in range(len(ps))]
counters[0] = 1

for i,p in enumerate(ps):
  distance = abs(x - p)
  if distance < len(ps):
    counters[distance] += 1

print(counters)
for i,counter in enumerate(counters):
  if counter == 0:
    print(x-i)
    break
  elif counter == 1:
    if x-i in ps:
      print(x+i)
    else:
      print(x-i)
    break

x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
else:
  ps = list(map(int, input().split()))
counters = [0 for _ in range(len(ps)+1)]
counters[0] = 1

for i,p in enumerate(ps):
  distance = abs(x - p)
  if distance < len(ps):
    counters[distance] += 1

for i,counter in enumerate(counters):
  if counter == 0:
    print(x-i)
    break
  elif counter == 1:
    if x-i in ps:
      print(x+i)
    else:
      print(x-i)
    break

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x, n = map(int,input().split())
if n >0:
    p = list(map(int,input().split()))

    p.sort()
    gap = 10**1000
    ans =10**1000
    for i in p:
        if gap > abs(i-x) :
            ans = i
            gap =abs(i-x)



    print(ans)
else:
    print(x)

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

    p.sort()
    gap = 10**1000
    ans =10**1000
    for i in range(0,1000):
        if not x-i in p:
            print(x-i)
            break
        elif not x+i in p:
            print(x+i)
            break
else:
    print(x)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X, N = map(int, input().split())
d = list(map(int, input().split()))

for n in range(X + 1):
    for m in [-1, 1]:
        l = X + n*m
        if d.count(l) == 0:
            print(l)
            break 

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x,n = map(int,input().split())
if n != 0:
    l = list(map(int,input().split()))
else:
    print(x)
    exit()

if x not in l:
    print(x)
    exit()

tmp = []
for i in range(x-50,x+50):
    tmp.append(i)

ans = []
for j in tmp:
    if j not in l:
        ans.append(j)

tmp1 = 1
for k in ans:
    tmp2 = abs(x-k)
    if tmp2 != 0:
        if tmp1 >= tmp2:
            tmp1 = tmp2

ans2 = []
for m in ans:
    a = abs(m-x)
    if a == tmp1:
        ans2.append(m)

print(min(ans2))

import sys

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

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

tmp = []
for i in range(x-60,x+60):
    tmp.append(i)

ans = []
for j in tmp:
    if j not in l:
        ans.append(j)

tmp1 = 100
for k in ans:
    tmp2 = abs(x-k)
    if tmp2 != 0:
        if tmp1 >= tmp2:
            tmp1 = tmp2

ans2 = []
for m in ans:
    a = abs(m-x)
    if a == tmp1:
        ans2.append(m)

print(min(ans2))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()

if x == 1:
    print(0):
    sys.exit()


if n == 100:
    if x <= 50:
        print(0)
        sys.exit()
    else:
        print(101)
        sys.exit()


nun_list = list(map(int, input().split()))
answer = 0

for i in range(0, 210):
    if nun_list.__contains__(i):
        continue
    else :
        if abs(x - answer) >= abs(x - i):
            if abs(x - answer) == abs(x - i):
                if answer > i:
                    answer = i
            else:
                answer = i
if abs(x - answer) <= abs(x - 0):
    print(answer)
else :
    print(0)

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

nun_list = list(map(int, input().split()))
answer = nun_list[0]
for i in nun_list:
    if abs(x - answer) >= abs(x - i):
        if abs(x - answer) == abs(x - i):
            if answer > i:
                answer = i
        else:
            answer = i
tmp = 0
for i in range(0,1000):
    if not nun_list.__contains__(answer -i):
        tmp = answer -i
        break
    if not nun_list.__contains__(answer + i):
        # print(answer + i)
        tmp = answer + i
        break
print(tmp)
if abs(x - tmp) <= abs(x - 0):
    print(tmp)
else :
    print(tmp)

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

nun_list = list(map(int, input().split()))
answer = nun_list[0]
for i in nun_list:
    if abs(x - answer) >= abs(x - i):
        if abs(x - answer) == abs(x - i):
            if answer > i:
                answer = i
        else:
            answer = i
for i in range(0,1000):
    if not nun_list.__contains__(answer -i):
        print(answer - i)
        sys.exit() 
    if not nun_list.__contains__(answer + i):
        print(answer + i)
        sys.exit()        


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

if x == 1:
    print(0)
    sys.exit()


if n == 100:
    if x <= 50:
        print(0)
        sys.exit()
    else:
        print(101)
        sys.exit()


nun_list = list(map(int, input().split()))
answer = 0

for i in range(0, 210):
    if nun_list.__contains__(i):
        continue
    else :
        if abs(x - answer) >= abs(x - i):
            if abs(x - answer) == abs(x - i):
                if answer > i:
                    answer = i
            else:
                answer = i
if abs(x - answer) <= abs(x - 0):
    print(answer)
else :
    print(0)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = input().split()
n = [int(i) for i in n]
m = input().split()
m = [int(i) for i in m]
 
ans_1 = n[0]
ans_2 = n[0]
 
ans = []
while True:
  	if n[1] == 0:
      ans.append(0)
      
    ans_1 += 1
    ans_2 -= 1
    if not ans_1 in m:
        ans.append(ans_1)
        
    elif not ans_2 in m:
        ans.append(ans_2)
    
    if len(ans) > 0:
        break
        
print(min(ans))

n = input().split()
n = [int(i) for i in n]
m = input().split()
m = [int(i) for i in m]


ans_1 = n[0]
ans_2 = n[0]

ans = []
while True:
  	if n[1] == 0:
      ans.append(0)
      
    ans_1 += 1
    ans_2 -= 1
    if not ans_1 in m:
        ans.append(ans_1)
        
    elif not ans_2 in m:
        ans.append(ans_2)
    
    if len(ans) > 0:
        break
        
print(min(ans))

n = input().split()
n = [int(i) for i in n]
if not n[1] == 0:
	m = input().split()
	m = [int(i) for i in m]
else:
  	m =[0]

ans_1 = n[0]
ans_2 = n[0]
ans = []
while True:
    if n[1] == 0:
        ans.append(n[0])
    if not n[0] in m:
      ans.append(n[0])
    if len(ans) > 0:
        break    
        
    ans_1 += 1
    ans_2 -= 1
    if not ans_1 in m:
        ans.append(ans_1)
    if not ans_2 in m:
        ans.append(ans_2)
    
    
        
print(min(ans))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)


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)

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

if x not in a:
    print(x)
else:
    a.sort()
    idx=a.index(x)
    i=max(idx-1,0)
    j=min(idx+1,n-1)
    d=1
    ans=0
    while(True):
        if(a[i]!=x-d):
            ans=x-d
            break
        else:
            i=max(i-1,0)
        if(a[j]!=x+d):
            ans=x+d
            break
        else:
            j=min(j+1,n-1)
        d+=1
    print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x,n = map(int,input().split())
p = list(map(int,input().split()))

arr = []
incc = []
for i in range(101):
    for j in range(n):
        incc.append(p[j])
    if i in incc:
        continue
    else:
        arr.append(i)
arr.pop(0)
# print(arr)
        
for i in range(1,len(arr)):
    if n == 0:
        print(x)
        break
    elif x in arr:
        print(x)
        break
    elif x-i or x+i in arr:
        if not ((x-i) in arr):
            print(x-i)
            break
        elif not((x+i) in arr):
            print(x+i)
            break

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

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

p = set([int(i) for i in input().split()])

for a in range(110):
    if not((x-a) in p):
        print(x-a)
        exit()
    if not((x+a) in p):
        print(x+a)
        exit()

# arr = []
# incc = []

#     for j in range(n):
#         incc.append(p[j])

#         continue
#     else:
#         arr.append(i)
# arr.pop(0)
# # print(arr)
        

#     if n == 0:
#         print(x)
#         break
#     elif x in arr:
#         print(x)
#         break
#     elif x-i or x+i in arr:

#             print(x-i)
#             break

#             print(x+i)
#             break

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x, n = list(map(int, input().split(" ")))
if n != 0:

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

    p_ = [abs(x - n) for n in p]

    m_p_ = p_.index(min(p_))

    start = p[m_p_]

    for v in range(100):
        a = start - v - 1
        if a not in p:
            ans = a
        b = start + v + 1
        if b not in p:
            if ans > b:
                ans = b
            break
            
else:
    ans = x
    
print(ans)

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

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

    p_ = [abs(x - n) for n in p]

    m_p_ = p_.index(min(p_))

    start = p[m_p_]

    for v in range(100):
        a = start - v - 1
        b = start + v + 1
        if (a not in p) and (b in p):
            ans = a
            break

        elif (a in p) and (b not in p):
            ans = b
            break
            
        elif (a not in p) and (b not in p):
            if a > b:
                ans = b
                break
            else:
                ans = a
                break
                
else:
    ans = x
    
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x, n = map(int,input().split())
p = list(map(int,input().split()))

y = []
z = []
for i in range(n):
    if x - n[i] >= 0:
        y.append(x - n[i])
    else:
        z.append(n[i] - x)



y = sorted(y)
z = sorted(z)

if y[0] == z[0]:
    print(y[0])
elif y[0] > z[0]:
    print(z[0])
else:
    print(y[0])

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

y = []
z = []
for i in range(n):
    if x - p[i] >= 0:
        y.append(x - p[i])
    else:
        z.append(p[i] - x)



y = sorted(y)
z = sorted(z)

if y[0] == z[0]:
    print(y[0])
elif y[0] > z[0]:
    print(z[0])
else:
    print(y[0])

x, n = map(int,input().split())
p = list(map(int,input().split()))
y = 0
z = 0
while y == 0:
    a = x + z
    b = x - z
    if a in p and b in p:
        z += 1
    elif a not in p and b in p:
        print(a)
        y = 4
    elif b not in p:
        print(b)
        y = 5

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x,n = map(int,input().split())

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

p = map(int,input().split())

x1,x2 = x,x
for i in range(1000):
  x1 -= 1
  x2 += 1
  if x1 not in p:
    print(x1)
    exit()
  if x2 not in p:
    print(x2)
    exit()

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

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

p = map(int,input().split())

x1,x2 = x,x
for i in range(1000):
  x1 -= 1
  x2 += 1
  if x1 not in p:
    print(x1)
    exit()
  if x2 not in p:
    print(x2)
    exit()

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

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

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

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

x1,x2 = x,x
for i in range(100):
  x1 -= 1
  x2 += 1
  if x1 not in p:
    print(x1)
    exit()
  if x2 not in p:
    print(x2)
    exit()

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  q=[i-X for i in p]
  qs=set(q)
  print(q)

  for i in range(N):
    if -i not in qs:
      print(X-i)
      break
    elif i not in qs:
      print(X+i)
      break

X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=set(map(int,input().split()))
  for i in range(N+1):
    if X-i not in p:
      print(X-i)
      break
    elif X+i not in p:
      print(X+i)
      break

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X, N = list(map(int, input().split()))
P = list(map(int, input().split()))

min_ = 100
for i in range(0, 102):
    print(i)
    cur = i 
    if cur in P:
        continue
    diff = abs(X - cur)
    if diff < min_:
        min_ = diff

front = X - min_
back = X + min_
if front not in P:
    print(front)
else:
    print(back)

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

min_ = 100
for i in range(0, 102):
    cur = i 
    if cur in P:
        continue
    diff = abs(X - cur)
    if diff < min_:
        min_ = diff

front = X - min_
back = X + min_
if front not in P:
    print(front)
else:
    print(back)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

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

result = []

for i in range(max(p)):
    result.append(i)

ans = set(result)-p
ans1 = 1000000000000

print(ans)

for count, i in enumerate(ans):
    if (ans1 > abs(i-X)):
        ans1 = abs(i-X)
        print(ans1, abs(i-X))
        index = count

print(list(ans)[index])


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

result = []

for i in range(102):
    result.append(i)

ans = set(result)-p
ans1 = 1*10**50


for count, i in enumerate(ans):
    if (ans1 > abs(i-X)):
        ans1 = abs(i-X)
        index = count

print(list(ans)[index])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import bisect
X, N=map(int, input().split())
if N==0:print(X);exit()
p=sorted(list(map(int, input().split())))
#print(p)
m=min(p)-1
M=max(p)+1

#  p.append(i)

m=X;i=0
for i in range(m,min(p)-2,-1):
  if i not in p:break
M=X;j=0
for j in range(M,max(p)+2):
  if j not in p:break

print(min(i,j))


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

m=X;i=0
for i in range(m,min(p)-2,-1):
  if i not in p:break
M=X;j=0
for j in range(M,max(p)+2):
  if j not in p:break
if abs(i-X)==abs(j-X):print(min(i,j))
elif abs(i-X)<abs(j-X):
  print(i)
else:print(j)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X, N = map(int, input().split())
line = list(map(int, input().split()))
notLine = [i for i in range(-100, 201) if i not in line]
left = -1
right = len(notLine)
while abs(right - left) > 1:
    middle = (right + left) // 2
    if notLine[middle] >= X:
        right = middle
    else:
        left = middle
print(notLine[left], notLine[right])
if X - notLine[left] <= notLine[right] - X:
    print(notLine[left])
else:
    print(notLine[right])


X, N = map(int, input().split())
line = list(map(int, input().split()))
notLine = [i for i in range(-100, 201) if i not in line]
left = -1
right = len(notLine)
while abs(right - left) > 1:
    middle = (right + left) // 2
    if notLine[middle] >= X:
        right = middle
    else:
        left = middle
#print(notLine[left], notLine[right])
if X - notLine[left] <= notLine[right] - X:
    print(notLine[left])
else:
    print(notLine[right])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()

p = list(map(int, input().split()))
pp = set(p)
numlist = [i for i in range(-1000, 1000)]
numlistt = set(numlist)
newlist = numlistt - pp
newlistt = list(newlist)
absn = 1000
ans = 1000
 
for i in newlistt:
    if absn > abs(X-i):
        ans = i
        absn = abs(X-i)
    elif absn == abs(X-i) and i < ans:
        ans = i
        absn = abs(X-i)

print(ans)
print(newlistt)

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

p = list(map(int, input().split()))
pp = set(p)
numlist = [i for i in range(-1000, 1000)]
numlistt = set(numlist)
newlist = numlistt - pp
newlistt = list(newlist)
absn = 1000
ans = 1000
 
for i in newlistt:
    if absn > abs(X-i):
        ans = i
        absn = abs(X-i)
    elif absn == abs(X-i) and i < ans:
        ans = i
        absn = abs(X-i)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  ans = []

  for i in range(n-2):
    if x-i not in p:
      ans.append(-i)
      break
    elif x+i not in p:
      ans.append(i)
      break
    else:
      ans.append(-3)
  print(x+ans[0])

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

if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  for j in range(0, int(n/2)+ 2):
    #print(j)
    if x-j not in p:
      print(x-j)
      break
    else:
      if x+j not in p:
        print(x+j)
        break

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys

input = sys.stdin.readline

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

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

import sys

input = sys.stdin.readline

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

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

import sys

input = sys.stdin.readline

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

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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import defaultdict

x,n = map(int,input().split())
if n==0:
    print(x)
else:
    dd = defaultdict(int)
    arr = list(map(int,input().split()))
    for i in range(len(arr)):
        dd[x-arr[i]]+=1
    
    print(dd)

    for i in range(101):
        if dd[i]==0:
            print(x-i)
            break
        elif dd[-i]==0:
            print(x+i)
            break




from collections import defaultdict

x,n = map(int,input().split())
if n==0:
    print(x)
else:
    dd = defaultdict(int)
    arr = list(map(int,input().split()))
    for i in range(len(arr)):
        dd[x-arr[i]]+=1

    for i in range(101):
        if dd[i]==0:
            print(x-i)
            break
        elif dd[-i]==0:
            print(x+i)
            break




Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(100):
    if x + i not in p:
        print(x+i)
    elif x - i not in p:
        print(x-i)

x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n+1):
    c = 10**5
    t = 10**5
    y = 0
    if x + i not in p:
        c = x+i
        y += 1
    if x - i not in p:
        t = x-i
        y += 1
    if y:
        print(min(t,c))
        exit()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def resolve():
    X, N = map(int, input().split())
    P = []
    for i in range(N):
        p = int(input())
        P.append(p)
    plus = 1
    while True:
        if X in P:
            if plus%2 == 1:
                X -= plus
                plus +=1
            else:
                X += plus
                plus += 1
        else:
            print(X)
            exit()
resolve()

def resolve():
    X, N = map(int, input().split())
    P = [int(input()) for _ in range(N)]
    if X in P:
        for j in range(N):
            if X+j in P:
                continue
            else:
                print(X+j)
                exit()
            if X-j in P:
                continue
            else:
                print(X-j)
                exit()
    else:
        print(X)
resolve()

def resolve():
    X, N = map(int, input().split())
    if N != 0:
        P = list(map(int, input().split()))
        if X in P:
            for j in range(1, N):
                if X-j in P:
                    continue
                else:
                    print(X-j)
                    exit()
                if X+j in P:
                    continue
                else:
                    print(X+j)
                    exit()
        else:
            print(X)
    else:
        print(X)
resolve()

def resolve():
    X, N = map(int, input().split())
    P = []
    for i in range(N):
        p = int(input())
        P.append(p)
    plus = 1
    while True:
        if X in P:
            if plus%2 == 1:
                X -= plus
            else:
                X += plus
        else:
            print(X)
            exit()
        plus += 1
resolve()

def resolve():
    X, N = map(int, input().split())
    if N != 0:
        P = list(map(int, input().split()))
        S = []
        for _ in range(0, 102):
            if _ in P:
                continue
            else:
                S.append(_)
        if X in S:
            print(X)
        else:
            for i in range(1, 102):
                if X-i in S:
                    print(X-i)
                    exit()
                elif X+i in S:
                    print(X+i)
                    exit()
    else:
        print(X)
resolve()

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x,n = map(int,input().split())
p = list(map(int,input().split()))
p1 = [i for i in range(0,101)]
for i in p:
    if i in p1:
        p1.remove(i)
ans = 1000

for i in p1:
    if ans >= abs(i-x):
        ans = min(abs(i-x),ans)
        al.append(i)

if len(al) == 0:
    if x < 50:
        print(0)
    else:
        print(101)
elif abs(al[-1]-x) == abs(al[-2]-x):
    print(al[-2])
else:
    print(al[-1])

x,n = map(int,input().split())
p = list(map(int,input().split()))
p1 = [i for i in range(0,102)]
for i in p:
    if i in p1:
        p1.remove(i)
ans = 1000
al = []
for i in p1:
    if ans >= abs(i-x):
        ans = min(abs(i-x),ans)
        al.append(i)

if len(al) == 0:
    if x < 50:
        print(0)
    else:
        print(101)
elif len(al) > 1:
    if abs(al[-1]-x) == abs(al[-2]-x):
        print(al[-2])
    else:
        print(al[-1])
else:
    print(al[-1])

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):

def input2():
	return map(int,input().split())
x,n=input2()
p=sorted(input_array())
q=[0]*102
result=[10000,-1]
for i in range(n):
	q[p[i]]=1
for i in range(102):
	if q[i]==0:
		num=abs(i-x)
		if num<result[0]:
			result=[num,i]
print(result[1])


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


def input_array():
	return list(map(int,input().split()))
  
x,n=input2()
p=sorted(input_array())
q=[0]*102
result=[10000,-1]
for i in range(n):
	q[p[i]]=1
for i in range(102):
	if q[i]==0:
		num=abs(i-x)
		if num<result[0]:
			result=[num,i]
print(result[1])

Verdicts: Runtime Error

Accepted