Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

INF = 10**7
dp = [INF]*2**N
dp[0] = 0
bits = set(0)
for i in range(M):
    a, b = map(int, input().split())
    d = sum((1<< (i - 1)) for i in  map(int, input().split()))
    add_set = set() # i個目の鍵を使ってbitsに新しく追加する分の状態を入れる
    for j in bits:
        jord = j | d
        dp[jord] = min(dp[jord], dp[j] + a)
        add_set.add(jord)
    bits |= add_set
    
if dp[- 1] == INF:
    print(- 1)
else:
    print(dp[- 1])

Fixed submission:
N, M = map(int, input().split())

INF = 10**7
dp = [INF]*2**N
dp[0] = 0

for i in range(M):
    a, b = map(int, input().split())
    d = sum((1<< (i - 1)) for i in  map(int, input().split()))    
    for j in range(2**N):
        jord = j | d
        dp[jord] = min(dp[j] + a, dp[jord])
        
if dp[- 1] == INF:
    print(- 1)
else:
    print(dp[- 1])

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

INF = 10**7
dp = [INF]*2**N
dp[0] = 0

for i in range(M):
    a, b = map(int, input().split())
    c_ls = map(int, input().split())
    #d = sum((1<< (i - 1)) for i in  map(int, input().split()))  
    d = 0
    for c in c:
        d += 2**(c - 1)
    for j in range(2**N):
        jord = j | d
        dp[jord] = min(dp[j] + a, dp[jord])
        
if dp[- 1] == INF:
    print(- 1)
else:
    print(dp[- 1])

Fixed submission:
N, M = map(int, input().split())

INF = 10**7
dp = [INF]*2**N
dp[0] = 0

for i in range(M):
    a, b = map(int, input().split())
    d = sum((1<< (i - 1)) for i in  map(int, input().split()))    
    for j in range(2**N):
        jord = j | d
        dp[jord] = min(dp[j] + a, dp[jord])
        
if dp[- 1] == INF:
    print(- 1)
else:
    print(dp[- 1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, M = map(int, input().split())
inf = 10**9
dp = np.zeros((M + 1, 2**N), dtype = 'int') + inf 
# dp[i][j] := i個目までの鍵を使うときの状態jを実現する最小費用 # 0列目は使わない
# 行 : 0番目の鍵 ~ M - 1番目の鍵
# 列 : 状態0 ~ 2**N - 1

dp[0][0] = 0

for i in range(1, M + 1):
    a, b = map(int, input().split())
    c_ls = map(int, input().split())
    d = 0 # i番目の鍵が開けられる宝箱の状態
    for c in c_ls:
        d += 2**(c - 1)
    for j in range(2**N):
        jord = np.bitwise_or(j, d)
        dp[i][j] = min(dp[i][j], dp[i - 1][j])
        dp[i][jord] = min(dp[i - 1][j] + a, dp[i][jord])
#         if i == 1:
#             print(dp[i][jord], i, jord, j, d, np.bitwise_or(j, d))
        
if dp[M][2**N - 1] == inf:
    print(- 1)
else:
    print(dp[M][2**N - 1])

Fixed submission:
N, M = map(int, input().split())

INF = 10**7
dp = [INF]*2**N
dp[0] = 0

for i in range(M):
    a, b = map(int, input().split())
    d = sum((1<< (i - 1)) for i in  map(int, input().split()))    
    for j in range(2**N):
        jord = j | d
        dp[jord] = min(dp[j] + a, dp[jord])
        
if dp[- 1] == INF:
    print(- 1)
else:
    print(dp[- 1])

Buggy python submission (verdict: Runtime Error):
import copy
N, M = map(int, input().split())

def f(x):
    return int(x) - 1

A = []
#B = []
C = []
for i in range(M):
    a, b = map(int, input().split())
    A.append(a)
    #B.append(b)
    C.append(list(map(f, input().split())))



def rec(cost, still_closed, d):
    """
    初期値
    cost = 0
    still_closed = [1]*N
    d = 0
    """
    if sum(still_closed) == 0:
        return cost
    if d == M:
        return - 1
    still_closed1 = copy.copy(still_closed)
    still_closed2 = copy.copy(still_closed)
    res1 = rec(cost, still_closed1, d + 1)
    for c in C[d]:
        still_closed[c] = 0
    res2 = rec(cost + A[d], still_closed, d + 1)
    if res1 == - 1 or res2 == - 1:
        return max(res1, res2)
    else:
        return min(res1, res2)

print(rec(0, [1]*N, 0))

Fixed submission:
N, M = map(int, input().split())

INF = 10**7
dp = [INF]*2**N
dp[0] = 0

for i in range(M):
    a, b = map(int, input().split())
    d = sum((1<< (i - 1)) for i in  map(int, input().split()))    
    for j in range(2**N):
        jord = j | d
        dp[jord] = min(dp[j] + a, dp[jord])
        
if dp[- 1] == INF:
    print(- 1)
else:
    print(dp[- 1])

Buggy python submission (verdict: Runtime Error):
import copy
N, M = map(int, input().split())

def f(x):
    return int(x) - 1

A = []
#B = []
C = []
for i in range(M):
    a, b = map(int, input().split())
    A.append(a)
    #B.append(b)
    C.append(list(map(f, input().split())))



def rec(cost, still_closed, d):
    """
    初期値
    cost = 0
    still_closed = [1]*N
    d = 0
    """
    if d == M:
        if sum(still_closed) == 0:
            return cost
        else:
            return - 1
    still_closed1 = copy.copy(still_closed)
    still_closed2 = copy.copy(still_closed)
    res1 = rec(cost, still_closed1, d + 1)
    for c in C[d]:
        still_closed[c] = 0
    res2 = rec(cost + A[d], still_closed, d + 1)
    if res1 == - 1 or res2 == - 1:
        return max(res1, res2)
    else:
        return min(res1, res2)

print(rec(0, [1]*N, 0))

Fixed submission:
N, M = map(int, input().split())

INF = 10**7
dp = [INF]*2**N
dp[0] = 0

for i in range(M):
    a, b = map(int, input().split())
    d = sum((1<< (i - 1)) for i in  map(int, input().split()))    
    for j in range(2**N):
        jord = j | d
        dp[jord] = min(dp[j] + a, dp[jord])
        
if dp[- 1] == INF:
    print(- 1)
else:
    print(dp[- 1])