Problem p02641 (python)

Fixed submission:
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))

pN.sort()

diff = 0

if n == 0:
    print(x)
else:
    while(1):
        if x-diff not in pN:
            print(x-diff)
            exit()
        elif x+diff not in pN:
            print(x+diff)
            exit()
        diff+=1

Buggy submission (verdict: Runtime Error):
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
plus_flag = 1
minus_flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
plus_index = key_index
minus_index = key_index

if n == 0:
    print(x)
else:
    while(1):
        if minus_index <= 0:
            minus_flag = 0
            
        if minus_flag == 1:
            if pN[minus_index] - 1 != pN[minus_index-1]:
                print(pN[minus_index] - 1)
                break
            else:
                minus_index = minus_index - 1

        

        if plus_index >= n:
                    plus_flag = 0

        if plus_flag == 1:
            if pN[plus_index] + 1 != pN[plus_index+1]:
                print(pN[plus_index] + 1)
                break
            else:
                plus_index = plus_index + 1

Buggy submission (verdict: Runtime Error):
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
plus_flag = 1
minus_flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
plus_index = key_index
minus_index = key_index
print(key_index)
if n == 0:
    print(x)
else:
    while(1):
        if minus_index <= 0:
            minus_flag = 0
            
        if minus_flag == 1:
            if pN[minus_index] - 1 != pN[minus_index-1]:
                print(pN[minus_index] - 1)
                break
            else:
                minus_index = minus_index - 1

        

        if plus_index >= n:
                    plus_flag = 0

        if plus_flag == 1:
            if pN[plus_index] + 1 != pN[plus_index+1]:
                print(pN[plus_index] + 1)
                break
            else:
                plus_index = plus_index + 1

Buggy submission (verdict: Runtime Error):
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
plus_flag = 1
minus_flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
plus_index = key_index
minus_index = key_index

if n == 0:
    print(x)
else:
    while(1):
        if minus_index <= 0:
            minus_flag = 0
            
        if minus_flag == 1:
            if pN[minus_index] - 1 != pN[minus_index-1]:
                print(pN[minus_index] - 1)
                break
            else:
                minus_index = minus_index + 1

        

        if plus_index == n:
                    plus_flag = 0

        if plus_flag == 1:
            if pN[plus_index] + 1 != pN[plus_index+1]:
                print(pN[plus_index] + 1)
                break
            else:
                plus_index = plus_index + 1

Buggy submission (verdict: Runtime Error):
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
plus_flag = 1
minus_flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
plus_index = key_index
minus_index = key_index
if n == 0:
    print(x)
else:
    while(1):
        if minus_flag == 1:
            if pN[minus_index] - 1 != pN[minus_index-1]:
                print(pN[minus_index] - 1)
                break
            else:
                minus_index = minus_index + 1

        if minus_index == 0:
            minus_flag = 0



        if plus_flag == 1:
            if pN[plus_index] + 1 != pN[plus_index+1]:
                print(pN[plus_index] + 1)
                break
            else:
                plus_index = plus_index + 1

        if plus_index == n:
            plus_flag = 0

Buggy submission (verdict: Runtime Error):
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
plus_flag = 1
minus_flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
plus_index = key_index
minus_index = key_index
if n == 0:
    print(x)
else:
    while(1):
        if minus_flag == 1:
            if pN[key_index] - 1 != pN[key_index-1]:
                print(pN[key_index] - 1)
                break
            else:
                minus_index = minus_index + 1

        if minus_index == 0:
            minus_flag = 0



        if plus_flag == 1:
            if pN[key_index] + 1 != pN[key_index+1]:
                print(pN[key_index] + 1)
                break
            else:
                plus_index = plus_index + 1

        if plus_index == n:
            plus_flag = 0

Buggy submission (verdict: Runtime Error):
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
flag = 1
pN.sort()
key_index = bisect.bisect(pN, x) - 1
if n == 0:
    print(x)
else:
    while(1):
        if pN[key_index] - 1 != pN[key_index-1]:
            print(pN[key_index] - 1)
            break
        if flag == 1:
            if pN[key_index] + 1 != pN[key_index+1]:
                print(pN[key_index] + 1)
                break
        key_index = key_index + 1
        if(key_index >= n):
            flag = 0

Buggy submission (verdict: Runtime Error):
import bisect
x, n = map(int, input().split())
pN = list(map(int, input().split()))
pN.sort()
key_index = bisect.bisect(pN, x) - 1
if n == 0:
    print(x)
else:
    while(1):
        if pN[key_index] - 1 != pN[key_index-1]:
            print(pN[key_index] - 1)
            break

        if pN[key_index] + 1 != pN[key_index+1]:
            print(pN[key_index] + 1)
            break
        key_index = key_index + 1