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: Wrong Answer

Solution code:
import numpy as np
X,N = map(int, input().split())
if N != 0:
  p = list(map(int, input().split()))
  min_val = 1
  max_val = 200
  not_p = [i for i in range(min_val,max_val+1,1)]
  
  for i in range(N):
    not_p.remove(p[i])
  #print(not_p)

  min_val = 101
  out_num = 101
  for i in range(len(not_p)):
    if abs(X-not_p[i]) < min_val:
      min_val = abs(X-not_p[i])
      out_num = not_p[i]
else:
  out_num = 0
print(out_num)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
else:
    p = set(map(int, input().split()))
q = set(range(min(p),max(p)+1,1))
r = q-p
diff = 100
ans = 0
for i in r:
    if diff > abs(X-i):
        diff = abs(X-i)
        ans = i
print(ans)

Submission status: Wrong Answer

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

for i in range(0, 200):
  if (x-i) not in list:
    print(x-i)
    break
  if (x+i) not in list:
    print(x+i)
    break

Submission status: Wrong Answer

Solution code:
# coding:utf-8


def main():
    X, N = map(int, input().split())
    if (N > 0):
        P = list(map(int, input().split()))
        ans = 101
        temp = 101
        for pi in range(0, 102):
            n = abs(pi - X)
            if n < temp and pi != X and not pi in P:
                ans = pi
                temp = n
            elif n == temp and pi != X and not pi in P and pi < ans:
                ans = pi
                temp = n

        print(ans)

    else:
        print(X)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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_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()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
import random
from decimal import Decimal


X, N = [int(x) for x in stdin.readline().rstrip().split()]

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

ans = 10**9
ans1 = [0, 10**9]
for i in range(-100, 101):
    if i not in p:

        if ans > abs(X-i):
            ans = abs(X-i)
            # print(i, abs(X-i))
            if ans1[1] == abs(X-i):
                pass
            else:
                ans1[1] = abs(X-i)
                ans1[0] = i
            # ans1[1] = abs(X-i)
            # if ans1 > i:
            #     ans1 = i
                # print(i)
print(ans1[0])

Submission status: Wrong Answer

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

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

if N == 0:
    print(X)
else:
    for i in range(1, 101):
        if X - i not in p:
            print(X - i)
            break
        elif X + i not in p:
            print(X + i)
            break

Submission status: Wrong Answer

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

ans=101
flg=False
if X not in p:
    print(X)
    flg = True
else:
    for i in range(0,101):
        if i not in p and abs(X-i)<abs(X-ans) and i!=X:
            ans=i
if flg==False:
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

