Problem:
 Score : 300 points    Problem Statement 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?      Constraints  1 \leq N, M \leq 10  1 \leq k_i \leq N  1 \leq s_{ij} \leq N  s_{ia} \neq s_{ib} (a \neq b)  p_i is 0 or 1 .  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  M  k_1  s_{11}  s_{12}  ...  s_{1k_1}  :  k_M  s_{M1}  s_{M2}  ...  s_{Mk_M}  p_1  p_2  ...  p_M       Output Print the number of combinations of "on" and "off" states of the switches that light all the bulbs.        Sample Input 1 2 2
2 1 2
1 2
0 1      Sample Output 1 1   Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2 .  Bulb 2 is lighted when there is an odd number of switches that are "on" among the following: Switch 2 .   There are four possible combinations of states of (Switch 1 , Switch 2 ): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1 .       Sample Input 2 2 3
2 1 2
1 1
1 2
0 0 1      Sample Output 2 0   Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2 .  Bulb 2 is lighted when there is an even number of switches that are "on" among the following: Switch 1 .  Bulb 3 is lighted when there is an odd number of switches that are "on" among the following: Switch 2 .   Switch 1 has to be "off" to light Bulb 2 and Switch 2 has to be "on" to light Bulb 3 , but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0 .       Sample Input 3 5 2
3 1 2 5
2 2 3
1 0      Sample Output 3 8

Solution (Python):
N,M = map(int, input().split())
L = [[int(x) for x in input().split()] for _ in range(M)]
P = [int(p) for p in input().split()]


ans = 0
for i in range(2**N, 2**(N+1)):
    b = bin(i)
    temp = [0]*M
    for j in range(3, N+3):
        if b[j] == "1":
            for k in range(M):
                switch = L[k][1:]
                if j-2 in switch:
                    temp[k] += 1
    jud = 0
    for j in range(M):
        if temp[j]%2 != P[j]:
            jud = 1
    if jud == 0:
        ans += 1
        
print(ans)

Solution (Python):

N, M = map(int,input().split())
KS = [list(map(int,input().split())) for i in range(M)]
P = list(map(int,input().split()))

count = 0
for i in range(2 ** N):
    add = True
    for j in range(M):
        k = KS[j]
        cnt = 0
        for s in k[1:]:
            if (1 << (s - 1)) & i > 0 :
                cnt += 1
        if cnt % 2 != P[j]:
            add = False
            break
    if add :
        count += 1
 
print(count)

Solution (Python):
n, m = map(int, input().split())
k = []
s = []
for i in range(m):
    l = list(map(int, input().split()))
    k.append(l[0])
    s.append(l[1:])
p = list(map(int, input().split()))

ans = 0
for bit in range(1<<n):
    q = 1
    for i in range(m):
        sum = 0
        for j in range(k[i]):
            if (bit >> (s[i][j] - 1)) & 1:
                sum += 1
        if sum % 2 != p[i]:
            q = 0
    if q == 1:
        ans += 1

print(ans)

Solution (Python):
N, M = map(int, input().split())
a = [0 for i in range(M)]
for i in range(M):
	k, *s = map(int, input().split())
	for j in range(k):
		a[i] = a[i] | (1 << (s[j] - 1))
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
	ok = True
	for i in range(M):
		x = a[i] & bit
		if bin(x).count("1") % 2 != p[i]:
			ok = False
			break
	if ok:
		ans += 1
print(ans)

Solution (Python):
N, M = map(int, input().split())
lst = []
for i in range(M):
	lst.append(list(map(int, input().split())))
p = list(map(int, input().split()))

suc = 0
for i in range(2**N):
	judge = 1
	s = []
	n = i
	for j in range(N):
		if n >= 2**(N-1-j):
			s.append(1)
			n -= 2**(N-1-j)
		else:
			s.append(0)
	for j in range(M):
		cnt = 0
		for k in range(lst[j][0]):
			if s[N-lst[j][k+1]] == 1:
				cnt += 1
		if cnt%2 != p[j]:
			judge = 0
	if judge == 1:
		suc += 1

