Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import math
    N,M=map(int,input().split())
    a=[]
    for i in range(M):
        tmp=list(map(int,input().split()))
        tmpc=list(map(int,input().split()))
        c=0
        for j in range(len(tmpc)):
            c+=2**(tmpc[j]-1)
        tmp[1]=c
        a+=[tmp]


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


    for i in range(1,M):
        dp[i]=dp[i-1]
        for j in range(2**N):
            z,p=a[i][0],a[i][1]
            q=j|p
            dp[i][q]=min(dp[i-1][j]+z,dp[i][q])

    ans=dp[M-1][2**N-1]
    print(ans if ans<10**10 else -1)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N,M=map(int,input().split())
    L=2**N
    dp=[10**10 for i in range(L)]
    dp[0]=0


    for i in range(M):
        a, _ = map(int, input().split())
        key=sum([2**(int(i)-1) for i in input().split()])
        for j in range(L):
                q=j|key
                dp[q]=min(dp[j]+a,dp[q])


    ans=dp[L-1]
    print(ans if ans<10**10 else -1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
L=2**N
dp=[10**10 for i in range(L)]
dp[0]=0


for i in range(M):
    a, _ = map(int, input().split())
    key=sum([2**(int(i)-1) for i in input().split()])
    for j in range(L):
            q=j|key
            dp[q]=min(dp[j]+a,dp[q])


ans=dp[L-1]
print(ans if ans<10**10 else -1)

Fixed submission:
def main():
    N,M=map(int,input().split())
    L=2**N
    dp=[10**10 for i in range(L)]
    dp[0]=0


    for i in range(M):
        a, _ = map(int, input().split())
        key=sum([2**(int(i)-1) for i in input().split()])
        for j in range(L):
                q=j|key
                dp[q]=min(dp[j]+a,dp[q])


    ans=dp[L-1]
    print(ans if ans<10**10 else -1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import numpy
N,M=map(int,input().split())
a=[]
for i in range(M):
    tmp=list(map(int,input().split()))
    tmpc=list(map(int,input().split()))
    c=0
    for j in range(len(tmpc)):
        c+=2**(tmpc[j]-1)
    tmp[1]=c
    a+=[tmp]


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


for i in range(1,M):
    dp[i]=dp[i-1]
    for j in range(2**N):
        if dp[i-1][j]<10**10:
            q=j|a[i][1]
            dp[i][q]=min(dp[i-1][j]+a[i][0],dp[i][q])

ans=dp[M-1][2**N-1]
print(ans if ans<10**10 else -1)

Fixed submission:
def main():
    N,M=map(int,input().split())
    L=2**N
    dp=[10**10 for i in range(L)]
    dp[0]=0


    for i in range(M):
        a, _ = map(int, input().split())
        key=sum([2**(int(i)-1) for i in input().split()])
        for j in range(L):
                q=j|key
                dp[q]=min(dp[j]+a,dp[q])


    ans=dp[L-1]
    print(ans if ans<10**10 else -1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
N,M=map(int,input().split())
a=[]
for i in range(M):
    tmp=list(map(int,input().split()))
    tmpc=list(map(int,input().split()))
    c=0
    for j in range(len(tmpc)):
        c+=2**(tmpc[j]-1)
    tmp[1]=c
    a+=[tmp]


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


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

ans=dp[M-1][2**N-1]
print(ans if ans<10**10 else -1)

Fixed submission:
def main():
    N,M=map(int,input().split())
    L=2**N
    dp=[10**10 for i in range(L)]
    dp[0]=0


    for i in range(M):
        a, _ = map(int, input().split())
        key=sum([2**(int(i)-1) for i in input().split()])
        for j in range(L):
                q=j|key
                dp[q]=min(dp[j]+a,dp[q])


    ans=dp[L-1]
    print(ans if ans<10**10 else -1)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
N,M=map(int,input().split())
a=[]
for i in range(M):
    tmp=list(map(int,input().split()))
    tmpc=list(map(int,input().split()))
    c=0
    for j in range(len(tmpc)):
        c+=2**(tmpc[j]-1)
    tmp[1]=c
    a+=[tmp]


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


for i in range(1,M):
    dp[i]=dp[i-1]
    for j in range(2**N):
        z,p=a[i][0],a[i][1]
        q=j|p
        dp[i][q]=min(dp[i-1][j]+z,dp[i][q])

ans=dp[M-1][2**N-1]
print(ans if ans<10**10 else -1)

Fixed submission:
def main():
    N,M=map(int,input().split())
    L=2**N
    dp=[10**10 for i in range(L)]
    dp[0]=0


    for i in range(M):
        a, _ = map(int, input().split())
        key=sum([2**(int(i)-1) for i in input().split()])
        for j in range(L):
                q=j|key
                dp[q]=min(dp[j]+a,dp[q])


    ans=dp[L-1]
    print(ans if ans<10**10 else -1)

if __name__ == '__main__':
    main()