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

INF = 10 ** 8 + 1
n, m = map(int, input().split())
state_num = 1 << n
key = []
for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    bt = 0
    for e in c:
        bt |= 1 << (e - 1)
    key.append((bt, a))

dp = [INF for _ in range(state_num)]
dp[0] = 0

for i in range(state_num):
    for j in range(m):
        ks, kc = key[j]
        state = i | ks
        cost = dp[i] + kc
        dp[state] = min(dp[state], cost)

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


Fixed submission:
import sys
input = sys.stdin.readline


def main():

    INF = 10 ** 7
    n, m = map(int, input().split())
    state_num = 1 << n
    key = []
    for i in range(m):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))
        bt = 0
        for e in c:
            bt |= 1 << (e - 1)
        key.append((bt, a))

    dp = [INF for _ in range(state_num)]
    dp[0] = 0

    for i in range(state_num):
        for j in range(m):
            ks, kc = key[j]
            state = i | ks
            cost = dp[i] + kc
            dp[state] = min(dp[state], cost)

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


if __name__ == "__main__":
    main()

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

INF = 10 ** 8 + 1
n, m = map(int, input().split())
state_num = 1 << n
key = []
for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    bt = 0
    for e in c:
        bt |= 1 << (e - 1)
    key.append((bt, a))

dp = [INF for _ in range(state_num)]
dp[0] = 0

for i in range(state_num):
    for j in range(m):
        ks, kc = key[j]
        state = i | ks
        cost = dp[i] + kc
        dp[state] = min(dp[state], cost)

if dp[-1] == INF:
    ans = -1
else:
    ans = dp[-1]

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline


def main():

    INF = 10 ** 7
    n, m = map(int, input().split())
    state_num = 1 << n
    key = []
    for i in range(m):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))
        bt = 0
        for e in c:
            bt |= 1 << (e - 1)
        key.append((bt, a))

    dp = [INF for _ in range(state_num)]
    dp[0] = 0

    for i in range(state_num):
        for j in range(m):
            ks, kc = key[j]
            state = i | ks
            cost = dp[i] + kc
            dp[state] = min(dp[state], cost)

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


if __name__ == "__main__":
    main()

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

INF = 10 ** 8 + 1
n, m = map(int, input().split())
state_num = 1 << n
key = []
for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    bt = 0
    for e in c:
        bt |= 1 << (e - 1)
    key.append((bt, a))

dp = [INF for _ in range(state_num)]
dp[0] = 0

for i in range(state_num):
    for j in range(m):
        state = i | key[j][0]
        cost = dp[i] + key[j][1]
        dp[state] = min(dp[state], cost)

if dp[-1] == INF:
    ans = -1
else:
    ans = dp[-1]

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline


def main():

    INF = 10 ** 7
    n, m = map(int, input().split())
    state_num = 1 << n
    key = []
    for i in range(m):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))
        bt = 0
        for e in c:
            bt |= 1 << (e - 1)
        key.append((bt, a))

    dp = [INF for _ in range(state_num)]
    dp[0] = 0

    for i in range(state_num):
        for j in range(m):
            ks, kc = key[j]
            state = i | ks
            cost = dp[i] + kc
            dp[state] = min(dp[state], cost)

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


if __name__ == "__main__":
    main()

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

INF = 10 ** 8 + 1
n, m = map(int, input().split())
key = []
for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    bt = 0
    for e in c:
        bt |= 1 << (e - 1)
    key.append((bt, a))

dp = [INF for _ in range(1 << n)]
dp[0] = 0

for i in range(1 << n):
    for j in range(m):
        state = i | key[j][0]
        cost = dp[i] + key[j][1]
        dp[state] = min(dp[state], cost)

if dp[-1] == INF:
    ans = -1
else:
    ans = dp[-1]

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline


def main():

    INF = 10 ** 7
    n, m = map(int, input().split())
    state_num = 1 << n
    key = []
    for i in range(m):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))
        bt = 0
        for e in c:
            bt |= 1 << (e - 1)
        key.append((bt, a))

    dp = [INF for _ in range(state_num)]
    dp[0] = 0

    for i in range(state_num):
        for j in range(m):
            ks, kc = key[j]
            state = i | ks
            cost = dp[i] + kc
            dp[state] = min(dp[state], cost)

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


if __name__ == "__main__":
    main()

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

n, m = map(int, input().split())
key = []
for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    bt = 0
    for e in c:
        bt |= 1 << (e - 1)
    key.append((bt, a))

dp = [float("inf") for _ in range(1 << n)]
dp[0] = 0

for i in range(1 << n):
    for j in range(m):
        state = i | key[j][0]
        cost = dp[i] + key[j][1]
        dp[state] = min(dp[state], cost)

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

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline


def main():

    INF = 10 ** 7
    n, m = map(int, input().split())
    state_num = 1 << n
    key = []
    for i in range(m):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))
        bt = 0
        for e in c:
            bt |= 1 << (e - 1)
        key.append((bt, a))

    dp = [INF for _ in range(state_num)]
    dp[0] = 0

    for i in range(state_num):
        for j in range(m):
            ks, kc = key[j]
            state = i | ks
            cost = dp[i] + kc
            dp[state] = min(dp[state], cost)

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


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ab = []
c = []
key = []
for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    bt = 0
    for e in c:
        bt |= 1 << (e - 1)
    key.append((bt, a))

dp = [float("inf") for _ in range(1 << n)]
dp[0] = 0

for i in range(1 << n):
    for j in range(m):
        state = i | key[j][0]
        cost = dp[i] + key[j][1]
        dp[state] = min(dp[state], cost)

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

print(ans)


Fixed submission:
import sys
input = sys.stdin.readline


def main():

    INF = 10 ** 7
    n, m = map(int, input().split())
    state_num = 1 << n
    key = []
    for i in range(m):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))
        bt = 0
        for e in c:
            bt |= 1 << (e - 1)
        key.append((bt, a))

    dp = [INF for _ in range(state_num)]
    dp[0] = 0

    for i in range(state_num):
        for j in range(m):
            ks, kc = key[j]
            state = i | ks
            cost = dp[i] + kc
            dp[state] = min(dp[state], cost)

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


if __name__ == "__main__":
    main()