print(suc)

Solution (Python):
n,m=map(int,input().split())
s=[]
for _ in range(m):
    s.append(list(map(int,input().split()))[1:])
p=list(map(int,input().split()))

import itertools

cnt=0
for i in itertools.product([0,1],repeat=n):
    tn_arr=[]
    for j in range(m):
        on_cnt=0
        for k in range(len(s[j])):
            on_cnt+=i[s[j][k]-1]
        if on_cnt%2==p[j]:
            tn_arr.append(True)
        else:
            tn_arr.append(False)
    if all(tn_arr):
        cnt+=1

print(cnt)

Solution (Python):

N,M = map(int,input().split())
target = [[num-1 for num in list(map(int,input().split()))[1:]] for _ in range(M)]

judge = list(map(int,input().split()))

cnt = 0

for i in range(2 ** N):


	switches = [0] * M
	for k in range(M):
	
		for j in range(N):
		
			if ((i >> j) & 1) and j in target[k]:
			
			
			
			
				switches[k] += 1

	switches =	[switch % 2 for switch in switches]
	
	if switches == judge:
		cnt += 1
		
print(cnt)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

N,M = map(int,readline().split())
lines = readlines()
S = [list(map(int,line.split()))[1:] for line in lines[:-1]]
P = list(map(int,lines[-1].split()))

answer = 0
for switch in itertools.product([0,1],repeat=N):
    on = sum(sum(switch[x-1] for x in s) % 2 == p for s,p in zip(S,P))
    if on == M:
        answer += 1
print(answer)

Solution (Python):
n, m = map(int, input().split())
k = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
answer = 0


all = [] 
for i in range(0, 2**n):
  all.append(list(str(format(i, 'b').zfill(n))))

for a in all:
  for index in range(len(k)):
    switch_count = 0 
    for switch in k[index]: 
        switch_count+=int(a[switch-1])
    
    if switch_count%2 == p[index]:
      if index == len(k)-1:
      	answer+=1
      continue
    break

print(answer)

Solution (Python):
n, m = map(int, input().split())
k = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
answer = 0


all = [] 
for i in range(0, 2**n):
  all.append(list(str(format(i, 'b').zfill(n))))

for a in all:
  for index in range(len(k)):
    switch_count = 0 
    for switch in k[index]: 
      if a[switch-1] == "1":
        switch_count+=1
      else:
        continue
    
    if switch_count%2 == p[index]:
      if index == len(k)-1:
      	answer+=1
      continue
    break

print(answer)

Solution (Python):
"""
n,m<=10
"""

n,m = map(int, input().split( ))
s = []

for i in range(m):
    sij = list(map(int, input().split( )))
    s.append(sij[1:])

p = list(map(int, input().split( )))

ans = 0

for i in range(2**n):
    flag = True
    for k in range(m):
        tst = 0
        for sm in s[k]:
            tst ^= i>>(sm-1)&1
        if tst^p[k]:
            flag = False
            break
    if flag:
        ans += 1

print(ans)

Solution (Python):
n, m = map(int, input().split())
s = [[int(i) for i in input().split()[1:]] for _ in range(m)]
p = [int(i) for i in input().split()]
c = 0

for i in range(2**n):
    addable = True
    for j in range(m):
        d = sum(2 ** (k - 1) for k in s[j])
        if bin(i & d).count('1') % 2 != p[j]:
            addable = False
            break
    if addable:
        c += 1
print(c)

Solution (Python):
from sys import stdin


def f(s, p, P, i):
    
    
    if len(s) == i:
        return 1 if P == p else 0
    
    
    return f(s, p, P, i + 1) + f(s, p, P ^ s[i], i + 1)


def main():
    lines = stdin.readlines()
    N, M = map(int, lines[0].split())
    sn = [[int(j) for j in i.split()[1:]] for i in lines[1:-1]]
    pn = (int(i) for i in lines[-1].split())
    
    
    s = [0] * N
    for i in range(M):
        for j in sn[i]:
            s[j - 1] |= (1 << i)
    
    
    
    p = 0
    for i, j in enumerate(pn):
        p |= (1 << i) if j == 1 else 0
    print(f(s, p, 0, 0))


