Problem p02641 (python)

Fixed submission:
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(x)

        value_left=x-1
        value_right=x+1

        if index!=0:
            index_left=index-1
        if index!=n-1:
            index_right=index+1
        
        if index==0:
            ans=x-1
        elif index==n-1:
            if num_list[index-1]==x-1:
                ans=x+1
            else:
                ans=x-1
        else:
            for i in range(n):
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                elif num_list[index_right]!=value_right:
                    ans=value_right
                    break
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n:
                    index_right=index_right+1
                value_left=value_left-1
                value_right=value_right+1

if n==1:
    ans=x-1

if n==100:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

Buggy submission (verdict: Runtime Error):
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(x)

        value_left=x-1
        value_right=x+1

        if index!=0:
            index_left=index-1
        if index!=n-1:
            index_right=index+1
        
        if index==0:
            ans=x-1
        elif index==n-1:
            if num_list[index-1]==x-1:
                ans=x+1
            else:
                ans=x-1
        else:
            for i in range(n):
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                elif num_list[index_right]!=value_right:
                    ans=value_right
                    break
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n:
                    index_right=index_right+1
                value_left=value_left-1
                value_right=value_right+1

if n==1
    ans=x-1

if n==100:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

Buggy submission (verdict: Runtime Error):
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(x)

        value_left=x-1
        value_right=x+1

        if index!=0:
            index_left=index-1
        if index!=n:
            index_right=index+1
        
        if index==0:
            ans=x-1
        elif index==n:
            if num_list[index_right-1]!=x-1:
                ans=x+1
        else:
            for i in range(n):
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                elif num_list[index_right]!=value_right:
                    ans=value_right
                    break
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n:
                    index_right=index_right+1
                value_left=value_left-1
                value_right=value_right+1

if n==1:
    ans=x-1

if n==100:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

Buggy submission (verdict: Runtime Error):
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(x)

        value_left=x-1
        value_right=x+1

        if index!=0:
            index_left=index-1
        if index!=n:
            index_right=index+1
        
        if index==0:
            ans=x-1
        elif index==n:
            if num_list[index_right-1]!=x-1:
                ans=x+1
        else:
            for i in range(n):
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                elif num_list[index_right]!=value_right:
                    ans=value_right
                    break
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n-1:
                    index_right=index_right+1
                value_left=value_left-1
                value_right=value_right+1

if n==1:
    ans=x-1

if n==100:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

Buggy submission (verdict: Runtime Error):
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(6)
        index_left=index-1
        index_right=index+1
        value_left=x-1
        value_right=x+1
        
        for i in range(n):
            if num_list[index_left]!=value_left:
                ans=value_left
                break
            elif num_list[index_right]!=value_right:
                ans=value_right
                break
            index_left=index_left-1
            index_right=index_right+1
            value_left=value_left-1
            value_right=value_right+1

if n==1:
    ans=x-1

if n==100:
    ans=0

print(ans)

Buggy submission (verdict: Runtime Error):
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0:
    if x in num_list:
        index=num_list.index(6)
        index_left=index-1
        index_right=index+1
        value_left=x-1
        value_right=x+1
        
        for i in range(n):
            if num_list[index_left]!=value_left:
                ans=value_left
                break
            elif num_list[index_right]!=value_right:
                ans=value_right
                break
            index_left=index_left-1
            index_right=index_right+1
            value_left=value_left-1
            value_right=value_right+1

print(ans)

Buggy submission (verdict: Runtime Error):
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0:
    if x in num_list:
        index=num_list.index(6)
        index_left=index-1
        index_right=index+1
        value_left=x-1
        value_right=x+1
        
        for i in range(n):
            if num_list[index_left]!=value_left:
                ans=value_left
                break
            elif num_list[index_right]!=value_right:
                ans=value_right
                break
            index_left=index_left-1
            index_right=index_right+1
            value_left=value_left-1
            value_right=value_right+1

print(ans)

Buggy submission (verdict: Runtime Error):
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if len(num_list)!=0:
    index=num_list.index(6)
    index_left=index-1
    index_right=index+1
    value_left=x-1
    value_right=x+1
    
    for i in range(n):
        if num_list[index_left]!=value_left:
            ans=value_left
            break
        elif num_list[index_right]!=value_right:
            ans=value_right
            break
        index_left=index_left-1
        index_right=index_right+1
        value_left=value_left-1
        value_right=value_right+1

print(ans)