Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = [0]
C = [0] 
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    c = list(map(int,input().split()))
    x = 0
    for j in range(1,N+1):
        if j in c:
            x += 2**(j-1)
    C.append(x)
inf = 10**9
dp = [inf for i in range(2**N)]
dp[0] = 0
for i in range(1,M+1):
    dp[C[i]] = min(dp[C[i]],A[i])
    for j in range(2**N):
        k =  j|C[i]
        dp[k] = min(dp[k],dp[j]+A[i])
if dp[2**N-1] == inf:
    dp[2**N-1] = -1
print(dp[2**N-1])

Fixed submission:
N,M = map(int,input().split())
A = [0]
C = [0] 
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    c = list(map(int,input().split()))
    x = 0
    for j in range(1,N+1):
        if j in c:
            x += 2**(j-1)
    C.append(x)
inf = 10**9
dp = [inf for i in range(2**N)]
dp[0] = 0
for i in range(1,M+1):
    dp[C[i]] = min(dp[C[i]],A[i])
    for j in range(2**N):
        k =  j|C[i]
        dp[k] = min(dp[k],dp[j]+A[i])
if dp[2**N-1] == inf:
    dp[2**N-1] = -1
print(dp[2**N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = [0]
C = [0] 
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    c = list(map(int,input().split()))
    x = 0
    for j in range(1,N+1):
        if j in c:
            x += 2**(j-1)
    C.append(x)
inf = 10**9
dp = [[inf for i in range(M+1)] for i in range(2**N)]
dp[0][0] = 0
for i in range(2**N):
    for j in range(1,M+1):
        if i - C[j] < 0:
            dp[i][j] = min(dp[i][j-1],dp[i][j])
            continue
        for k in range(0,i+1):
            if k|C[j] == i:
                dp[i][j] = min(dp[i][j],dp[k][j-1]+A[j])
            dp[i][j] = min(dp[i][j],dp[i][j-1])
if dp[2**N-1][M] == inf:
    dp[2**N-1][M] = -1
print(dp[2**N-1][M])

Fixed submission:
N,M = map(int,input().split())
A = [0]
C = [0] 
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    c = list(map(int,input().split()))
    x = 0
    for j in range(1,N+1):
        if j in c:
            x += 2**(j-1)
    C.append(x)
inf = 10**9
dp = [inf for i in range(2**N)]
dp[0] = 0
for i in range(1,M+1):
    dp[C[i]] = min(dp[C[i]],A[i])
    for j in range(2**N):
        k =  j|C[i]
        dp[k] = min(dp[k],dp[j]+A[i])
if dp[2**N-1] == inf:
    dp[2**N-1] = -1
print(dp[2**N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = [0]
C = [0] 
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    c = list(map(int,input().split()))
    x = 0
    for j in range(1,N+1):
        if j in c:
            x += 2**(j-1)
    C.append(x)
inf = 10**9
dp = [[inf for i in range(M+1)] for i in range(2**N)]
dp[0][0] = 0
for i in range(2**N):
    for j in range(1,M+1):
        if i - C[j] < 0:
            dp[i][j] = min(dp[i][j-1],dp[i][j])
            continue
        for k in range(0,i+1):
            if k|C[j] == i:
                dp[i][j] = min(dp[i][j],dp[k][j-1]+A[j])
            dp[i][j] = min(dp[i][j],dp[i][j-1])
if dp[2**N-1][M] == inf:
    dp[2**N-1][M] = -1
print(dp[2**N-1][M])

Fixed submission:
N,M = map(int,input().split())
A = [0]
C = [0] 
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    c = list(map(int,input().split()))
    x = 0
    for j in range(1,N+1):
        if j in c:
            x += 2**(j-1)
    C.append(x)
inf = 10**9
dp = [inf for i in range(2**N)]
dp[0] = 0
for i in range(1,M+1):
    dp[C[i]] = min(dp[C[i]],A[i])
    for j in range(2**N):
        k =  j|C[i]
        dp[k] = min(dp[k],dp[j]+A[i])
if dp[2**N-1] == inf:
    dp[2**N-1] = -1
print(dp[2**N-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [[]]
for i in range(N):
    a = list(map(int,input().split()))
    A.append(a)
ans = 0
n = 0
while n < ((N-1)*N)//2:
    f = []
    ans += 1
    t = 0
    for i in range(1,N+1):
        if i in f:
            continue
        if len(A[i]) > 0:
            a = A[i][0]
        else:
            continue
        if (A[a][0] == i):
            if a not in f:
                A[i].pop(0)
                A[a].pop(0)
                f.append(i)
                f.append(a)
                n += 1
                t = 1
    if t == 0:
        print(-1)
        quit()
print(ans)

Fixed submission:
N,M = map(int,input().split())
A = [0]
C = [0] 
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    c = list(map(int,input().split()))
    x = 0
    for j in range(1,N+1):
        if j in c:
            x += 2**(j-1)
    C.append(x)
inf = 10**9
dp = [inf for i in range(2**N)]
dp[0] = 0
for i in range(1,M+1):
    dp[C[i]] = min(dp[C[i]],A[i])
    for j in range(2**N):
        k =  j|C[i]
        dp[k] = min(dp[k],dp[j]+A[i])
if dp[2**N-1] == inf:
    dp[2**N-1] = -1
print(dp[2**N-1])