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()))
    A = [0] * N
    for i in range(N):
        A[i] = abs(l[i] - X)
        S = A.count(0)
        if S == 0:
            print(X)
        else:
            for i in range(1, N):
                S = A.count(N)
                if S == 1:
                    if l.count(X - 1) == 0:
                        print(X - 1)
                        break
                    else:
                        print(X + 1)
                        break
                else:
                    pass
else:
    print(X)


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

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

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

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

else:
    print(X)


X, N = map(int, input().split())
if N > 0:
    l = list(map(int, input().split()))
    A = [0] * N
    for i in range(N):
        A[i] = abs(l[i] - X)
        S = A.count(0)
        if S == 0:
            print(X)
        else:
            for i in range(1, N):
                S = A.count(N)
                if S == 1:
                    if l.count(X + 1) == 1 or l.count(X - 1) == 0:
                        print(X - 1)
                        break
                    else:
                        print(X + 1)
                        break
                else:
                    pass
else:
    print(X)


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

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

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

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

else:
    print(X)
print(A)


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

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

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

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

else:
    print(X)


X, N, *d = map(int, open(0).read().split())
if N == 0:
    print(X)
else:
    ans = -100
    for i in range(102):
        if i not in d and abs(i - X) < abs(ans - X):
            ans = i

    print(ans)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted