Problem: We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.  Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.  How many combinations of "on" and "off" states of the switches light all the bulbs?

Submission attempts (in order):
import itertools
count =0
ans=0
n,m = map(int,input().split())
pattern = list(itertools.permutations(range(2), n))
#pattern.append([0]*m)
#pattern.append([1]*m)

lists =[]
switches = [1]*n
onoff = [0]*m
for i in range(m):
    lists.append(list(map(int,input().split())))
key_value = list(map(int,input().split()))
for l in pattern:
    switches = list(l)
    print(switches)
    for j in range(m):
        for k in range(int(lists[j][0])):
            if switches[k] == 1:
                count += 1
        if count %2 == key_value[j]:
            onoff[j] = 1
        else:
            break
    if not 0 in onoff:
        ans += 1

print(ans)













import itertools
count =0
ans=0
n,m = map(int,input().split())
pattern = list(itertools.permutations(range(2), n))
pattern.append([0]*m)
pattern.append([1]*m)

lists =[]
switches = [1]*n
onoff = [0]*m
for i in range(m):
    lists.append(list(map(int,input().split())))
key_value = list(map(int,input().split()))
for l in pattern:
    switches = list(l)
    for j in range(m):
        for k in range(int(lists[j][0])):
            if switches[k] == 1:
                count += 1
        if count %2 == key_value[j]:
            onoff[j] = 1
        else:
            break
    if not 0 in onoff:
        ans += 1

print(ans)













import itertools
count =0
ans=0
n,m = map(int,input().split())
pattern = list(itertools.permutations(range(2), n))
pattern.append([0]*n)
pattern.append([1]*n)

lists =[]
switches = [1]*n
onoff = [0]*m
for i in range(m):
    lists.append(list(map(int,input().split())))
key_value = list(map(int,input().split()))
for l in pattern:
    switches = list(l)
    for j in range(m):
        for k in range(int(lists[j][0])):
            if switches[k] == 1:
                count += 1
        if count %2 == key_value[j]:
            onoff[j] = 1
        else:
            break
    if not 0 in onoff:
        ans += 1

print(ans)













import itertools
count =0
ans=0
n,m = map(int,input().split())
pattern = list(itertools.permutations(range(2), n))
pattern.append([0]*m)
pattern.append([1]*m)

lists =[]
switches = [1]*n
onoff = [0]*m
for i in range(m):
    lists.append(list(map(int,input().split())))
key_value = list(map(int,input().split()))
for l in pattern:
    switches = list(l)
    print(switches)
    for j in range(m):
        for k in range(int(lists[j][0])):
            if switches[k] == 1:
                count += 1
        if count %2 == key_value[j]:
            onoff[j] = 1
        else:
            break
    if not 0 in onoff:
        ans += 1

print(ans)













import itertools
count =0
ans=0
n,m = map(int,input().split())
num=[0,1]
pattern = list(itertools.product(num, repeat=n))
lists =[]
switches = [1]*n
onoff = [0]*m
for i in range(m):
    lists.append(list(map(int,input().split())))
key_value = list(map(int,input().split()))
for l in pattern:
    switches = list(l)
    onoff = [0]*m
    for j in range(m):
        count=0
        for k in lists[j][1:]:
            if switches[k-1] == 1:
                count += 1
        if count %2 == key_value[j]:
            onoff[j] = 1
        else:
            break
    if not 0 in onoff:
        ans += 1

print(ans)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Accepted