main()

Solution (Python):
from sys import stdin

lines = stdin.readlines()
N, M = map(int, lines[0].split())
sn = [[int(j) for j in i.split()[1:]] for i in lines[1:-1]]
pn = (int(i) for i in lines[-1].split())


s = [0] * N
for i in range(M):
    for j in sn[i]:
        s[j - 1] |= (1 << i)


p = 0
for i, j in enumerate(pn):
    p |= (1 << i) if j == 1 else 0


def f(P, i):
    
    
    if len(s) == i:
        return 1 if P == p else 0
    
    
    return f(P, i + 1) + f(P ^ s[i], i + 1)


def main():
    print(f(0, 0))


main()

Solution (Python):
from sys import stdin


def f(s, p, P, i):
    
    
    if len(s) == i:
        return 1 if P == p else 0
    
    
    return f(s, p, P, i + 1) + f(s, p, P ^ s[i], i + 1)


def main():
    lines = stdin.readlines()
    N, M = map(int, lines[0].split())
    sn = [[int(j) for j in i.split()[1:]] for i in lines[1:-1]]
    pn = (int(i) for i in lines[-1].split())
    
    
    s = [0] * N
    for i in range(M):
        for j in sn[i]:
            s[j - 1] |= (1 << i)
    
    
    p = 0
    for i, j in enumerate(pn):
        p |= (1 << i) if j == 1 else 0
    print(f(s, p, 0, 0))


main()

Solution (Python):
n, m = map(int, input().split())
bits = '0b' + '1' * n
s = []

for _ in range(m):
    i = [int(i) for i in input().split()]
    s.append(i[1:])

p = [int(i) for i in input().split()]
c = 0
for i in range(2**n):
    l = bin(i)[2:]
    b = (n - len(l)) * '0' + l
    addable = True
    for h, j in enumerate(s):
        d = 0
        for k in j:
            d += int(b[k - 1])
        if addable:
            addable = d % 2 == p[h]
    if addable:
        c += 1
print(c)

Solution (Python):
from sys import stdin
from itertools import combinations_with_replacement,product

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
p = list(map(int,stdin.readline().rstrip().split()))

hai = [0,1]
hai = list(product(hai, repeat=n))

point = 0

for i in range(len(hai)):
    h = list(hai[i])
    kai = 0
    for j in range(m):
        gou = 0
        for k in range(1,len(li[j])):
            if h[li[j][k]-1] == 1:
                gou += 1
        if p[j] != gou%2:
            kai += 1
    if kai == 0:
        point += 1
print(point)

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    N, M = map(int, lines[0].split())
    print(sum(1
              for i in range(1 << N)
              if sum(1
                     for s, p in zip(
                         (sum(1 << int(j) - 1
                              for j in i.split()[1:])
                          for i in lines[1:-1]),
                         (int(i)
                          for i in lines[-1].split()))
                     if bin(i & s).count("1") % 2 == p) == M))
    return


main()

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    N, M = map(int, lines[0].split())
    print(sum(1
              for i in range(1 << N)
              if sum(1
                     for s, p in zip(
                         (sum(1 << int(j) - 1
                              for j in i.split()[1:])
                          for i in lines[1:-1]),
                         (int(i) for i in lines[-1].split()))
                     if bin(i & s).count("1") % 2 == p) == M))
    return


main()

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    N, M = map(int, lines[0].split())
    print(sum([1
               for i in range(1 << N)
               if sum([1
                       for s, p in zip(
                           [sum(1 << int(j) - 1
                                for j in i.split()[1:])
                            for i in lines[1:-1]], lines[-1].split())
                       if bin(i & s).count("1") % 2 == int(p)]) == M]))
    return


main()

