Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
A = [0] * M
C = [0] * M
for i in range(M):
    a, b = list(map(int, input().split()))
    A[i] = a
    c = list(map(int, input().split()))
    n = ['0'] * N
    for j in range(b):
        n[N-c[j]-2] = '1'
    C[i] = int(''.join(n), 2)

INF = float('inf')

dp = [[INF for i in range(2**N)] for j in range(M+1)]
dp[0][0] = 0

for i in range(1, M+1):
    for j in range(2**N):
        dp[i][j] = dp[i-1][j]

    for j in range(2**N):
        dp[i][j | C[i-1]] = min(dp[i][j | C[i-1]], dp[i-1][j | C[i-1]], dp[i-1][j]+A[i-1])

ans = dp[M][-1]
if ans == INF: ans = -1
print(ans)

Fixed submission:
def main():
    N, M = map(int, input().split())
    INF = float('inf')
    
    L = 2 ** N
    dp = [INF] * L
    dp_next = [INF] * L
    
    nums = [2 ** i for i in range(N)]
    
    for i in range(M):
        a, b = map(int, input().split())
        b = sum([nums[c-1] for c in list(map(int, input().split()))])            
    
        dp[b] = min(dp[b], a)
        for j in range(L):
            n = j | b
            dp_next[n] = min(dp[n], dp_next[n], dp[j]+a)
        
        for j in range(L):
            dp[j] = dp_next[j]
            
    if dp[-1] == INF: print(-1)
    else: print(dp[-1])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy as copy
import sys
input = sys.stdin.readline

def main(): 
    N, M = list(map(int, input().split()))
    n = 2**N

    dp = [float('inf')] * n
    dp[0] = 0

    for i in range(M):
        a, b = list(map(int, input().split()))
        t = 0

        for c in list(map(int, input().split())):
            t += 2**(c-1)

        dp_next = copy(dp)

        for j in range(n):
            dp_next[j|t] = min(dp[j|t], dp_next[j|t], dp[j]+a)

        dp = copy(dp_next)
        
    ans = dp[-1]
    
    if ans == float('inf'): print(-1)
    else: print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N, M = map(int, input().split())
    INF = float('inf')
    
    L = 2 ** N
    dp = [INF] * L
    dp_next = [INF] * L
    
    nums = [2 ** i for i in range(N)]
    
    for i in range(M):
        a, b = map(int, input().split())
        b = sum([nums[c-1] for c in list(map(int, input().split()))])            
    
        dp[b] = min(dp[b], a)
        for j in range(L):
            n = j | b
            dp_next[n] = min(dp[n], dp_next[n], dp[j]+a)
        
        for j in range(L):
            dp[j] = dp_next[j]
            
    if dp[-1] == INF: print(-1)
    else: print(dp[-1])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main(): 
    N, M = list(map(int, input().split()))
    n = 2**N
    dp = [[float('inf') for i in range(n)] for j in range(M+1)]
    for i in range(M+1): dp[i][0] = 0

    for i in range(1, M+1):
        a, b = list(map(int, input().split()))
        t = 0

        for c in list(map(int, input().split())):
            t += 2**(c-1)

        for j in range(n): dp[i][j] = dp[i-1][j]
        for j in range(n):
            dp[i][j | t] = min(dp[i][j | t], dp[i-1][j | t], dp[i-1][j]+a)

    ans = dp[-1][-1]
    if ans == float('inf'): print(-1)
    else: print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N, M = map(int, input().split())
    INF = float('inf')
    
    L = 2 ** N
    dp = [INF] * L
    dp_next = [INF] * L
    
    nums = [2 ** i for i in range(N)]
    
    for i in range(M):
        a, b = map(int, input().split())
        b = sum([nums[c-1] for c in list(map(int, input().split()))])            
    
        dp[b] = min(dp[b], a)
        for j in range(L):
            n = j | b
            dp_next[n] = min(dp[n], dp_next[n], dp[j]+a)
        
        for j in range(L):
            dp[j] = dp_next[j]
            
    if dp[-1] == INF: print(-1)
    else: print(dp[-1])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
n = 2**N
dp = [[float('inf') for i in range(n)] for j in range(M+1)]
for i in range(M+1): dp[i][0] = 0

for i in range(1, M+1):
    a, b = list(map(int, input().split()))
    t = 0

    for c in list(map(int, input().split())):
        t += 2**(c-1)

    for j in range(n): dp[i][j] = dp[i-1][j]
    for j in range(n):
        dp[i][j | t] = min(dp[i][j | t], dp[i-1][j | t], dp[i-1][j]+a)

ans = dp[-1][-1]
if ans == float('inf'): print(-1)
else: print(ans)

Fixed submission:
def main():
    N, M = map(int, input().split())
    INF = float('inf')
    
    L = 2 ** N
    dp = [INF] * L
    dp_next = [INF] * L
    
    nums = [2 ** i for i in range(N)]
    
    for i in range(M):
        a, b = map(int, input().split())
        b = sum([nums[c-1] for c in list(map(int, input().split()))])            
    
        dp[b] = min(dp[b], a)
        for j in range(L):
            n = j | b
            dp_next[n] = min(dp[n], dp_next[n], dp[j]+a)
        
        for j in range(L):
            dp[j] = dp_next[j]
            
    if dp[-1] == INF: print(-1)
    else: print(dp[-1])

if __name__ == '__main__':
    main()