for i in range(1000):
    m = X - ((i//2 +1) * (-1)**i)
    if m not in p:
        print(m)
        break

Submission status: Wrong Answer

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

d=0
while 1:
    d+=1
    if X-d not in  Ps:
        print(X-d)
        break
    elif X+d not in Ps:
        print(X+d)
        break

Submission status: Wrong Answer

Solution code:
X , N = map(int,input().split())
if N == 0:
    print(X)
elif N == 1:
    P = int(input())
    if P == X:
        print(X - 1)
    elif X + 1 == P or X - P > 1:
        print(X - 1)
    else:
        print(X + 1)

else:
    P = list(map(int,input().split()))
    j = 1
    while True:
        if X - j not in P:
            print(X - j)
            break
        if X + j not in P:
            print(X + j)
            break
        j += 1

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
num = list(map(int, input().split()))
asc, dec, val1, val2 = 0, 0, 0, 0

if N == 0:
    print(X)
else:
    for i in range(1, X):
        if i not in num:
            val1 = i
            asc = abs(i - X)

    for i in range(X,100):
        if i not in num:
            val2 = i
            dec = abs(i - X)
            break

    if asc > dec:
        print(val2)
    else:
        print(val1)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
sa = []
num = []
for i in range(-100,101):
    if i in p:
        continue
    sa.append(abs(x-i))
    num.append(i)

print(num[sa.index(min(sa))])

Submission status: Wrong Answer

Solution code:
x, n = [int(i)  for i in input().split()]
if n == 0:
  print(x)
  exit()
p = list(input().split())
p = [int(i) for i in p]

  
s1=1000
s2=1000
i=1

for ii in range(n):
  #print((x+i),(x-i))
  if (x+i) not in p:
    s1 = (x+i)
  if (x-i) not in p:
    s2= (x-i)
  i+=1
  #print(i)
  if s1 != 1000 or s2 != 1000:
    break

if s1 > s2:
  if s2 != 1000:
    print(s2)
  else:
    print(s1)
else:
  if s1 != 1000:
    print(s1)
  else:
    print(s2)

Submission status: Wrong Answer

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

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

abs_list = []

for p in P:
  abs_list.append(np.abs(x-p))
  
if len(abs_list) == 0:
  print(x)
  sys.exit()
   
abs_max = max(abs_list)
for i in range(max(abs_list)+1):
  if abs_list.count(i) == 0:
    print(x-i)
    sys.exit()
  elif abs_list.count(i) == 1 and x+i in P and i !=0:
    print(x-i)
    sys.exit()
  elif abs_list.count(i) == 1 and x-i in P and i != 0:
    print(x+i)
    sys.exit()

Submission status: Wrong Answer

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

kouho = list(range(1, 100 ** 2))


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

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

if (x not in p):
  print(x)
elif abs(kouho[right] - kouho[kouho_num]) > abs(kouho[kouho_num] - kouho[left]):
  print(kouho[left])
elif abs(kouho[right] - kouho[kouho_num]) == abs(kouho[kouho_num] - kouho[left]):
  print(kouho[left])
else:
  print(kouho[right])

Submission status: Wrong Answer

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

    for i in range(x+1, max(p)+2):
        if i not in p:
            ans1 = i
            break
    for i in range(x-1, min(p)-2, -1):
        if i not in p:
            ans2 = i
            break

    if abs(x-ans1) > abs(x-ans2):
        print(ans2)
    elif abs(x-ans1) < abs(x-ans2):
        print(ans1)
    else:
        if ans1 > ans2:
            print(ans2)
        else:
            print(ans1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
if a[1] == 0:
    print(a[0])
else:
    b = list(map(int, input().split()))
    c = []
    b.sort()
    ans = min(b)
    while(ans < max(b)):
        if ans not in b:
            c.append(ans)
        ans += 1
    res = 1000001
    out = 0
    for i in range(len(c)):
        if (abs(c[i] - a[0]) < res):
            res = abs(c[i] - a[0])
            out = c[i]
    print(out)

Submission status: Wrong Answer

Solution code:
import sys
x,n = map(int,input().split())
p = list(map(int,input().split()))
if p.count(x) == 0:
    print(x)
for i in range(1,n+1):
    if i%2 != 0:
        x -= i
    else:
        x += i
    if p.count(x) == 0:
        print(x)
        sys.exit()
    else:
        continue

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = []
sortlist = []
if n == 0:
    print(x)
else:
    p.sort()
    p1 = p[0]
    pn = p[n-1]
    new = [i for i in range(p1-1, pn+1)]
    nolist = set(new) ^ set(p)
    nolist = list(nolist)

    for i in range(0, len(nolist)):
        d = abs(nolist[i] - x)
        sortlist.append(d)

        k = sortlist.index(min(sortlist))
    print(nolist[k])

Submission status: Wrong Answer

Solution code:
def main():
  X, N = map(int, input().split())
  if N == 0:
    return X
  
  P = list(map(int, input().split()))
  
  if X < min(P) or X > max(P):
    return X
  
  delta = []
  for n in range(1, 101):
    if n in P:
      delta.append(float('inf'))
    else:
      delta.append(abs(X - n))
      
  minD = min(delta)
  for i, d in enumerate(delta):
    if d == minD:
      return i + 1


print(main())

Submission status: Wrong Answer

Solution code:
s = input().split()

x = int(s[0])
n = int(s[1])

s = {i for i in range(-1,101)}

p1 = input().split()

p = set()

for i in p1:
    p.add(int(i))

t = s - p

answer = 150

for i in t:
    if (abs(x - abs(int(i))) < abs(x - abs(answer))) or (abs(x - abs(int(i))) == abs(x - abs(answer))) and i < answer:
        answer = int(i)

print(answer)

Submission status: Wrong Answer

Solution code:
X,N = input().split()
f = input()
if f:
    p=[int(x) for x in f.split()]
X,N = int(X), int(N)
mini = 1000
for i in range(1,101):
    error = 0
    for j in range(N):
        if p[j]==i:
            error+=1
           # print('e')
    if error == 0:
        dis = abs(i-X)
        
        if dis<abs(mini-X):
            mini = i
    
#print(p)
print(mini)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
import sys
if n==0:
    _=input()
    print(x)
    sys.exit()
    
p_list=list(map(int,input().split()))
r=list(range(-100,101))
a=list(set(r)-set(p_list))
ans=100000
kkk=100000
for i in a:
    tem=abs(i-x)
    if ans>tem:
        ans=tem
        kkk=i
    
print(kkk)

Submission status: Wrong Answer

Solution code:
import numpy as np
X, N = list(map(int,input().split()))
if N == 0:
  input()
  print(X)
else:
  p_arr = list(map(int,input().split()))
  for i in range(101):
    if not (X in p_arr):
      print(X)
    else:
      if i == 0:
        continue
    lower = (X-i in p_arr)
    upper = (X+i in p_arr)
    if not lower:
      print(X-i)
      break
    else:
      if not upper:
        print(X+i)
        break

Submission status: Wrong Answer

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

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

p.sort()

for i in range(p[0], p[n - 1]):
    if (i not in p) and abs(x - i) < abs(ans - x):
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    X,N=[int(x) for x in input().strip().split(" ")]
    P=list(map(int,input().split()))
    f=0
    if len(P)==0:
        print(X)
    else:
        for i in range(N):
            if X-i not in P:
                print(X-i)
                f=1
            elif X+i not in P:
                print(X+i)
                f=1
            if f==1:
                break
main()

Submission status: Wrong Answer

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

kouho=[]

ans1=ans2=101
flag=0

for i in range(len(p)):
    if x+i not in p:
        ans1=x+i
        flag=1
    if x-i not in p:
        ans2=x-i
        flag=1
    if flag==1:
        break


# print(ans1,ans2)
print(min(ans1,ans2))

Submission status: Wrong Answer

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

A = [0]*101
for i in P:
    A[i] = 1

if A[X] == 0:
    print(X)
    exit()

count = 1
while(1):
    if (X - count) < 101 and (X - count) > 0:
        if A[X - count] == 0:
            print(X - count)
            exit()

    if count > 0:
        count = -count
    else:
        count = -count
        count += 1

Submission status: Wrong Answer

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

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

arr = [0]*101

for i in range(len(P)):
  target=P[i]
  arr[target]=1

near=float('inf')
idx =0
for i in range(len(arr)):
  if arr[i] == 0 and i != 0:
    if near > abs(X-i):
      near = abs(X-i)
      idx = i
print(idx)

Submission status: Wrong Answer

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

def calc():
    x, n = [int(x) for x in input().split()]
    if n == 100:
        print(x)
        return
    elif n == 0:
        q = [x for x in range(1, 101)]
    else:
        p = [int(x) for x in input().split()]
        q = [x for x in range(1, 101) if x not in p]

    diffs = [abs(x - qk) for qk in q]
    mindiff = min(diffs)
    idx = diffs.index(mindiff)
    print(q[idx])

calc()

Submission status: Wrong Answer

Solution code:
# C - Forbidden List

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

for i in range(100):
    a = x-(i+1)
    if a not in p:
        print(a)
        break
    b = x+(i+1)
    if b not in p:
        print(b)
        break

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
if n==0:
    print(x)
else:
    cnt=0
    for i in range(0,100):
        y=x+i
        for j in range(0,n):
            if p[j]-y==0:
                print(y-i)
                cnt+=1
                break
            else:
                continue
        if cnt==1:
            break
        else:
            continue

Submission status: Wrong Answer

Solution code:
c,x = map(int,input().split())
if not x:
    print(c)
    exit()
a = list(map(int,input().split()))
s = list(range(0,105))
for i in a:
    s.remove(i)

diffB = 99999
n = 9999

for i in s:
    if diffB > abs(c-i):
        diffB = abs(c-i)
        n = i
if n < abs((-1)-c):
    print(n)
else:
    print(abs(-1)-c)

Submission status: Wrong Answer

Solution code:
X,N=map(int, input().split())
if(N==0):
  print(X)
  exit()
P=list(map(int, input().split()))
P.sort()
mi=100000000000000
for i in range(1,100):
  if(i in P):
    continue
  mi=min(abs(X-i),mi)
co=X-mi
co2=X+mi
if(X-mi in P):
  print(co2)
else:
  print(co)

Submission status: Wrong Answer

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


def main():
    x, n = [int(i) for i in input().split()]
    p = set([int(i) for i in input().split()])

    for i in range(1, 101):
        left = right = None
        if x - i in p:
            left = True
        if x + i in p:
            right = True

        if left and right:
            continue
        elif not left:
            ans = x + 1
        elif not right:
            ans = x - 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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()
tmp=101
for i in range(-100,101):
	if i in p:
		continue
	if tmp>abs(X-i):
		ans=i
		tmp=abs(X-i)
print(ans)

Submission status: Wrong Answer

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

table = [0 for i in range(100)]
for i in p:
    table[i-1] = 1

mx = 10000
ans = mx
dis = mx
for i in range(len(table)):
    idx = 99-i
    if (table[idx] == 0) and (dis >= abs(idx+1-x)):
        ans = idx+1
        dis = abs(idx+1-x)
if ans == mx:
    if 50 >= x:
        print(0)
    else:
        print(101)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# coding:utf-8


def main():
    X, N = map(int, input().split())
    if (N > 0):
        P = list(map(int, input().split()))
        ans = X
        temp = 101
        for pi in range(0, 102):
            n = abs(pi - X)
            if n < temp and pi != X and not pi in P:
                ans = pi
                temp = n
            elif n == temp and pi != X and not pi in P and pi < ans:
                ans = pi
                temp = n

        print(ans)

    else:
        print(X)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def solution():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    else:
        numList = list(map(int, input().split()))

    try:
        numList.index(x)
        left = x - 1
        right = x + 1
    except:
        print(x)
        return

    while True:
        try:
            if left >= 1:
                numList.index(left)
        except:
            print(left)
            break
        
        try:
            if right <= 100:
                numList.index(right)
        except:
            print(right)
            break
        
        left -= 1
        right += 1

solution()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	x, n = map(int, sys.stdin.readline().split())
	p = list(map(int, sys.stdin.readline().split()))
	p.sort()
	a = [0]*100
	if n == 0:
		print(x)
		exit()
	if n == 100:
		if x <= 50:
			print(-1)
		else:
			print(101)
	for i in range(n):
		a[p[i]-1] = 1
	i = x - 1
	log.print(p, i)
	lower = 0
	while i >= 0:
		log.print(i, a[i])
		if a[i] == 0:
			lower = i + 1
			break
		i -= 1
	i = x - 1
	upper = 0
	while i < 100:
		log.print(i, a[i])
		if a[i] == 0:
			upper = i + 1
			break
		i += 1
	if abs(x - lower) == abs(x - upper):
		print(lower)
		exit()
	if abs(x - lower) < abs(x - upper):
		print(lower)
	else:
		print(upper)

main()

Submission status: Wrong Answer

Solution code:
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()]

ans = 10000
ans_diff = 10000

list_100 = [0] * 100
for i in range(100):
  list_100[i] = i+1
  
list_100.append(-1)
list_100.append(101)
  
live_list = list(set(list_100) - set(p))

for i in live_list:
  diff = abs(X - i)
  if diff < ans_diff:
    ans = i
    ans_diff = diff
  if diff == ans_diff:
    ans = min(ans, i)
 
print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p=sorted(map(int,input().split()))
m=100
ans=X
for i in range(1,101):
    diff=abs(X-i)
    if i not in p and diff<m:
        m=diff
        ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
x,n=map(int,input().split())
if n!=0:
    a=list(map(int,input().split()))
else:
    a=[0]*3
number=[0]*101

for num in range(len(a)):
    number[a[num]]=a[num]
    
counter=0
plus=0
ans=0

while counter==0:
    if number[x-plus]==0:
        counter+=1
        ans=x-plus
    elif number[x+plus]==0:
        counter+=1
        ans=x+plus
    else:
        plus+=1
        if plus>x or plus>(100-x):
            counter+=1
            ans=0

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
elif n==100:
    print(-1)
    exit()
List=list(map(int,input().split()))
num=list(range(0,102))
min_num=1000000000
for i in range(len(List)):
    if num.count(List[i])>=1:
        num.remove(List[i])
for i in range(len(num)):
    if (abs(num[i]-x)<abs(min_num-x)) or (abs(num[i]-x)==abs(min_num-x) and num[i]<min_num):
        min_num=num[i]
print(min_num)

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
array = list(map(int, input().split()))
ans_l = []

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

x  = (N % 2)
if x == 0:
    n = N // 2
else:
    n = N // 2 + 1
i = 1

while i <= n:
    ans_l.append(X - i)
    ans_l.append(X + i)
    i += 1
l = len(array)

for j in range(l):
    try:
        ans_l.remove(array[j])
    except ValueError:
        pass
print(ans_l[0])

Submission status: Wrong Answer

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

    for i in range(x+1, max(p)+2):
        if i not in p:
            ans1 = i
            break
    for i in range(x-1, min(p)-2, -1):
        if i not in p:
            ans2 = i
            break

    if abs(x-ans1) > abs(x-ans2):
        print(ans2)
    elif abs(x-ans1) < abs(x-ans2):
        print(ans1)
    else:
        if ans1 > ans2:
            print(ans2)
        else:
            print(ans1)

Submission status: Wrong Answer

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

if n == 0:  
    p = input()
    print(x)
else:
    p = list(map(int, input().split()))
    max_p = max(p)
    ans = 0
    tmp = 1000

    for i in range(1, 101):
        diff = abs(x - i)
        if i not in p and tmp > diff:
            ans = i
            tmp = diff

    print(ans)

Submission status: Wrong Answer

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

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

for i in range(1, 101):
    i1 = x - i
    i2 = x + i
    if i1 not in p:
        print(i1)
        break
    elif i2 not in p:
        print(i2)
        break
    else:
        continue

Submission status: Wrong Answer

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

ps = list(map(int, input().split()))
if not x in ps:
    print(x)
    quit()

min_near = 0
big_near = 0

m = x
while min_near == 0:
    m -= 1
    if not m in ps:
        min_near = m

b = x
while big_near == 0:
    b += 1
    if not b in ps:
        big_near = b

if min_near < 0:
    min_diff = x - min_near
else:
    min_diff = x + min_near

big_diff = big_near - x

if (min_diff > big_diff):
    print(big_near)
else:
    print(min_near)

Submission status: Wrong Answer

Solution code:
X,N=map(int, input().split())
p=list(map(int, input().split()))
seisuu=[0 for i in range(0,101)]
if N==0:
    print(X)
else:
    for i in range(0,N):
        seisuu[p[i]]=1
    count1=X-1
    count2=X+1
    ans=0
    if seisuu[X]==0:
        print(X)
    else:
        while True:
            if count1>=0 and count2<=100:
                if seisuu[count1]==0:
                    ans=count1
                    break
                elif seisuu[count2]==0:
                    ans=count2
                    break
            else:
                if count1<0:
                    ans=-1
                    break
                elif count2>100:
                    ans=101
                    break
            count1-=1
            count2+=1
        print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

d = 101

for k in p:
    if d > abs(x - k):
        d = abs(x - k)

for i in range(101):
    if not x - (d + i) in p:
        print(x - (d + i))
        sys.exit()
    elif not x + (d + i) in p:
        print(x + (d + i))
        sys.exit()

Submission status: Wrong Answer

Solution code:
x, n = input().split()
x = int(x)
n = int(n)
m = list(map(int,input().split()))
sa = 999
ans = 0

if x in m == False:
    print(x)
    exit()
elif len(m) == 0:
    print(x)
    exit()

for k in range(1,n):
    if m.count((x - k)) == 0 and x - (x - k) < sa:
        sa =  x - (x - k)
        ans = x - k

for l in range(1,300):
    if m.count((x + l)) == 0 and (x+l) - x < sa:
        sa = (x+l) - x
        ans = x + l

print(ans)

Submission status: Wrong Answer

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

result = 100
ans = 0
if n == 0:
    print(x)
else:
    p = list(map(int,input().split()))
    for i in range(1,max(p)+2):
        if p.count(i) == 0:
            if abs(x-i) < result:
                result = abs(x-i)
                ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
try:
  p=list(map(int,input().split()))
except:
  print(x)
  exit()
ans=float('inf')
for i in range(1,101):
  if i not in p:
    ans=min(ans,abs(x-i))
    
    
if x-ans not in p and (x-ans)>0 and (x-ans)<=x:
  print(x-ans)
  
elif x-ans not in p and (x-ans)<=0:
  print(x+ans)

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int,input().split())
    li = list(map(int,input().split()))
    li2 = []
    ans = 0
    for i in range(102):
        check = True
        for j in li:
            if j == i:
                check = False
        if check:
            li2.append(i)
    for i in li2:
        if abs(ans - x) > abs(i - x):
            ans = i
    print(li2)
    print(ans)
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

p,f = x-1,x+1
bans = set(map(int,input().split()))
while True:
    if p not in bans:
        print(p)
        break 
    p -= 1
    
    if f not in bans:
        print(f)
        break 
    f += 1

Submission status: Wrong Answer

Solution code:
import sys
input1 = list(map(int, input().split()))
X = input1[0]
N = input1[1]
p = list(map(int, input().split()))

if p == []:
    print(X)
    sys.exit()

# print(X)
flag = True
diff = 1
# print((X - diff) in p)
while(flag):
    if ((X - diff) in p) == False:
        answer = X - diff
        flag = False
    elif ((X + diff) in p) == False:
        answer = X + diff
        flag = False
    else:
        diff += 1

print(answer)

Submission status: Wrong Answer

Solution code:
x, n = (int(each) for each in input().split())
if n == 0:
    print(x)
else:
    p = [int(each) for each in input().split()]
    candidate = 0
    for i in range(101):
        if i == 0:
            continue
        if i not in p and abs(i-x) < abs(candidate-x):
            candidate = i
            # print('replaced')
    print(candidate)

Submission status: Wrong Answer

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

c = collections.Counter(list)
res1=-1000
res2=-1000

for i in range (0, 100):
  if(c[X+i]==0):
    res1=X+i
    if(c[X-i]==0):
      res2=X-i
    break

if(abs(X-res1)<abs(X-res2)):
  print(res1)
else:
  print(res2)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = []
sortlist = []
if n == 0:
    print(x)
else:
    p.sort()
    p1 = p[0]
    pn = p[n-1]
    new = [i for i in range(p1-1, pn+1)]
    nolist = set(new) ^ set(p)
    nolist = list(nolist)

    for i in range(0, len(nolist)):
        d = abs(nolist[i] - x)
        sortlist.append(d)

        k = sortlist.index(min(sortlist))
        print(nolist[k])

Submission status: Wrong Answer

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
import math
x, n = map(int, input().split())
p = list(map(int, input().split()))

if n == 0:
    print(x)

else:
    max = 0
    i = -1
    while(max == 0):
        i = i + 1
        if p.count(x+i) == 0:
            max = x+i

    min = 0
    j = -1
    while(min == 0):
        j = j + 1
        if p.count(x-j) == 0:
            min = x-j

    if (abs(x-max) < abs(x-min)):
        print(max)
    else:
        print(min)

Submission status: Wrong Answer

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

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

f = [1]*100
sa = 100
ans = 0

for i in p:
    f[i-1] = 0

for i in range(100):
    if f[i] == 1 and sa > abs(i+1-x):
        sa = abs(i+1-x)
        ans = i+1

if ans == 0:
    print(0)
elif sa >= x:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

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

    p_set = set(p_list)
    new_list = []
    for i in range(1, 101):
        if i in p_set:
            pass
        else:
            new_list.append(i)

#    print(new_list)

    min_x = 100 #絶対値の最小
    min_diff = 100
    for x in new_list:
        if abs(x - X) <= min_diff:
            if min_diff == abs(x - X):
                if x < min_x:
                    min_x = x
            else:
                min_x = x
                min_diff = abs(x - X)
            
        else:
            pass
    print(min_x)

Submission status: Wrong Answer

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

antip = set(range(101)) - set(p)

dist = 1000
ans = 1000
for v in antip:
    can = abs(v - X)
    if(can < dist):
        dist = can
        ans = v
    if(can == dist):
        ans = min(ans, v)
print(ans)

Submission status: Wrong Answer

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

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

ans = 1

if N != 0 :
    for i in range(105):
        if p.count(i)==0 :
            if abs(X-i) < abs(X-ans) :
                ans = i
    if X <= abs(X-ans):
        ans = X
    print(ans)
else :
    print(X)

Submission status: Wrong Answer

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

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

l = [0] * 100

for p in P:
    l[p-1] = 1
    
i = 1
while 1:
    if X-i-1 < 0:
        print(0)
        exit()
    elif l[X-i-1] == 0:
        print(X-i)
        exit()
    elif X+i+1 >= 100:
        print(101)
        exit()
    elif l[X+i-1] == 0:
        print(X+i)
        exit()
    i+=1