Solution (Python):
n,m = map(int, input().split())
k = [list(map(int, input().split())) for i in range(m)]
p= list(map(int, input().split()))
a=2**n
on=0
cnt=0
light=True
s = [bin(i)[2:] for i in range(a)]
for i in range(a):
    s[i]='0'*(n-len(s[i]))+s[i]
    s[i]=s[i][::-1]
for i in range(a):
    for j in range(m):
        for l in range(1,k[j][0]+1):
            
            if s[i][k[j][l]-1]=='1':
                on+=1
        if on%2!=p[j]:
            light=False
        
        on=0
    if light:
        cnt+=1
    light=True
print(cnt)

Solution (Python):
from numpy import*
n, m = map(int, input().split())
l = []
for i in range(m):
    *a,=map(int,input().split())
    l.append(a[1:])
*p,=map(int,input().split())
ans = 0
for t in range(2**n):
    tmp=array([t>>s&1 for s in range(n)])
    if p==[sum(tmp[array(i)-1])%2for i in l]:
        ans+=1
print(ans)

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    N, M = map(int, lines[0].split())
    X = [sum(1 << int(j) - 1 for j in i.split()[1:]) for i in lines[1:-1]]
    Z = lines[-1].split()
    print(sum([1 for i in range(1 << N) if sum([1 for x, y in zip(X, Z) if bin(i & x).count("1") % 2 == int(y)]) == M]))
    return


main()

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    N, M = map(int, lines[0].split())
    X = [sum(1 << int(j) - 1 for j in i.split()[1:]) for i in lines[1:-1]]
    Z = lines[-1].split()
    ans = 0
    for i in range(1 << N):
        tmp = 0
        for x, y in zip(X, Z):
            if bin(i & x).count("1") % 2 == int(y):
                tmp += 1
        if tmp == M:
            ans += 1
    print(ans)

    return


main()

Solution (Python):
from __future__ import print_function


import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )



import random


def main():
    
    n,m = map(int, input().split())
    
    k=[0 for i in range(m)]     
    
    
    S=[ [] for i in range(m)]
    
    

    
    for i in range(m):
        l = list(map(int, input().split()))
        k[i] = l[0]
        ll=l[1:]
        for j in range(len(ll)):
            ll[j]=ll[j]-1
        S[i] = ll
    p = list(map(int, input().split()))

    
    eprint()
    
    eprint("num of Switch : " + str(n) + "    num of Light : " + str(m))
    for i in range(m):
        
        eprint("k[%d]: %d      S[%d]: " % (i,k[i],i ) + str(S[i]) )
    eprint("p: "+ str(p))

    
    cnt_state_whereLightIsTurnedOn=0
    
    for state in range(2**n):   
        failure_flag=0
        for index in range(m):  
            cnt=0
            for i in range(k[index]): 
                if (state>>S[index][i] & 1)==1 :
                    cnt+=1
                    
            if cnt%2==p[index]:
                
                
                continue
            else:
                failure_flag=1
                break
                
        if failure_flag==0:
            cnt_state_whereLightIsTurnedOn+=1
        else:
            continue
        
    print(cnt_state_whereLightIsTurnedOn)
    return

if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
s=[list(map(int,input().split()))for i in range(m)]
for i in range(m):
    del s[i][0]
p=list(map(int, input().split()))
q=[0]*11


ans=0
while(True):
    for i in range(n):
        if(q[i]==2):
            q[i+1]+=1
            q[i]=0
    if(q[n]==1):
        break
    
    flag=1
    for i in range(m):
        tmp=0
        for j in s[i]:
            tmp+=q[j-1]
        if(tmp%2!=p[i]):
            flag=0
            break
    if(flag==1):
        ans+=1
    q[0]+=1

print(ans)

Solution (Python):
n,m=map(int,input().split())
ks=[[int(i) for i in input().split()] for j in range(m)]
p=[int(i) for i in input().split()]

ans=0
for i in range(2**n):
    for j in range(m):
        k=ks[j][0]
        s=ks[j][1:]
        pid=p[j]
        check=0

        for x in s:
            if i >>(x-1) &1:
                check+=1
        if pid == check%2:
            continue
        else:
            break
    else:
        ans+=1
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(200000)


def a(l2,x):
    l3=l2[:]
    if x==n+1:
        for j in l2:
            if j%2==1:
                return 0
        return 1
    for i in sw_l[x]:
        l3[i-1]+=1
    return a(l2,x+1)+a(l3,x+1)







n,m=map(int,input().split())
sw_l=[[] for _ in range(n+1)]
for i in range(1,m+1):
    l=list(map(int,input().split()))
    for j in l[1:]:
        sw_l[j].append(i)
p=list(map(int,input().split()))
ans=a(p,1)
print(ans)

Solution (Python):


N, M = map(int,input().split())
S = [list(map(int,input().split()))[1:] for _ in range(M)]
P = list(map(int,input().split()))

ans = 0

for mask in range(1<<N):
    flag = True
    for i in range(M):
        cnt = 0
        for j in S[i]:
            if (mask >> (j-1)) & 1:
                cnt += 1
        flag &= (cnt % 2) == P[i]
    if flag:
        ans += 1

print(ans)

Solution (Python):
n, m = map(int, input().split())
k = []
s = [[] for _ in range(m)]
for i in range(m):
    line = list(map(int, input().split()))
    k.append(line[0])
    for j in range(len(line)-1):
        s[i].append(line[j+1])
p = list(map(int, input().split()))

def make(n):
    lists = []
    for i in range(2**n):
        str = format(i,"10b")
        bitlist = list(reversed(str.replace(" ", "0")))
        lists.append(bitlist)
    return lists
count = 0

for switch in make(n):
    flag = 0
    for i in range(m):
        sum = 0
        for j in range(k[i]):
            sum += int(switch[s[i][j]-1])
        if sum % 2 != p[i]:
            flag = 1
    if flag == 0:
        count += 1
print(count)

Solution (Python):
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
*p,=map(int,input().split())
a=0
for i in range(2**n):
    a+=all(sum((i>>(k-1))&1 for k in s[j][1:])%2==p[j] for j in range(m))
print(a)

Solution (Python):
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split())) 
ans=0
for i in range(2**n):
    b=0
    for j in range(m):
        a=0
        for k in s[j][1:]:
            if (i>>(k-1))&1:
                a+=1
        if a%2==p[j]:
            a+=1
            b+=1
    if b==m:        
        ans+=1
print(ans)

Solution (Python):
from functools import reduce

N, M = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))

t = [reduce(lambda x, y: x | (1 << (y - 1)), e, 0) for e in s]
result = 0
for i in range(2 ** N):
    for j in range(M):
        if (bin(i & t[j]).count('1') & 1) != p[j]:
            break
    else:
        result += 1
print(result)

Solution (Python):
N,M = map(int,input().split())
ks = [list(map(int,input().split())) for _ in range(M)]
p = list(map(int,input().split()))

ans = 0

for i in range(2**N):
    switch = [0]*N
    
    for j in range(N):
        if (i>>j & 1):
            switch[j] = 1
    
    n_on_light = 0
    
    for x in range(M):
        n_on_switch_for_one_light = 0
        for k in range(ks[x][0]):
            n_on_switch_for_one_light += switch[ks[x][k+1]-1]
        if n_on_switch_for_one_light%2 == p[x]:
            n_on_light += 1
    
    if n_on_light == M:
        ans += 1
    
print(ans)

Solution (Python):
N, M = list(map(int, input().split()))
K = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))

ans = 0

for i in range(2**N):
    light = [0]*M 
    for j in range(M):
        on = 0 
        for k in K[j]: 
            if (i>>(k-1))&1: 
                on += 1
        if on%2 == P[j]: 
            light[j] = True
    if all(light): 
        ans += 1
print(ans)

Solution (Python):
N,M=map(int,input().split())

s=[[0 for i in range(N)] for j in range(M)]

for i in range(M):
    tmp=list(map(int,input().split()))

    k=tmp[0]
    for j in range(k):
        s[i][tmp[j+1]-1]=1

p=list(map(int,input().split()))

out=0

for i in range(2**N):
    b=list(map(int,list(bin(i))[2:]))
    b=[0 for j in range((N-len(b)))]+b
    ss=1
    for j in range(M):
        t=0
        for k in range(N):
            if b[k]==1 and s[j][k]==1:
                t+=1
        if t%2!=p[j]:
            ss=0
    if ss==1:
        out+=1

print(out)

Solution (Python):

N, M = map(int, input().split())
S = []
for i in range(M):
    s = map(int, input().split())
    sl = list(s)
    S.append(sl[1:])

P = list(map(int, input().split()))

a = []
for i in range(2 ** N):
    i_bin = bin(i)
    a.append(i_bin[2:].zfill(N))

c = 0
for ai in a:
    
    r = True
    for i, si in enumerate(S):
        x = 0
        for sii in si:
            
            x += int(ai[sii-1])
        if x % 2 != P[i]:
            r = False
    if r:
        c += 1

print(c)

Solution (Python):
from numpy import*
n,m=map(int,input().split())

r=[list(map(int,input().split()))[1:]for i in range(m)]
*p,=map(int,input().split())
ans=0
for i in range(2**n):
    lamp=array([i>>j&1for j in range(n)])
    ans+= p==[sum(lamp[array(j)-1])%2 for j in r]
print(ans)

Solution (Python):
import math
n, m = map(int, input().split())
s = [list(map(int,input().split()))[1:] for i in range(m)]
p = list(map(int, input().split()))


def is_on(s, x, p):
    parity = 0
    for i in s:
        parity += (x >> (i-1)) & 1
    return parity % 2 == p


ans = 0
for i in range(int(math.pow(2, n))):
    on = 1
    for j in range(m):
        if not is_on(s[j], i, p[j]):
            on = 0
            break
    ans += on
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

n,m = map(int, input().split())
ks = [ list(map(int,input().split())) for _ in range(m) ]
p = list(map(int,input().split()))






x = [ len(c) for c in ks ]


count = 0
for i in range(2**n):
    b = bin(i)
    b = list(b)
    b = b[2:]
    b = list(map(int,b))
    swich_list = [0]*(n - len(b))
    c = swich_list + b
    c.reverse()
    

    lamp_list = [0]*m
    for j in range(m):
        s = 0
        for k in ks[j][1:]:
            
            s += c[k-1]

        if s%2==p[j]:
            lamp_list[j] = 1

    if sum(lamp_list)==m:
        count += 1

print(count)

Solution (Python):
def resolve():
    
    n, m = map(int, input().split())
    s = list(list(map(int, input().split()))[1:] for _ in range(m))
    p = list(map(int, input().split()))
    print(sum([1 for i in range(1 << n) if all([sum([1 for sji in sj if i & (1 << (sji - 1))]) % 2 == pj for sj, pj in zip(s, p)])]))


if __name__ == "__main__":
    resolve()

Solution (Python):
def resolve():
    
    n, m = map(int, input().split())
    s = list(list(map(int, input().split()))[1:] for _ in range(m))
    p = list(map(int, input().split()))
    ok = 0
    for i in range(1 << n):
        lights = [False] * m
        for j in range(m):
            on = 0
            for sji in s[j]:
                
                if i & (1 << (sji - 1)):
                    on += 1
            if on % 2 == p[j]:
                lights[j] = True
        if all(lights):
            ok += 1
    print(ok)


if __name__ == "__main__":
    resolve()

Solution (Python):
n, m = map(int, input().split())
k = []
for _ in range(m):
    k.append(list(map(int, input().split()))[1:])
*p, = map(int, input().split())

count = 0
for i in range(2 ** n):
    res = 0
    for kc, pc in zip(k, p):
        s = sum([(i >> (j-1)) & 1 for j in kc]) % 2
        res += s == pc
    count += res == len(p)
print(count)

