Problem p02641 (python)

Fixed submission:
import numpy as np
lis=[]
for i in range(102):
    lis.append(i)
#print(lis)
listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
#print(listA)
 
X_=listA[0]
X=X_[0]
N=X_[1]
if N!=0:
    P =listA[1]
 
    arr = np.array(lis)
    P_max = max(P)
    P_min = min(P)-1
    arr=arr[arr<=P_max+1]
    arr=arr[arr>=P_min-1]
    lis=arr.tolist()
    for p in P:
        lis.remove(p)
    #print(lis)
    lis_=[]
    for l in lis:
        lis_.append(abs(l-X))
    #print(lis_)
    lis_min=min(lis_)
 
    def my_index(l, x, default=False):
        if x in l:
            return l.index(x)
        else:
            return default
 
    print(lis[my_index(lis_, lis_min)])
else:
    print(X)

Buggy submission (verdict: Runtime Error):
import numpy as np
listA=[]
lis=[]
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
#print(listA)

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

X_=listA[0]
X=X_[0]
N=X_[1]
if N!=0:
    P =listA[1]

    arr = np.array(lis)
    P_max = max(P)
    P_min = min(P)   

    for i in range(P_max+1):
        lis.append(i)
    lis.remove(0)
    
    arr=arr[arr<=P_max]
    arr=arr[arr>=P_min]
    lis=arr.tolist()
    for p in P:
        lis.remove(p)
    #print(lis)
    lis_=[]
    for l in lis:
        lis_.append(abs(l-X))
    #print(lis_)
    lis_min=min(lis_)
    print(lis[my_index(lis_, lis_min)])
else:
    print(X)

Buggy submission (verdict: Runtime Error):
import numpy as np
listA=[]
lis=[]
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
#print(listA)

X_=listA[0]
X=X_[0]
N=X_[1]
if N!=0:
    P =listA[1]

    arr = np.array(lis)
    P_max = max(P)
    P_min = min(P)   

    for i in range(P_max+1):
        lis.append(i)
    lis.remove(0)
    
    arr=arr[arr<=P_max]
    arr=arr[arr>=P_min]
    lis=arr.tolist()
    for p in P:
        lis.remove(p)
    #print(lis)
    lis_=[]
    for l in lis:
        lis_.append(abs(l-X))
    #print(lis_)
    lis_min=min(lis_)

    def my_index(l, x, default=False):
        if x in l:
            return l.index(x)
        else:
            return default

    print(lis[my_index(lis_, lis_min)])
else:
    print(X)

Buggy submission (verdict: Runtime Error):
import numpy as np
lis=[]
for i in range(101):
    lis.append(i)
lis.remove(0)

listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
#print(listA)

X_=listA[0]
X=X_[0]
N=X_[1]
if N!=0:
    P =listA[1]

    arr = np.array(lis)
    P_max = max(P)
    P_min = min(P)
    arr=arr[arr<=P_max]
    arr=arr[arr>=P_min]
    lis=arr.tolist()
    for p in P:
        lis.remove(p)
    #print(lis)
    lis_=[]
    for l in lis:
        lis_.append(abs(l-X))
    #print(lis_)
    lis_min=min(lis_)

    def my_index(l, x, default=False):
        if x in l:
            return l.index(x)
        else:
            return default

    print(lis[my_index(lis_, lis_min)])
else:
    print(X)

Buggy submission (verdict: Runtime Error):
import numpy as np
lis=[]
for i in range(101):
    lis.append(i)
lis.remove(0)

listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
#print(listA)

X_=listA[0]
X=X_[0]
N=X_[1]
if N!=0:
    P =listA[1]

    arr = np.array(lis)
    P_max = max(P)
    P_min = min(P)-1
    arr=arr[arr<=P_max]
    arr=arr[arr>=P_min]
    lis=arr.tolist()
    for p in P:
        lis.remove(p)
    #print(lis)
    lis_=[]
    for l in lis:
        lis_.append(abs(l-X))
    #print(lis_)
    lis_min=min(lis_)

    def my_index(l, x, default=False):
        if x in l:
            return l.index(x)
        else:
            return default

    print(lis[my_index(lis_, lis_min)])
else:
    print(X)