Problem p02683 (python)

Fixed submission:
from itertools import combinations as co
n,m,x=map(int,input().split())
A=[]
ansl=[]
for i in range(n):
    A.append(list(map(int,input().split())))
for i in range(n):
    for j in range(1,m+1):
        if A[i][j]<x:
            break
        if j==m:
            ansl.append(A[i][0])

if n==1:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()
for i,j in co(range(n),2):
    for k in range(1,m+1):
        if A[i][k]+A[j][k]<x:
            break
        if k==m:
            ansl.append(A[i][0]+A[j][0])
if n==2:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()
for i,j,k in co(range(n),3):
    for l in range(1,m+1):
        if A[i][l]+A[j][l]+A[k][l]<x:
            break
        if l==m:
            ansl.append(A[i][0]+A[j][0]+A[k][0])
if n==3:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()
for h,i,j,k in co(range(n),4):
    for l in range(1,m+1):
        if A[h][l]+A[i][l]+A[j][l]+A[k][l]<x:
            break
        if l==m:
            ansl.append(A[h][0]+A[i][0]+A[j][0]+A[k][0])
if n==4:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()
for g,h,i,j,k in co(range(n),5):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [g,h,i,j,k]]))
if n==5:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()
for f,g,h,i,j,k in co(range(n),6):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [f,g,h,i,j,k]]))
if n==6:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()
for e,f,g,h,i,j,k in co(range(n),7):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [e,f,g,h,i,j,k]]))
if n==7:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()
for d,e,f,g,h,i,j,k in co(range(n),8):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [d,e,f,g,h,i,j,k]]))
if n==8:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()
for c,d,e,f,g,h,i,j,k in co(range(n),9):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [c,d,e,f,g,h,i,j,k]]))
if n==9:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()
for b,c,d,e,f,g,h,i,j,k in co(range(n),10):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [b,c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [b,c,d,e,f,g,h,i,j,k]]))
if n==10:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()
for a,b,c,d,e,f,g,h,i,j,k in co(range(n),11):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [a,b,c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [a,b,c,d,e,f,g,h,i,j,k]]))
if n==11:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()
for a0,a,b,c,d,e,f,g,h,i,j,k in co(range(n),12):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [a0,a,b,c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [a0,a,b,c,d,e,f,g,h,i,j,k]]))
if n==12:
    print(min(ansl) if len(ansl)>0 else "-1")
    quit()

Buggy submission (verdict: Runtime Error):
from itertools import combinations as co
n,m,x=map(int,input().split())
A=[[] for i in range(m)]
ansl=[]
for i in range(n):
    A[i].append(map(int,input().split()))
for i in range(n):
    for j in range(1,m+1):
        if A[i][j]<x:
            break
        if j==m:
            ansl.append(A[i][0])

if n==1:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for i,j in co(range(n),2):
    for k in range(1,m+1):
        if A[i][k]+A[j][k]<x:
            break
        if k==m:
            ansl.append(A[i][0]+A[j][0])
if n==2:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for i,j,k in co(range(n),3):
    for l in range(1,m+1):
        if A[i][l]+A[j][l]+A[k][l]<x:
            break
        if l==m:
            ansl.append(A[i][0]+A[j][0]+A[k][0])
if n==3:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for h,i,j,k in co(range(n),4):
    for l in range(1,m+1):
        if A[h][l]+A[i][l]+A[j][l]+A[k][l]<x:
            break
        if l==m:
            ansl.append(A[h][0]+A[i][0]+A[j][0]+A[k][0])
if n==4:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for g,h,i,j,k in co(range(n),5):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [g,h,i,j,k]]))
if n==5:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for f,g,h,i,j,k in co(range(n),6):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [f,g,h,i,j,k]]))
if n==6:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for e,f,g,h,i,j,k in co(range(n),7):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [e,f,g,h,i,j,k]]))
if n==7:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for d,e,f,g,h,i,j,k in co(range(n),8):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [d,e,f,g,h,i,j,k]]))
if n==8:
    print(min(ansl))
    quit()
for c,d,e,f,g,h,i,j,k in co(range(n),9):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [c,d,e,f,g,h,i,j,k]]))
if n==9:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for b,c,d,e,f,g,h,i,j,k in co(range(n),10):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [b,c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [b,c,d,e,f,g,h,i,j,k]]))
if n==10:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for a,b,c,d,e,f,g,h,i,j,k in co(range(n),11):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [a,b,c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [a,b,c,d,e,f,g,h,i,j,k]]))
if n==11:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()
for a0,a,b,c,d,e,f,g,h,i,j,k in co(range(n),12):
    for l in range(1,m+1):
        if sum([A[alp][l] for alp in [a0,a,b,c,d,e,f,g,h,i,j,k]])<x:
            break
        if l==m:
            ansl.append(sum([A[alp][0] for alp in [a0,a,b,c,d,e,f,g,h,i,j,k]]))
if n==12:
    print(min(ansl) if len(ansl)!>0 else "-1")
    quit()