Solution (Python):
n, m = map(int, input().split())
k = []
for _ in range(m):
    k.append(list(map(int, input().split()))[1:])
*p, = map(int, input().split())

table = []
for i in range(n):
    row = []
    for j in range(2 ** i):
        row += [1] * (2 ** (n-i) // 2) + [0] * (2 ** (n-i) // 2)
    table.append(row)

count = 0
for j in range(len(table[0])):
    res = 0
    for i, item in enumerate(k):
        if sum([table[n-1][j] for n in item]) % 2 == p[i]:
            res += 1
    if res == len(p):
        count += 1

print(count)

Solution (Python):
N,M=map(int,input().split())
ks=[list(map(int,input().split()))[1:] for _ in range(M)]
p=list(map(int,input().split()))

ans=0

for i in range(2**N):
  lamp=[0]*M
  for j in range(len(bin(i))-2):
    if (i>>j)&1==1:
      for k in range(M):
        if j+1 in ks[k]:
          lamp[k]+=1
  ja=0
  for j in range(M):
    if lamp[j]%2!=p[j]:
      ja+=1
  if ja==0:
    ans+=1
    
    
print(ans)

Solution (Python):
import numpy as np

def countMatchedSwitch(sw_status, switch, index):
    ret = 0
    for s in switch[index]:
        if int(sw_status[int(s) - 1]) == 1:
            ret += 1
    return ret % 2


if __name__ == '__main__':
    N, M = [int(i) for i in input().split()]
    s = []
    for i in range(int(M)):
        data = input().split()
        s.append(data[1:])
    p = [int(i) for i in input().split()]

    ret = 0
    for i in range(2**N):
        is_all_passed = True
        sw_status = bin(i)[2:].zfill(N)
        for j in range(M):
            if p[j] != countMatchedSwitch(sw_status, s, j):
                is_all_passed = False
        if is_all_passed:
            ret += 1
    print("{ret}".format(ret=ret))

Solution (Python):
N , M = map(int , input().split())
switch = []
bit_switch = []
for _ in range(M):
    switch = list(map(int ,input().split()))
    del switch[0]
    k = 0
    for i in switch:
        k += 1 << (i - 1)
    bit_switch.append(k)
p = list(map(int,input().split()))
cnt = 0
dp = [[] for _ in range(M + 1)]
dp[0] = [i for i in range(2 ** N)]


for i in range(M):
    for j in dp[i]:
        if str(bin(j & bit_switch[i])).count('1')% 2 == p[i]:
            dp[i + 1].append(j)

print(len(dp[M]))

Solution (Python):
n,m=map(int,input().split()) 
lists=[]
for i in range(m):
	s= list(map(int,input().split()))
	lists.append(s)
listp = [int(i) for i in input().split()]





ans=0
for i in range(2**n):
	nn=format(i,"b")
	nnn=nn.zfill(n)	
	temp2=0
	for j in range(m):
		temp=0
		for k in range(lists[j][0]):
			ss=lists[j][k+1]
			temp=temp+int(nnn[ss-1])
		if temp%2==listp[j]:
			temp2=temp2+1
	if temp2==m:
		ans=ans+1
			
print(ans)

Solution (Python):
n,m=map(int,input().split())

data = []
for _ in range(m):
    lista = [int(i) for i in input().split()]
    data.append(lista)
    
listp = [int(i) for i in input().split()]

testnum = 2**n
ans = 0
for i in range(testnum):
    checklist = [0]*n
    tmpi = i
    for j in range(n):
        if tmpi>=2**(n-1-j):
            checklist[j]=1
            tmpi -= 2**(n-1-j)
    
    succ = True
    for j in range(m):
        sumnum = 0
        for jj in range(1,len(data[j])):
            sumnum += checklist[data[j][jj]-1]
        if sumnum%2 != listp[j]:
            succ = False
            break
    if succ==True:
        ans +=1
        
print(ans)

Solution (Python):
from itertools import combinations

N,M=map(int,input().split())

swt=[]
for i in range(M):
    lis=list(map(int,input().split()))
    swt.append(lis)
p=list(map(int,input().split()))
li=list(range(1,N+1))
combi=[]
for i in range(N+1):
    combi.extend(combinations(li,i))

ans=0
for s in combi:
    f=True
    for i in range(M):
        temp=0
        for j in range(1,swt[i][0]+1):
            if  swt[i][j] in s:
                temp+=1
        if not temp%2==p[i]:
            f=False
            break
    if f:
        ans+=1
print(ans)

Solution (Python):
N, M = map(int, input().split())
S = []
for _ in range(M):
    k, *s = map(int, input().split())
    S.append(s)
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
    check = [0 for _ in range(N)]
    tmp = i
    flg = True
    for j in range(N):
        check[j] = tmp % 2
        tmp //= 2
    for l, s in enumerate(S):
        cnt = 0
        for k in s:
            cnt += check[k - 1]
        if cnt % 2 != p[l]:
            flg = False
    if flg:
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
count = 0


def dfs(i, switch):
    if i == n:
        
        light_on_flag = True
        for a in range(m):
            switch_on_count = 0
            for b in range(ks[a][0]):
                if switch[ks[a][b + 1] - 1]:
                    switch_on_count += 1
            if not switch_on_count % 2 == p[a]:
                light_on_flag = False
                break
        if light_on_flag:
            global count
            count += 1
        return

    switch[i] = True
    dfs(i + 1, switch)
    switch[i] = False
    dfs(i + 1, switch)


switch = [False] * n
dfs(0, switch)
print(count)

Solution (Python):
def main():
    N, M = (int(i) for i in input().split())
    s = [[int(i) for i in input()[2:].split()] for j in range(M)]
    p = [int(i) for i in input().split()]
    ans = 0
    for bit in range(1<<N):
        switches = [0] * N
        for i in range(N):
            if bit & (1<<i):
                switches[i] = 1
        for ss,pp in zip(s,p):
            tmp = 0
            for i in ss:
                if switches[i-1]:
                    tmp += 1
            if tmp%2 != pp:
                break
        else:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import copy
n,m = map(int,input().split())
lamp = [[]for _ in range(m) ]
for i in range(m):
    s= list(map(lambda x:int(x)-1,input().split()))
    lamp[i] = s[1:]
mod = list(map(int,input().split()))

swiches = [[0 for _ in range(n)]]
for i in range(n):
    swiches2 =[]
    for swich in swiches:
        swiches2.append(swich)
        swich2 = copy.copy(swich)
        swich2[i] = 1
        swiches2.append(swich2)
    swiches = swiches2
ans = 0
for switch in swiches:
    for i,lampi in enumerate(lamp):
        sw_on = 0
        for j in lampi:
            sw_on += switch[j]
        if sw_on%2!=mod[i]:
            break
        else:
            if i==m-1:
                ans +=1
print(ans)

Solution (Python):
n,m = map(int,input().split())
S = []
for _ in range(m):
  s = list(map(int,input().split()))
  del s[0]
  k = 0
  for i in s:
    k +=  1<<(i-1)
  S.append(k)

p = list(map(int,input().split()))

dp = [[] for _ in range(m+1)]
dp[0] = [i for i in range(2**n)]
for i in range(m):
  for j in dp[i]:
    if str(bin(j & S[i])).count('1')%2==p[i]:
      dp[i+1].append(j)
      
print(len(dp[m]))

Solution (Python):
def count1(x):
    global N
    return sum([(x&(1<<t))>>t for t in range(N)])

def check(k):
    global M,s,p
    for j in range(M):
        if (count1(k&s[j])-p[j])%2!=0:
            return False
    return True

N,M=map(int,input().split())
s=[]
for j in range(M):
    l=list(map(int,input().split()))
    A=sum([1<<(x-1) for x in l[1:]])
    s.append(A)
p=list(map(int,input().split()))

ans=0
for k in range(1<<N):
    if check(k):
        ans+=1

print(ans)